source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Combination.lean
import Mathlib.Algebra.BigOperators.Group.Finset.Indicator import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.Tactic.FinCases /-! # Affine combinations of points This file defines affine combinations of points. ## Main definitions * `weightedVSubOfPoint` is a general weighted combination of subtractions with an explicit base point, yielding a vector. * `weightedVSub` uses an arbitrary choice of base point and is intended to be used when the sum of weights is 0, in which case the result is independent of the choice of base point. * `affineCombination` adds the weighted combination to the arbitrary base point, yielding a point rather than a vector, and is intended to be used when the sum of weights is 1, in which case the result is independent of the choice of base point. These definitions are for sums over a `Finset`; versions for a `Fintype` may be obtained using `Finset.univ`, while versions for a `Finsupp` may be obtained using `Finsupp.support`. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Affine namespace Finset theorem univ_fin2 : (univ : Finset (Fin 2)) = {0, 1} := rfl variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [S : AffineSpace V P] variable {ι : Type*} (s : Finset ι) variable {ι₂ : Type*} (s₂ : Finset ι₂) /-- A weighted sum of the results of subtracting a base point from the given points, as a linear map on the weights. The main cases of interest are where the sum of the weights is 0, in which case the sum is independent of the choice of base point, and where the sum of the weights is 1, in which case the sum added to the base point is independent of the choice of base point. -/ def weightedVSubOfPoint (p : ι → P) (b : P) : (ι → k) →ₗ[k] V := ∑ i ∈ s, (LinearMap.proj i : (ι → k) →ₗ[k] k).smulRight (p i -ᵥ b) @[simp] theorem weightedVSubOfPoint_apply (w : ι → k) (p : ι → P) (b : P) : s.weightedVSubOfPoint p b w = ∑ i ∈ s, w i • (p i -ᵥ b) := by simp [weightedVSubOfPoint, LinearMap.sum_apply] /-- The value of `weightedVSubOfPoint`, where the given points are equal. -/ @[simp (high)] theorem weightedVSubOfPoint_apply_const (w : ι → k) (p : P) (b : P) : s.weightedVSubOfPoint (fun _ => p) b w = (∑ i ∈ s, w i) • (p -ᵥ b) := by rw [weightedVSubOfPoint_apply, sum_smul] lemma weightedVSubOfPoint_vadd (s : Finset ι) (w : ι → k) (p : ι → P) (b : P) (v : V) : s.weightedVSubOfPoint (v +ᵥ p) b w = s.weightedVSubOfPoint p (-v +ᵥ b) w := by simp [vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, add_comm] lemma weightedVSubOfPoint_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] (s : Finset ι) (w : ι → k) (p : ι → V) (b : V) (a : G) : s.weightedVSubOfPoint (a • p) b w = a • s.weightedVSubOfPoint p (a⁻¹ • b) w := by simp [smul_sum, smul_sub, smul_comm a (w _)] /-- `weightedVSubOfPoint` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSubOfPoint_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) (b : P) : s.weightedVSubOfPoint p₁ b w₁ = s.weightedVSubOfPoint p₂ b w₂ := by simp_rw [weightedVSubOfPoint_apply] refine sum_congr rfl fun i hi => ?_ rw [hw i hi, hp i hi] /-- Given a family of points, if we use a member of the family as a base point, the `weightedVSubOfPoint` does not depend on the value of the weights at this point. -/ theorem weightedVSubOfPoint_eq_of_weights_eq (p : ι → P) (j : ι) (w₁ w₂ : ι → k) (hw : ∀ i, i ≠ j → w₁ i = w₂ i) : s.weightedVSubOfPoint p (p j) w₁ = s.weightedVSubOfPoint p (p j) w₂ := by simp only [Finset.weightedVSubOfPoint_apply] congr ext i rcases eq_or_ne i j with h | h · simp [h] · simp [hw i h] /-- The weighted sum is independent of the base point when the sum of the weights is 0. -/ theorem weightedVSubOfPoint_eq_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w = s.weightedVSubOfPoint p b₂ w := by apply eq_of_sub_eq_zero rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_sub_distrib] conv_lhs => congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, zero_smul] /-- The weighted sum, added to the base point, is independent of the base point when the sum of the weights is 1. -/ theorem weightedVSubOfPoint_vadd_eq_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w +ᵥ b₁ = s.weightedVSubOfPoint p b₂ w +ᵥ b₂ := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← @vsub_eq_zero_iff_eq V, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← add_sub_assoc, add_comm, add_sub_assoc, ← sum_sub_distrib] conv_lhs => congr · skip · congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, one_smul, vsub_add_vsub_cancel, vsub_self] /-- The weighted sum is unaffected by removing the base point, if present, from the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_erase [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (s.erase i).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_erase rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by adding the base point, whether or not present, to the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_insert [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (insert i s).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_insert_zero rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSubOfPoint_indicator_subset (w : ι → k) (p : ι → P) (b : P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint p b (Set.indicator (↑s₁) w) := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] exact Eq.symm <| sum_indicator_subset_of_eq_zero w (fun i wi => wi • (p i -ᵥ b : V)) h fun i => zero_smul k _ /-- A weighted sum, over the image of an embedding, equals a weighted sum with the same points and weights over the original `Finset`. -/ theorem weightedVSubOfPoint_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) (b : P) : (s₂.map e).weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint (p ∘ e) b (w ∘ e) := by simp_rw [weightedVSubOfPoint_apply] exact Finset.sum_map _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSubOfPoint` expressions. -/ theorem sum_smul_vsub_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ p₂ : ι → P) (b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSubOfPoint p₁ b w - s.weightedVSubOfPoint p₂ b w := by simp_rw [weightedVSubOfPoint_apply, ← sum_sub_distrib, ← smul_sub, vsub_sub_vsub_cancel_right] /-- A weighted sum of pairwise subtractions, where the point on the right is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_vsub_const_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ : ι → P) (p₂ b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSubOfPoint p₁ b w - (∑ i ∈ s, w i) • (p₂ -ᵥ b) := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum of pairwise subtractions, where the point on the left is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_const_vsub_eq_sub_weightedVSubOfPoint (w : ι → k) (p₂ : ι → P) (p₁ b : P) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = (∑ i ∈ s, w i) • (p₁ -ᵥ b) - s.weightedVSubOfPoint p₂ b w := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w + s₂.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, sum_sdiff h] /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w - s₂.weightedVSubOfPoint p b (-w) = s.weightedVSubOfPoint p b w := by rw [map_neg, sub_neg_eq_add, s.weightedVSubOfPoint_sdiff h] /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSubOfPoint_subtype_eq_filter (w : ι → k) (p : ι → P) (b : P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSubOfPoint (fun i => p i) b fun i => w i) = {x ∈ s | pred x}.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_subtype_eq_sum_filter] /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSubOfPoint_filter_of_ne (w : ι → k) (p : ι → P) (b : P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, sum_filter_of_ne] intro i hi hne refine h i hi ?_ intro hw simp [hw] at hne /-- A constant multiplier of the weights in `weightedVSubOfPoint` may be moved outside the sum. -/ theorem weightedVSubOfPoint_const_smul (w : ι → k) (p : ι → P) (b : P) (c : k) : s.weightedVSubOfPoint p b (c • w) = c • s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, smul_sum, Pi.smul_apply, smul_smul, smul_eq_mul] /-- A weighted sum of the results of subtracting a default base point from the given points, as a linear map on the weights. This is intended to be used when the sum of the weights is 0; that condition is specified as a hypothesis on those lemmas that require it. -/ def weightedVSub (p : ι → P) : (ι → k) →ₗ[k] V := s.weightedVSubOfPoint p (Classical.choice S.nonempty) /-- Applying `weightedVSub` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `weightedVSub` would involve selecting a preferred base point with `weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero` and then using `weightedVSubOfPoint_apply`. -/ theorem weightedVSub_apply (w : ι → k) (p : ι → P) : s.weightedVSub p w = ∑ i ∈ s, w i • (p i -ᵥ Classical.choice S.nonempty) := by simp [weightedVSub] /-- `weightedVSub` gives the sum of the results of subtracting any base point, when the sum of the weights is 0. -/ theorem weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b : P) : s.weightedVSub p w = s.weightedVSubOfPoint p b w := s.weightedVSubOfPoint_eq_of_sum_eq_zero w p h _ _ /-- The value of `weightedVSub`, where the given points are equal and the sum of the weights is 0. -/ @[simp] theorem weightedVSub_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 0) : s.weightedVSub (fun _ => p) w = 0 := by rw [weightedVSub, weightedVSubOfPoint_apply_const, h, zero_smul] /-- The `weightedVSub` for an empty set is 0. -/ @[simp] theorem weightedVSub_empty (w : ι → k) (p : ι → P) : (∅ : Finset ι).weightedVSub p w = (0 : V) := by simp [weightedVSub_apply] lemma weightedVSub_vadd {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → P) (v : V) : s.weightedVSub (v +ᵥ p) w = s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_vadd, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] lemma weightedVSub_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → V) (a : G) : s.weightedVSub (a • p) w = a • s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_smul, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] /-- `weightedVSub` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSub_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.weightedVSub p₁ w₁ = s.weightedVSub p₂ w₂ := s.weightedVSubOfPoint_congr hw hp _ /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSub_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSub p w = s₂.weightedVSub p (Set.indicator (↑s₁) w) := weightedVSubOfPoint_indicator_subset _ _ _ h /-- A weighted subtraction, over the image of an embedding, equals a weighted subtraction with the same points and weights over the original `Finset`. -/ theorem weightedVSub_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).weightedVSub p w = s₂.weightedVSub (p ∘ e) (w ∘ e) := s₂.weightedVSubOfPoint_map _ _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSub` expressions. -/ theorem sum_smul_vsub_eq_weightedVSub_sub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSub p₁ w - s.weightedVSub p₂ w := s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 0. -/ theorem sum_smul_vsub_const_eq_weightedVSub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSub p₁ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, sub_zero] /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 0. -/ theorem sum_smul_const_vsub_eq_neg_weightedVSub (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = -s.weightedVSub p₂ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, zero_sub] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSub_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w + s₂.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff h _ _ _ /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSub_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w - s₂.weightedVSub p (-w) = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff_sub h _ _ _ /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSub_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSub (fun i => p i) fun i => w i) = {x ∈ s | pred x}.weightedVSub p w := s.weightedVSubOfPoint_subtype_eq_filter _ _ _ _ /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSub_filter_of_ne (w : ι → k) (p : ι → P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_filter_of_ne _ _ _ h /-- A constant multiplier of the weights in `weightedVSub_of` may be moved outside the sum. -/ theorem weightedVSub_const_smul (w : ι → k) (p : ι → P) (c : k) : s.weightedVSub p (c • w) = c • s.weightedVSub p w := s.weightedVSubOfPoint_const_smul _ _ _ _ instance : AffineSpace (ι → k) (ι → k) := Pi.instAddTorsor variable (k) /-- A weighted sum of the results of subtracting a default base point from the given points, added to that base point, as an affine map on the weights. This is intended to be used when the sum of the weights is 1, in which case it is an affine combination (barycenter) of the points with the given weights; that condition is specified as a hypothesis on those lemmas that require it. -/ def affineCombination (p : ι → P) : (ι → k) →ᵃ[k] P where toFun w := s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty linear := s.weightedVSub p map_vadd' w₁ w₂ := by simp_rw [vadd_vadd, weightedVSub, vadd_eq_add, LinearMap.map_add] /-- The linear map corresponding to `affineCombination` is `weightedVSub`. -/ @[simp] theorem affineCombination_linear (p : ι → P) : (s.affineCombination k p).linear = s.weightedVSub p := rfl variable {k} /-- Applying `affineCombination` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `affineCombination` would involve selecting a preferred base point with `affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one` and then using `weightedVSubOfPoint_apply`. -/ theorem affineCombination_apply (w : ι → k) (p : ι → P) : (s.affineCombination k p) w = s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty := rfl /-- The value of `affineCombination`, where the given points are equal. -/ @[simp] theorem affineCombination_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 1) : s.affineCombination k (fun _ => p) w = p := by rw [affineCombination_apply, s.weightedVSubOfPoint_apply_const, h, one_smul, vsub_vadd] /-- `affineCombination` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem affineCombination_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.affineCombination k p₁ w₁ = s.affineCombination k p₂ w₂ := by simp_rw [affineCombination_apply, s.weightedVSubOfPoint_congr hw hp] /-- `affineCombination` gives the sum with any base point, when the sum of the weights is 1. -/ theorem affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b : P) : s.affineCombination k p w = s.weightedVSubOfPoint p b w +ᵥ b := s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w p h _ _ /-- Adding a `weightedVSub` to an `affineCombination`. -/ theorem weightedVSub_vadd_affineCombination (w₁ w₂ : ι → k) (p : ι → P) : s.weightedVSub p w₁ +ᵥ s.affineCombination k p w₂ = s.affineCombination k p (w₁ + w₂) := by rw [← vadd_eq_add, AffineMap.map_vadd, affineCombination_linear] /-- Subtracting two `affineCombination`s. -/ theorem affineCombination_vsub (w₁ w₂ : ι → k) (p : ι → P) : s.affineCombination k p w₁ -ᵥ s.affineCombination k p w₂ = s.weightedVSub p (w₁ - w₂) := by rw [← AffineMap.linearMap_vsub, affineCombination_linear, vsub_eq_sub] theorem attach_affineCombination_of_injective [DecidableEq P] (s : Finset P) (w : P → k) (f : s → P) (hf : Function.Injective f) : s.attach.affineCombination k f (w ∘ f) = (image f univ).affineCombination k id w := by simp [affineCombination, hf] theorem attach_affineCombination_coe (s : Finset P) (w : P → k) : s.attach.affineCombination k ((↑) : s → P) (w ∘ (↑)) = s.affineCombination k id w := by classical rw [attach_affineCombination_of_injective s w ((↑) : s → P) Subtype.coe_injective, univ_eq_attach, attach_image_val] /-- Viewing a module as an affine space modelled on itself, a `weightedVSub` is just a linear combination. -/ @[simp] theorem weightedVSub_eq_linear_combination {ι} (s : Finset ι) {w : ι → k} {p : ι → V} (hw : s.sum w = 0) : s.weightedVSub p w = ∑ i ∈ s, w i • p i := by simp [s.weightedVSub_apply, vsub_eq_sub, smul_sub, ← Finset.sum_smul, hw] /-- Viewing a module as an affine space modelled on itself, affine combinations are just linear combinations. -/ @[simp] theorem affineCombination_eq_linear_combination (s : Finset ι) (p : ι → V) (w : ι → k) (hw : ∑ i ∈ s, w i = 1) : s.affineCombination k p w = ∑ i ∈ s, w i • p i := by simp [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw 0] /-- An `affineCombination` equals a point if that point is in the set and has weight 1 and the other points in the set have weight 0. -/ -- Cannot be @[simp] because `i` cannot be inferred by `simp`. theorem affineCombination_of_eq_one_of_eq_zero (w : ι → k) (p : ι → P) {i : ι} (his : i ∈ s) (hwi : w i = 1) (hw0 : ∀ i2 ∈ s, i2 ≠ i → w i2 = 0) : s.affineCombination k p w = p i := by have h1 : ∑ i ∈ s, w i = 1 := hwi ▸ sum_eq_single i hw0 fun h => False.elim (h his) rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p h1 (p i), weightedVSubOfPoint_apply] convert zero_vadd V (p i) refine sum_eq_zero ?_ intro i2 hi2 by_cases h : i2 = i · simp [h] · simp [hw0 i2 hi2 h] /-- An affine combination is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem affineCombination_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.affineCombination k p w = s₂.affineCombination k p (Set.indicator (↑s₁) w) := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_indicator_subset _ _ _ h] /-- An affine combination, over the image of an embedding, equals an affine combination with the same points and weights over the original `Finset`. -/ theorem affineCombination_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).affineCombination k p w = s₂.affineCombination k (p ∘ e) (w ∘ e) := by simp_rw [affineCombination_apply, weightedVSubOfPoint_map] /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `affineCombination` expressions. -/ theorem sum_smul_vsub_eq_affineCombination_vsub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.affineCombination k p₁ w -ᵥ s.affineCombination k p₂ w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 1. -/ theorem sum_smul_vsub_const_eq_affineCombination_vsub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 1) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.affineCombination k p₁ w -ᵥ p₂ := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 1. -/ theorem sum_smul_const_vsub_eq_vsub_affineCombination (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 1) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = p₁ -ᵥ s.affineCombination k p₂ w := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] /-- A weighted sum may be split into a subtraction of affine combinations over two subsets. -/ theorem affineCombination_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).affineCombination k p w -ᵥ s₂.affineCombination k p (-w) = s.weightedVSub p w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.weightedVSub_sdiff_sub h _ _ /-- If a weighted sum is zero and one of the weights is `-1`, the corresponding point is the affine combination of the other points with the given weights. -/ theorem affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one {w : ι → k} {p : ι → P} (hw : s.weightedVSub p w = (0 : V)) {i : ι} [DecidablePred (· ≠ i)] (his : i ∈ s) (hwi : w i = -1) : {x ∈ s | x ≠ i}.affineCombination k p w = p i := by classical rw [← @vsub_eq_zero_iff_eq V, ← hw, ← s.affineCombination_sdiff_sub (singleton_subset_iff.2 his), sdiff_singleton_eq_erase, ← filter_ne'] congr refine (affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_singleton_self _) ?_ ?_).symm · simp [hwi] · simp /-- An affine combination over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem affineCombination_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).affineCombination k (fun i => p i) fun i => w i) = {x ∈ s | pred x}.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_subtype_eq_filter] /-- An affine combination over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem affineCombination_filter_of_ne (w : ι → k) (p : ι → P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.affineCombination k p w = s.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, s.weightedVSubOfPoint_filter_of_ne _ _ _ h] /-- Suppose an indexed family of points is given, along with a subset of the index type. A vector can be expressed as `weightedVSubOfPoint` using a `Finset` lying within that subset and with a given sum of weights if and only if it can be expressed as `weightedVSubOfPoint` with that sum of weights for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype {v : V} {x : k} {s : Set ι} {p : ι → P} {b : P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = x ∧ v = fs.weightedVSubOfPoint p b w) ↔ ∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = x ∧ v = fs.weightedVSubOfPoint (fun i : s => p i) b w := by classical simp_rw [weightedVSubOfPoint_apply] constructor · rintro ⟨fs, hfs, w, rfl, rfl⟩ exact ⟨fs.subtype s, fun i => w i, sum_subtype_of_mem _ hfs, (sum_subtype_of_mem _ hfs).symm⟩ · rintro ⟨fs, w, rfl, rfl⟩ refine ⟨fs.map (Function.Embedding.subtype _), map_subtype_subset _, fun i => if h : i ∈ s then w ⟨i, h⟩ else 0, ?_, ?_⟩ <;> simp variable (k) /-- Suppose an indexed family of points is given, along with a subset of the index type. A vector can be expressed as `weightedVSub` using a `Finset` lying within that subset and with sum of weights 0 if and only if it can be expressed as `weightedVSub` with sum of weights 0 for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_weightedVSub_subset_iff_eq_weightedVSub_subtype {v : V} {s : Set ι} {p : ι → P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = 0 ∧ v = fs.weightedVSub p w) ↔ ∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = 0 ∧ v = fs.weightedVSub (fun i : s => p i) w := eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype variable (V) /-- Suppose an indexed family of points is given, along with a subset of the index type. A point can be expressed as an `affineCombination` using a `Finset` lying within that subset and with sum of weights 1 if and only if it can be expressed an `affineCombination` with sum of weights 1 for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_affineCombination_subset_iff_eq_affineCombination_subtype {p0 : P} {s : Set ι} {p : ι → P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = 1 ∧ p0 = fs.affineCombination k p w) ↔ ∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = 1 ∧ p0 = fs.affineCombination k (fun i : s => p i) w := by simp_rw [affineCombination_apply, eq_vadd_iff_vsub_eq] exact eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype variable {k V} /-- Affine maps commute with affine combinations. -/ theorem map_affineCombination {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AffineSpace V₂ P₂] (p : ι → P) (w : ι → k) (hw : s.sum w = 1) (f : P →ᵃ[k] P₂) : f (s.affineCombination k p w) = s.affineCombination k (f ∘ p) w := by have b := Classical.choice (inferInstance : AffineSpace V P).nonempty have b₂ := Classical.choice (inferInstance : AffineSpace V₂ P₂).nonempty rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw b, s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w (f ∘ p) hw b₂, ← s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w (f ∘ p) hw (f b) b₂] simp only [weightedVSubOfPoint_apply, RingHom.id_apply, AffineMap.map_vadd, LinearMap.map_smulₛₗ, AffineMap.linearMap_vsub, map_sum, Function.comp_apply] /-- The value of `affineCombination`, where the given points take only two values. -/ lemma affineCombination_apply_eq_lineMap_sum [DecidableEq ι] (w : ι → k) (p : ι → P) (p₁ p₂ : P) (s' : Finset ι) (h : ∑ i ∈ s, w i = 1) (hp₂ : ∀ i ∈ s ∩ s', p i = p₂) (hp₁ : ∀ i ∈ s \ s', p i = p₁) : s.affineCombination k p w = AffineMap.lineMap p₁ p₂ (∑ i ∈ s ∩ s', w i) := by rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p h p₁, weightedVSubOfPoint_apply, ← s.sum_inter_add_sum_diff s', AffineMap.lineMap_apply, vadd_right_cancel_iff, sum_smul] convert add_zero _ with i hi · convert Finset.sum_const_zero with i hi simp [hp₁ i hi] · exact (hp₂ i hi).symm variable (k) /-- Weights for expressing a single point as an affine combination. -/ def affineCombinationSingleWeights [DecidableEq ι] (i : ι) : ι → k := Pi.single i 1 @[simp] theorem affineCombinationSingleWeights_apply_self [DecidableEq ι] (i : ι) : affineCombinationSingleWeights k i i = 1 := Pi.single_eq_same _ _ @[simp] theorem affineCombinationSingleWeights_apply_of_ne [DecidableEq ι] {i j : ι} (h : j ≠ i) : affineCombinationSingleWeights k i j = 0 := Pi.single_eq_of_ne h _ @[simp] theorem sum_affineCombinationSingleWeights [DecidableEq ι] {i : ι} (h : i ∈ s) : ∑ j ∈ s, affineCombinationSingleWeights k i j = 1 := by rw [← affineCombinationSingleWeights_apply_self k i] exact sum_eq_single_of_mem i h fun j _ hj => affineCombinationSingleWeights_apply_of_ne k hj /-- Weights for expressing the subtraction of two points as a `weightedVSub`. -/ def weightedVSubVSubWeights [DecidableEq ι] (i j : ι) : ι → k := affineCombinationSingleWeights k i - affineCombinationSingleWeights k j @[simp] theorem weightedVSubVSubWeights_self [DecidableEq ι] (i : ι) : weightedVSubVSubWeights k i i = 0 := by simp [weightedVSubVSubWeights] @[simp] theorem weightedVSubVSubWeights_apply_left [DecidableEq ι] {i j : ι} (h : i ≠ j) : weightedVSubVSubWeights k i j i = 1 := by simp [weightedVSubVSubWeights, h] @[simp] theorem weightedVSubVSubWeights_apply_right [DecidableEq ι] {i j : ι} (h : i ≠ j) : weightedVSubVSubWeights k i j j = -1 := by simp [weightedVSubVSubWeights, h.symm] @[simp] theorem weightedVSubVSubWeights_apply_of_ne [DecidableEq ι] {i j t : ι} (hi : t ≠ i) (hj : t ≠ j) : weightedVSubVSubWeights k i j t = 0 := by simp [weightedVSubVSubWeights, hi, hj] @[simp] theorem sum_weightedVSubVSubWeights [DecidableEq ι] {i j : ι} (hi : i ∈ s) (hj : j ∈ s) : ∑ t ∈ s, weightedVSubVSubWeights k i j t = 0 := by simp_rw [weightedVSubVSubWeights, Pi.sub_apply, sum_sub_distrib] simp [hi, hj] variable {k} /-- Weights for expressing `lineMap` as an affine combination. -/ def affineCombinationLineMapWeights [DecidableEq ι] (i j : ι) (c : k) : ι → k := c • weightedVSubVSubWeights k j i + affineCombinationSingleWeights k i @[simp] theorem affineCombinationLineMapWeights_self [DecidableEq ι] (i : ι) (c : k) : affineCombinationLineMapWeights i i c = affineCombinationSingleWeights k i := by simp [affineCombinationLineMapWeights] @[simp] theorem affineCombinationLineMapWeights_apply_left [DecidableEq ι] {i j : ι} (h : i ≠ j) (c : k) : affineCombinationLineMapWeights i j c i = 1 - c := by simp [affineCombinationLineMapWeights, h.symm, sub_eq_neg_add] @[simp] theorem affineCombinationLineMapWeights_apply_right [DecidableEq ι] {i j : ι} (h : i ≠ j) (c : k) : affineCombinationLineMapWeights i j c j = c := by simp [affineCombinationLineMapWeights, h.symm] @[simp] theorem affineCombinationLineMapWeights_apply_of_ne [DecidableEq ι] {i j t : ι} (hi : t ≠ i) (hj : t ≠ j) (c : k) : affineCombinationLineMapWeights i j c t = 0 := by simp [affineCombinationLineMapWeights, hi, hj] @[simp] theorem sum_affineCombinationLineMapWeights [DecidableEq ι] {i j : ι} (hi : i ∈ s) (hj : j ∈ s) (c : k) : ∑ t ∈ s, affineCombinationLineMapWeights i j c t = 1 := by simp_rw [affineCombinationLineMapWeights, Pi.add_apply, sum_add_distrib] simp [hi, hj, ← mul_sum] variable (k) /-- An affine combination with `affineCombinationSingleWeights` gives the specified point. -/ @[simp] theorem affineCombination_affineCombinationSingleWeights [DecidableEq ι] (p : ι → P) {i : ι} (hi : i ∈ s) : s.affineCombination k p (affineCombinationSingleWeights k i) = p i := by refine s.affineCombination_of_eq_one_of_eq_zero _ _ hi (by simp) ?_ rintro j - hj simp [hj] /-- A weighted subtraction with `weightedVSubVSubWeights` gives the result of subtracting the specified points. -/ @[simp] theorem weightedVSub_weightedVSubVSubWeights [DecidableEq ι] (p : ι → P) {i j : ι} (hi : i ∈ s) (hj : j ∈ s) : s.weightedVSub p (weightedVSubVSubWeights k i j) = p i -ᵥ p j := by rw [weightedVSubVSubWeights, ← affineCombination_vsub, s.affineCombination_affineCombinationSingleWeights k p hi, s.affineCombination_affineCombinationSingleWeights k p hj] variable {k} /-- An affine combination with `affineCombinationLineMapWeights` gives the result of `line_map`. -/ @[simp] theorem affineCombination_affineCombinationLineMapWeights [DecidableEq ι] (p : ι → P) {i j : ι} (hi : i ∈ s) (hj : j ∈ s) (c : k) : s.affineCombination k p (affineCombinationLineMapWeights i j c) = AffineMap.lineMap (p i) (p j) c := by rw [affineCombinationLineMapWeights, ← weightedVSub_vadd_affineCombination, weightedVSub_const_smul, s.affineCombination_affineCombinationSingleWeights k p hi, s.weightedVSub_weightedVSubVSubWeights k p hj hi, AffineMap.lineMap_apply] end Finset section AffineSpace' variable {ι k V P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- A `weightedVSub` with sum of weights 0 is in the `vectorSpan` of an indexed family. -/ theorem weightedVSub_mem_vectorSpan {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → P) : s.weightedVSub p w ∈ vectorSpan k (Set.range p) := by classical rcases isEmpty_or_nonempty ι with (hι | ⟨⟨i0⟩⟩) · simp [Finset.eq_empty_of_isEmpty s] · rw [vectorSpan_range_eq_span_range_vsub_right k p i0, ← Set.image_univ, Finsupp.mem_span_image_iff_linearCombination, Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s w p h (p i0), Finset.weightedVSubOfPoint_apply] let w' := Set.indicator (↑s) w have hwx : ∀ i, w' i ≠ 0 → i ∈ s := fun i => Set.mem_of_indicator_ne_zero use Finsupp.onFinset s w' hwx, Set.subset_univ _ rw [Finsupp.linearCombination_apply, Finsupp.onFinset_sum hwx] · apply Finset.sum_congr rfl intro i hi simp [w', Set.indicator_apply, if_pos hi] · exact fun _ => zero_smul k _ /-- An `affineCombination` with sum of weights 1 is in the `affineSpan` of an indexed family, if the underlying ring is nontrivial. -/ theorem affineCombination_mem_affineSpan [Nontrivial k] {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 1) (p : ι → P) : s.affineCombination k p w ∈ affineSpan k (Set.range p) := by classical have hnz : ∑ i ∈ s, w i ≠ 0 := h.symm ▸ one_ne_zero have hn : s.Nonempty := Finset.nonempty_of_sum_ne_zero hnz obtain ⟨i1, hi1⟩ := hn let w1 : ι → k := Function.update (Function.const ι 0) i1 1 have hw1 : ∑ i ∈ s, w1 i = 1 := by simp only [w1, Function.const_zero, Finset.sum_update_of_mem hi1, Pi.zero_apply, Finset.sum_const_zero, add_zero] have hw1s : s.affineCombination k p w1 = p i1 := s.affineCombination_of_eq_one_of_eq_zero w1 p hi1 (Function.update_self ..) fun _ _ hne => Function.update_of_ne hne .. have hv : s.affineCombination k p w -ᵥ p i1 ∈ (affineSpan k (Set.range p)).direction := by rw [direction_affineSpan, ← hw1s, Finset.affineCombination_vsub] apply weightedVSub_mem_vectorSpan simp [Pi.sub_apply, h, hw1] rw [← vsub_vadd (s.affineCombination k p w) (p i1)] exact AffineSubspace.vadd_mem_of_mem_direction hv (mem_affineSpan k (Set.mem_range_self _)) /-- An `affineCombination` with sum of weights 1 is in the `affineSpan` of an indexed family, if the family is nonempty. -/ theorem affineCombination_mem_affineSpan_of_nonempty [Nonempty ι] {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 1) (p : ι → P) : s.affineCombination k p w ∈ affineSpan k (Set.range p) := by rcases subsingleton_or_nontrivial k with hs | hn · have hnv := Module.subsingleton k V rw [AddTorsor.subsingleton_iff V P] at hnv rw [(affineSpan_eq_top_iff_nonempty_of_subsingleton k).2 (Set.range_nonempty p)] simp · exact affineCombination_mem_affineSpan h p variable (k) in /-- A vector is in the `vectorSpan` of an indexed family if and only if it is a `weightedVSub` with sum of weights 0. -/ theorem mem_vectorSpan_iff_eq_weightedVSub {v : V} {p : ι → P} : v ∈ vectorSpan k (Set.range p) ↔ ∃ (s : Finset ι) (w : ι → k), ∑ i ∈ s, w i = 0 ∧ v = s.weightedVSub p w := by classical constructor · rcases isEmpty_or_nonempty ι with (hι | ⟨⟨i0⟩⟩) swap · rw [vectorSpan_range_eq_span_range_vsub_right k p i0, ← Set.image_univ, Finsupp.mem_span_image_iff_linearCombination] rintro ⟨l, _, hv⟩ use insert i0 l.support set w := (l : ι → k) - Function.update (Function.const ι 0 : ι → k) i0 (∑ i ∈ l.support, l i) with hwdef use w have hw : ∑ i ∈ insert i0 l.support, w i = 0 := by rw [hwdef] simp_rw [Pi.sub_apply, Finset.sum_sub_distrib, Finset.sum_update_of_mem (Finset.mem_insert_self _ _), Finset.sum_insert_of_eq_zero_if_notMem Finsupp.notMem_support_iff.1] simp only [Function.const_apply, Finset.sum_const_zero, add_zero, sub_self] use hw have hz : w i0 • (p i0 -ᵥ p i0 : V) = 0 := (vsub_self (p i0)).symm ▸ smul_zero _ change (fun i => w i • (p i -ᵥ p i0 : V)) i0 = 0 at hz rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ w p hw (p i0), Finset.weightedVSubOfPoint_apply, ← hv, Finsupp.linearCombination_apply, @Finset.sum_insert_zero _ _ l.support i0 _ _ _ hz] change (∑ i ∈ l.support, l i • _) = _ congr with i by_cases h : i = i0 · simp [h] · simp [hwdef, h] · rw [Set.range_eq_empty, vectorSpan_empty, Submodule.mem_bot] rintro rfl use ∅ simp · rintro ⟨s, w, hw, rfl⟩ exact weightedVSub_mem_vectorSpan hw p /-- A point in the `affineSpan` of an indexed family is an `affineCombination` with sum of weights 1. See also `eq_affineCombination_of_mem_affineSpan_of_fintype`. -/ theorem eq_affineCombination_of_mem_affineSpan {p1 : P} {p : ι → P} (h : p1 ∈ affineSpan k (Set.range p)) : ∃ (s : Finset ι) (w : ι → k), ∑ i ∈ s, w i = 1 ∧ p1 = s.affineCombination k p w := by classical have hn : (affineSpan k (Set.range p) : Set P).Nonempty := ⟨p1, h⟩ rw [affineSpan_nonempty, Set.range_nonempty_iff_nonempty] at hn obtain ⟨i0⟩ := hn have h0 : p i0 ∈ affineSpan k (Set.range p) := mem_affineSpan k (Set.mem_range_self i0) have hd : p1 -ᵥ p i0 ∈ (affineSpan k (Set.range p)).direction := AffineSubspace.vsub_mem_direction h h0 rw [direction_affineSpan, mem_vectorSpan_iff_eq_weightedVSub] at hd rcases hd with ⟨s, w, h, hs⟩ let s' := insert i0 s let w' := Set.indicator (↑s) w have h' : ∑ i ∈ s', w' i = 0 := by rw [← h, Finset.sum_indicator_subset _ (Finset.subset_insert i0 s)] have hs' : s'.weightedVSub p w' = p1 -ᵥ p i0 := by rw [hs] exact (Finset.weightedVSub_indicator_subset _ _ (Finset.subset_insert i0 s)).symm let w0 : ι → k := Function.update (Function.const ι 0) i0 1 have hw0 : ∑ i ∈ s', w0 i = 1 := by rw [Finset.sum_update_of_mem (Finset.mem_insert_self _ _)] simp only [Function.const_apply, Finset.sum_const_zero, add_zero] have hw0s : s'.affineCombination k p w0 = p i0 := s'.affineCombination_of_eq_one_of_eq_zero w0 p (Finset.mem_insert_self _ _) (Function.update_self ..) fun _ _ hne => Function.update_of_ne hne _ _ refine ⟨s', w0 + w', ?_, ?_⟩ · simp [Pi.add_apply, Finset.sum_add_distrib, hw0, h'] · rw [add_comm, ← Finset.weightedVSub_vadd_affineCombination, hw0s, hs', vsub_vadd] theorem eq_affineCombination_of_mem_affineSpan_of_fintype [Fintype ι] {p1 : P} {p : ι → P} (h : p1 ∈ affineSpan k (Set.range p)) : ∃ w : ι → k, ∑ i, w i = 1 ∧ p1 = Finset.univ.affineCombination k p w := by classical obtain ⟨s, w, hw, rfl⟩ := eq_affineCombination_of_mem_affineSpan h refine ⟨(s : Set ι).indicator w, ?_, Finset.affineCombination_indicator_subset w p s.subset_univ⟩ simp only [Finset.mem_coe, Set.indicator_apply, ← hw] rw [Fintype.sum_extend_by_zero s w] /-- A point in the `affineSpan` of a subset of an indexed family is an `affineCombination` with sum of weights 1, using only points in the given subset. -/ lemma eq_affineCombination_of_mem_affineSpan_image {p₁ : P} {p : ι → P} {s : Set ι} (h : p₁ ∈ affineSpan k (p '' s)) : ∃ (fs : Finset ι) (w : ι → k), ↑fs ⊆ s ∧ ∑ i ∈ fs, w i = 1 ∧ p₁ = fs.affineCombination k p w := by classical rw [Set.image_eq_range] at h obtain ⟨fs', w', hw', rfl⟩ := eq_affineCombination_of_mem_affineSpan h refine ⟨fs'.map (Function.Embedding.subtype _), fun i ↦ if hi : i ∈ s then w' ⟨i, hi⟩ else 0, (by simp), (by simp [hw']), ?_⟩ simp only [Finset.affineCombination_map, Function.Embedding.coe_subtype] exact fs'.affineCombination_congr (by simp) (by simp) lemma affineCombination_mem_affineSpan_image [Nontrivial k] {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 1) {s' : Set ι} (hs' : ∀ i ∈ s, i ∉ s' → w i = 0) (p : ι → P) : s.affineCombination k p w ∈ affineSpan k (p '' s') := by classical rw [Set.image_eq_range] let w' : s' → k := fun i ↦ w i have h' : ∑ i ∈ s with i ∈ s', w i = 1 := by rw [← h, ← Finset.sum_sdiff (s₁ := {x ∈ s | x ∈ s'}) (s₂ := s) (by simp), right_eq_add] refine Finset.sum_eq_zero ?_ intro i hi simp only [Finset.mem_sdiff, Finset.mem_filter, not_and] at hi exact hs' i hi.1 (hi.2 hi.1) rw [← Finset.sum_subtype_eq_sum_filter] at h' convert affineCombination_mem_affineSpan h' (fun x ↦ p x) rw [Finset.affineCombination_subtype_eq_filter, Finset.affineCombination_indicator_subset w p (Finset.filter_subset _ _)] refine Finset.affineCombination_congr _ (fun i hi ↦ ?_) (fun _ _ ↦ rfl) simp_all [Set.indicator_apply] variable (k V) /-- A point is in the `affineSpan` of an indexed family if and only if it is an `affineCombination` with sum of weights 1, provided the underlying ring is nontrivial. -/ theorem mem_affineSpan_iff_eq_affineCombination [Nontrivial k] {p1 : P} {p : ι → P} : p1 ∈ affineSpan k (Set.range p) ↔ ∃ (s : Finset ι) (w : ι → k), ∑ i ∈ s, w i = 1 ∧ p1 = s.affineCombination k p w := by constructor · exact eq_affineCombination_of_mem_affineSpan · rintro ⟨s, w, hw, rfl⟩ exact affineCombination_mem_affineSpan hw p /-- Given a family of points together with a chosen base point in that family, membership of the affine span of this family corresponds to an identity in terms of `weightedVSubOfPoint`, with weights that are not required to sum to 1. -/ theorem mem_affineSpan_iff_eq_weightedVSubOfPoint_vadd [Nontrivial k] (p : ι → P) (j : ι) (q : P) : q ∈ affineSpan k (Set.range p) ↔ ∃ (s : Finset ι) (w : ι → k), q = s.weightedVSubOfPoint p (p j) w +ᵥ p j := by constructor · intro hq obtain ⟨s, w, hw, rfl⟩ := eq_affineCombination_of_mem_affineSpan hq exact ⟨s, w, s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw (p j)⟩ · rintro ⟨s, w, rfl⟩ classical let w' : ι → k := Function.update w j (1 - (s \ {j}).sum w) have h₁ : (insert j s).sum w' = 1 := by by_cases hj : j ∈ s · simp [w', Finset.sum_update_of_mem hj, Finset.insert_eq_of_mem hj] · simp_rw [w', Finset.sum_insert hj, Finset.sum_update_of_notMem hj, Function.update_self, ← Finset.erase_eq, Finset.erase_eq_of_notMem hj, sub_add_cancel] have hww : ∀ i, i ≠ j → w i = w' i := by intro i hij simp [w', hij] rw [s.weightedVSubOfPoint_eq_of_weights_eq p j w w' hww, ← s.weightedVSubOfPoint_insert w' p j, ← (insert j s).affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w' p h₁ (p j)] exact affineCombination_mem_affineSpan h₁ p variable {k V} /-- Given a set of points, together with a chosen base point in this set, if we affinely transport all other members of the set along the line joining them to this base point, the affine span is unchanged. -/ theorem affineSpan_eq_affineSpan_lineMap_units [Nontrivial k] {s : Set P} {p : P} (hp : p ∈ s) (w : s → Units k) : affineSpan k (Set.range fun q : s => AffineMap.lineMap p ↑q (w q : k)) = affineSpan k s := by have : s = Set.range ((↑) : s → P) := by simp conv_rhs => rw [this] apply le_antisymm <;> intro q hq <;> erw [mem_affineSpan_iff_eq_weightedVSubOfPoint_vadd k V _ (⟨p, hp⟩ : s) q] at hq ⊢ <;> obtain ⟨t, μ, rfl⟩ := hq <;> use t <;> [use fun x => μ x * ↑(w x); use fun x => μ x * ↑(w x)⁻¹] <;> simp [smul_smul] end AffineSpace' namespace AffineMap variable {k : Type*} {V : Type*} (P : Type*) [CommRing k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] {ι : Type*} (s : Finset ι) -- TODO: define `affineMap.proj`, `affineMap.fst`, `affineMap.snd` /-- A weighted sum, as an affine map on the points involved. -/ def weightedVSubOfPoint (w : ι → k) : (ι → P) × P →ᵃ[k] V where toFun p := s.weightedVSubOfPoint p.fst p.snd w linear := ∑ i ∈ s, w i • ((LinearMap.proj i).comp (LinearMap.fst _ _ _) - LinearMap.snd _ _ _) map_vadd' := by rintro ⟨p, b⟩ ⟨v, b'⟩ simp [LinearMap.sum_apply, Finset.weightedVSubOfPoint, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, ← sub_add_eq_add_sub, smul_add, Finset.sum_add_distrib] end AffineMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Independent.lean
import Mathlib.Data.Fin.VecNotation import Mathlib.Data.Sign.Basic import Mathlib.LinearAlgebra.AffineSpace.Combination import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv import Mathlib.LinearAlgebra.Basis.VectorSpace /-! # Affine independence This file defines affinely independent families of points. ## Main definitions * `AffineIndependent` defines affinely independent families of points as those where no nontrivial weighted subtraction is `0`. This is proved equivalent to two other formulations: linear independence of the results of subtracting a base point in the family from the other points in the family, or any equal affine combinations having the same weights. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Finset Function Module open scoped Affine section AffineIndependent variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] {ι : Type*} /-- An indexed family is said to be affinely independent if no nontrivial weighted subtractions (where the sum of weights is 0) are 0. -/ def AffineIndependent (p : ι → P) : Prop := ∀ (s : Finset ι) (w : ι → k), ∑ i ∈ s, w i = 0 → s.weightedVSub p w = (0 : V) → ∀ i ∈ s, w i = 0 /-- The definition of `AffineIndependent`. -/ theorem affineIndependent_def (p : ι → P) : AffineIndependent k p ↔ ∀ (s : Finset ι) (w : ι → k), ∑ i ∈ s, w i = 0 → s.weightedVSub p w = (0 : V) → ∀ i ∈ s, w i = 0 := Iff.rfl /-- A family with at most one point is affinely independent. -/ theorem affineIndependent_of_subsingleton [Subsingleton ι] (p : ι → P) : AffineIndependent k p := fun _ _ h _ i hi => Fintype.eq_of_subsingleton_of_sum_eq h i hi /-- A family indexed by a `Fintype` is affinely independent if and only if no nontrivial weighted subtractions over `Finset.univ` (where the sum of the weights is 0) are 0. -/ theorem affineIndependent_iff_of_fintype [Fintype ι] (p : ι → P) : AffineIndependent k p ↔ ∀ w : ι → k, ∑ i, w i = 0 → Finset.univ.weightedVSub p w = (0 : V) → ∀ i, w i = 0 := by constructor · exact fun h w hw hs i => h Finset.univ w hw hs i (Finset.mem_univ _) · intro h s w hw hs i hi rw [Finset.weightedVSub_indicator_subset _ _ (Finset.subset_univ s)] at hs rw [← Finset.sum_indicator_subset _ (Finset.subset_univ s)] at hw replace h := h ((↑s : Set ι).indicator w) hw hs i simpa [hi] using h @[simp] lemma affineIndependent_vadd {p : ι → P} {v : V} : AffineIndependent k (v +ᵥ p) ↔ AffineIndependent k p := by simp +contextual [AffineIndependent, weightedVSub_vadd] protected alias ⟨AffineIndependent.of_vadd, AffineIndependent.vadd⟩ := affineIndependent_vadd @[simp] lemma affineIndependent_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] {p : ι → V} {a : G} : AffineIndependent k (a • p) ↔ AffineIndependent k p := by simp +contextual [AffineIndependent, ← smul_comm (α := V) a, ← smul_sum, smul_eq_zero_iff_eq] protected alias ⟨AffineIndependent.of_smul, AffineIndependent.smul⟩ := affineIndependent_smul /-- A family is affinely independent if and only if the differences from a base point in that family are linearly independent. -/ theorem affineIndependent_iff_linearIndependent_vsub (p : ι → P) (i1 : ι) : AffineIndependent k p ↔ LinearIndependent k fun i : { x // x ≠ i1 } => (p i -ᵥ p i1 : V) := by classical constructor · intro h rw [linearIndependent_iff'] intro s g hg i hi set f : ι → k := fun x => if hx : x = i1 then -∑ y ∈ s, g y else g ⟨x, hx⟩ with hfdef let s2 : Finset ι := insert i1 (s.map (Embedding.subtype _)) have hfg : ∀ x : { x // x ≠ i1 }, g x = f x := by grind rw [hfg] have hf : ∑ ι ∈ s2, f ι = 0 := by rw [Finset.sum_insert (Finset.notMem_map_subtype_of_not_property s (Classical.not_not.2 rfl)), Finset.sum_subtype_map_embedding fun x _ => (hfg x).symm] rw [hfdef] dsimp only rw [dif_pos rfl] exact neg_add_cancel _ have hs2 : s2.weightedVSub p f = (0 : V) := by set f2 : ι → V := fun x => f x • (p x -ᵥ p i1) with hf2def set g2 : { x // x ≠ i1 } → V := fun x => g x • (p x -ᵥ p i1) have hf2g2 : ∀ x : { x // x ≠ i1 }, f2 x = g2 x := by simp only [g2, hf2def] refine fun x => ?_ rw [hfg] rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s2 f p hf (p i1), Finset.weightedVSubOfPoint_insert, Finset.weightedVSubOfPoint_apply, Finset.sum_subtype_map_embedding fun x _ => hf2g2 x] exact hg exact h s2 f hf hs2 i (Finset.mem_insert_of_mem (Finset.mem_map.2 ⟨i, hi, rfl⟩)) · intro h rw [linearIndependent_iff'] at h intro s w hw hs i hi rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s w p hw (p i1), ← s.weightedVSubOfPoint_erase w p i1, Finset.weightedVSubOfPoint_apply] at hs let f : ι → V := fun i => w i • (p i -ᵥ p i1) have hs2 : (∑ i ∈ (s.erase i1).subtype fun i => i ≠ i1, f i) = 0 := by rw [← hs] convert Finset.sum_subtype_of_mem f fun x => Finset.ne_of_mem_erase have h2 := h ((s.erase i1).subtype fun i => i ≠ i1) (fun x => w x) hs2 simp_rw [Finset.mem_subtype] at h2 have h2b : ∀ i ∈ s, i ≠ i1 → w i = 0 := fun i his hi => h2 ⟨i, hi⟩ (Finset.mem_erase_of_ne_of_mem hi his) exact Finset.eq_zero_of_sum_eq_zero hw h2b i hi /-- A set is affinely independent if and only if the differences from a base point in that set are linearly independent. -/ theorem affineIndependent_set_iff_linearIndependent_vsub {s : Set P} {p₁ : P} (hp₁ : p₁ ∈ s) : AffineIndependent k (fun p => p : s → P) ↔ LinearIndependent k (fun v => v : (fun p => (p -ᵥ p₁ : V)) '' (s \ {p₁}) → V) := by rw [affineIndependent_iff_linearIndependent_vsub k (fun p => p : s → P) ⟨p₁, hp₁⟩] constructor · intro h have hv : ∀ v : (fun p => (p -ᵥ p₁ : V)) '' (s \ {p₁}), (v : V) +ᵥ p₁ ∈ s \ {p₁} := fun v => (vsub_left_injective p₁).mem_set_image.1 ((vadd_vsub (v : V) p₁).symm ▸ v.property) let f : (fun p : P => (p -ᵥ p₁ : V)) '' (s \ {p₁}) → { x : s // x ≠ ⟨p₁, hp₁⟩ } := fun x => ⟨⟨(x : V) +ᵥ p₁, Set.mem_of_mem_diff (hv x)⟩, fun hx => Set.notMem_of_mem_diff (hv x) (Subtype.ext_iff.1 hx)⟩ convert h.comp f fun x1 x2 hx => Subtype.ext (vadd_right_cancel p₁ (Subtype.ext_iff.1 (Subtype.ext_iff.1 hx))) ext v exact (vadd_vsub (v : V) p₁).symm · intro h let f : { x : s // x ≠ ⟨p₁, hp₁⟩ } → (fun p : P => (p -ᵥ p₁ : V)) '' (s \ {p₁}) := fun x => ⟨((x : s) : P) -ᵥ p₁, ⟨x, ⟨⟨(x : s).property, fun hx => x.property (Subtype.ext hx)⟩, rfl⟩⟩⟩ convert h.comp f fun x1 x2 hx => Subtype.ext (Subtype.ext (vsub_left_cancel (Subtype.ext_iff.1 hx))) /-- A set of nonzero vectors is linearly independent if and only if, given a point `p₁`, the vectors added to `p₁` and `p₁` itself are affinely independent. -/ theorem linearIndependent_set_iff_affineIndependent_vadd_union_singleton {s : Set V} (hs : ∀ v ∈ s, v ≠ (0 : V)) (p₁ : P) : LinearIndependent k (fun v => v : s → V) ↔ AffineIndependent k (fun p => p : ({p₁} ∪ (fun v => v +ᵥ p₁) '' s : Set P) → P) := by rw [affineIndependent_set_iff_linearIndependent_vsub k (Set.mem_union_left _ (Set.mem_singleton p₁))] have h : (fun p => (p -ᵥ p₁ : V)) '' (({p₁} ∪ (fun v => v +ᵥ p₁) '' s) \ {p₁}) = s := by simp_rw [Set.union_diff_left, Set.image_diff (vsub_left_injective p₁), Set.image_image, Set.image_singleton, vsub_self, vadd_vsub, Set.image_id'] exact Set.diff_singleton_eq_self fun h => hs 0 h rfl rw [h] /-- A family is affinely independent if and only if any affine combinations (with sum of weights 1) that evaluate to the same point have equal `Set.indicator`. -/ theorem affineIndependent_iff_indicator_eq_of_affineCombination_eq (p : ι → P) : AffineIndependent k p ↔ ∀ (s1 s2 : Finset ι) (w1 w2 : ι → k), ∑ i ∈ s1, w1 i = 1 → ∑ i ∈ s2, w2 i = 1 → s1.affineCombination k p w1 = s2.affineCombination k p w2 → Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2 := by classical constructor · intro ha s1 s2 w1 w2 hw1 hw2 heq ext i by_cases hi : i ∈ s1 ∪ s2 · rw [← sub_eq_zero] rw [← Finset.sum_indicator_subset w1 (s1.subset_union_left (s₂ := s2))] at hw1 rw [← Finset.sum_indicator_subset w2 (s1.subset_union_right)] at hw2 have hws : (∑ i ∈ s1 ∪ s2, (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) i) = 0 := by simp [hw1, hw2] rw [Finset.affineCombination_indicator_subset w1 p (s1.subset_union_left (s₂ := s2)), Finset.affineCombination_indicator_subset w2 p s1.subset_union_right, ← @vsub_eq_zero_iff_eq V, Finset.affineCombination_vsub] at heq exact ha (s1 ∪ s2) (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) hws heq i hi · simp_all · intro ha s w hw hs i0 hi0 let w1 : ι → k := Function.update (Function.const ι 0) i0 1 have hw1 : ∑ i ∈ s, w1 i = 1 := by rw [Finset.sum_update_of_mem hi0] simp only [Finset.sum_const_zero, add_zero, const_apply] have hw1s : s.affineCombination k p w1 = p i0 := s.affineCombination_of_eq_one_of_eq_zero w1 p hi0 (Function.update_self ..) fun _ _ hne => Function.update_of_ne hne .. let w2 := w + w1 have hw2 : ∑ i ∈ s, w2 i = 1 := by simp_all only [w2, Pi.add_apply, Finset.sum_add_distrib, zero_add] have hw2s : s.affineCombination k p w2 = p i0 := by simp_all only [w2, ← Finset.weightedVSub_vadd_affineCombination, zero_vadd] replace ha := ha s s w2 w1 hw2 hw1 (hw1s.symm ▸ hw2s) have hws : w2 i0 - w1 i0 = 0 := by rw [← Finset.mem_coe] at hi0 rw [← Set.indicator_of_mem hi0 w2, ← Set.indicator_of_mem hi0 w1, ha, sub_self] simpa [w2] using hws /-- A finite family is affinely independent if and only if any affine combinations (with sum of weights 1) that evaluate to the same point are equal. -/ theorem affineIndependent_iff_eq_of_fintype_affineCombination_eq [Fintype ι] (p : ι → P) : AffineIndependent k p ↔ ∀ w1 w2 : ι → k, ∑ i, w1 i = 1 → ∑ i, w2 i = 1 → Finset.univ.affineCombination k p w1 = Finset.univ.affineCombination k p w2 → w1 = w2 := by rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq] constructor · intro h w1 w2 hw1 hw2 hweq simpa only [Set.indicator_univ, Finset.coe_univ] using h _ _ w1 w2 hw1 hw2 hweq · intro h s1 s2 w1 w2 hw1 hw2 hweq have hw1' : (∑ i, (s1 : Set ι).indicator w1 i) = 1 := by rwa [Finset.sum_indicator_subset _ (Finset.subset_univ s1)] have hw2' : (∑ i, (s2 : Set ι).indicator w2 i) = 1 := by rwa [Finset.sum_indicator_subset _ (Finset.subset_univ s2)] rw [Finset.affineCombination_indicator_subset w1 p (Finset.subset_univ s1), Finset.affineCombination_indicator_subset w2 p (Finset.subset_univ s2)] at hweq exact h _ _ hw1' hw2' hweq variable {k} /-- If we single out one member of an affine-independent family of points and affinely transport all others along the line joining them to this member, the resulting new family of points is affine- independent. This is the affine version of `LinearIndependent.units_smul`. -/ theorem AffineIndependent.units_lineMap {p : ι → P} (hp : AffineIndependent k p) (j : ι) (w : ι → Units k) : AffineIndependent k fun i => AffineMap.lineMap (p j) (p i) (w i : k) := by rw [affineIndependent_iff_linearIndependent_vsub k _ j] at hp ⊢ simp only [AffineMap.lineMap_vsub_left, AffineMap.coe_const, AffineMap.lineMap_same, const_apply] exact hp.units_smul fun i => w i theorem AffineIndependent.indicator_eq_of_affineCombination_eq {p : ι → P} (ha : AffineIndependent k p) (s₁ s₂ : Finset ι) (w₁ w₂ : ι → k) (hw₁ : ∑ i ∈ s₁, w₁ i = 1) (hw₂ : ∑ i ∈ s₂, w₂ i = 1) (h : s₁.affineCombination k p w₁ = s₂.affineCombination k p w₂) : Set.indicator (↑s₁) w₁ = Set.indicator (↑s₂) w₂ := (affineIndependent_iff_indicator_eq_of_affineCombination_eq k p).1 ha s₁ s₂ w₁ w₂ hw₁ hw₂ h /-- An affinely independent family is injective, if the underlying ring is nontrivial. -/ protected theorem AffineIndependent.injective [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) : Function.Injective p := by intro i j hij rw [affineIndependent_iff_linearIndependent_vsub _ _ j] at ha by_contra hij' refine ha.ne_zero ⟨i, hij'⟩ (vsub_eq_zero_iff_eq.mpr ?_) simp_all only [ne_eq] /-- If a family is affinely independent, so is any subfamily given by composition of an embedding into index type with the original family. -/ theorem AffineIndependent.comp_embedding {ι2 : Type*} (f : ι2 ↪ ι) {p : ι → P} (ha : AffineIndependent k p) : AffineIndependent k (p ∘ f) := by classical intro fs w hw hs i0 hi0 let fs' := fs.map f let w' i := if h : ∃ i2, f i2 = i then w h.choose else 0 have hw' : ∀ i2 : ι2, w' (f i2) = w i2 := by intro i2 have h : ∃ i : ι2, f i = f i2 := ⟨i2, rfl⟩ have hs : h.choose = i2 := f.injective h.choose_spec simp_rw [w', dif_pos h, hs] have hw's : ∑ i ∈ fs', w' i = 0 := by rw [← hw, Finset.sum_map] simp [hw'] have hs' : fs'.weightedVSub p w' = (0 : V) := by rw [← hs, Finset.weightedVSub_map] congr with i simp_all only [comp_apply] rw [← ha fs' w' hw's hs' (f i0) ((Finset.mem_map' _).2 hi0), hw'] /-- If a family is affinely independent, so is any subfamily indexed by a subtype of the index type. -/ protected theorem AffineIndependent.subtype {p : ι → P} (ha : AffineIndependent k p) (s : Set ι) : AffineIndependent k fun i : s => p i := ha.comp_embedding (Embedding.subtype _) /-- If an indexed family of points is affinely independent, so is the corresponding set of points. -/ protected theorem AffineIndependent.range {p : ι → P} (ha : AffineIndependent k p) : AffineIndependent k (fun x => x : Set.range p → P) := by let f : Set.range p → ι := fun x => x.property.choose have hf : ∀ x, p (f x) = x := fun x => x.property.choose_spec let fe : Set.range p ↪ ι := ⟨f, fun x₁ x₂ he => Subtype.ext (hf x₁ ▸ hf x₂ ▸ he ▸ rfl)⟩ convert ha.comp_embedding fe ext simp [fe, hf] theorem affineIndependent_equiv {ι' : Type*} (e : ι ≃ ι') {p : ι' → P} : AffineIndependent k (p ∘ e) ↔ AffineIndependent k p := by refine ⟨?_, AffineIndependent.comp_embedding e.toEmbedding⟩ intro h have : p = p ∘ e ∘ e.symm.toEmbedding := by ext simp rw [this] exact h.comp_embedding e.symm.toEmbedding /-- If a set of points is affinely independent, so is any subset. -/ protected theorem AffineIndependent.mono {s t : Set P} (ha : AffineIndependent k (fun x => x : t → P)) (hs : s ⊆ t) : AffineIndependent k (fun x => x : s → P) := ha.comp_embedding (s.embeddingOfSubset t hs) /-- If the range of an injective indexed family of points is affinely independent, so is that family. -/ theorem AffineIndependent.of_set_of_injective {p : ι → P} (ha : AffineIndependent k (fun x => x : Set.range p → P)) (hi : Function.Injective p) : AffineIndependent k p := ha.comp_embedding (⟨fun i => ⟨p i, Set.mem_range_self _⟩, fun _ _ h => hi (Subtype.mk_eq_mk.1 h)⟩ : ι ↪ Set.range p) /-- If an affine combination of affinely independent points lies in the affine span of a subset of those points, all weights outside that subset are zero. -/ lemma AffineIndependent.eq_zero_of_affineCombination_mem_affineSpan {p : ι → P} (ha : AffineIndependent k p) {fs : Finset ι} {w : ι → k} (hw : ∑ i ∈ fs, w i = 1) {s : Set ι} (hm : fs.affineCombination k p w ∈ affineSpan k (p '' s)) {i : ι} (hifs : i ∈ fs) (his : i ∉ s) : w i = 0 := by obtain ⟨fs', w', hfs's, hw', he⟩ := eq_affineCombination_of_mem_affineSpan_image hm have hi' : (fs : Set ι).indicator w i = 0 := by rw [ha.indicator_eq_of_affineCombination_eq fs fs' w w' hw hw' he] exact Set.indicator_of_notMem (Set.notMem_subset hfs's his) w' rw [Set.indicator_apply_eq_zero] at hi' exact hi' (Finset.mem_coe.2 hifs) lemma AffineIndependent.indicator_extend_eq_of_affineCombination_comp_embedding_eq {ι₂ : Type*} {p : ι → P} (ha : AffineIndependent k p) {s₁ : Finset ι} {s₂ : Finset ι₂} {w₁ : ι → k} {w₂ : ι₂ → k} (hw₁ : ∑ i ∈ s₁, w₁ i = 1) (hw₂ : ∑ i ∈ s₂, w₂ i = 1) (e : ι₂ ↪ ι) (h : s₂.affineCombination k (p ∘ e) w₂ = s₁.affineCombination k p w₁) : Set.indicator (s₂.map e) (extend e w₂ 0) = Set.indicator s₁ w₁ := by have hw₂e : extend e w₂ 0 ∘ e = w₂ := extend_comp e.injective _ _ rw [← hw₂e, ← affineCombination_map] at h refine (ha.indicator_eq_of_affineCombination_eq s₁ (s₂.map e) _ _ hw₁ ?_ h.symm).symm rw [sum_map] convert hw₂ with i hi exact e.injective.extend_apply _ _ _ lemma AffineIndependent.indicator_extend_eq_of_affineCombination_comp_embedding_eq_of_fintype [Fintype ι] {ι₂ : Type*} [Fintype ι₂] {p : ι → P} (ha : AffineIndependent k p) {w₁ : ι → k} {w₂ : ι₂ → k} (hw₁ : ∑ i, w₁ i = 1) (hw₂ : ∑ i, w₂ i = 1) (e : ι₂ ↪ ι) (h : Finset.univ.affineCombination k (p ∘ e) w₂ = Finset.univ.affineCombination k p w₁) : Set.indicator (Set.range e) (extend e w₂ 0) = w₁ := by simpa using ha.indicator_extend_eq_of_affineCombination_comp_embedding_eq hw₁ hw₂ e h section Composition variable {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AffineSpace V₂ P₂] /-- If the image of a family of points in affine space under an affine transformation is affine- independent, then the original family of points is also affine-independent. -/ theorem AffineIndependent.of_comp {p : ι → P} (f : P →ᵃ[k] P₂) (hai : AffineIndependent k (f ∘ p)) : AffineIndependent k p := by rcases isEmpty_or_nonempty ι with h | h · apply affineIndependent_of_subsingleton obtain ⟨i⟩ := h rw [affineIndependent_iff_linearIndependent_vsub k p i] simp_rw [affineIndependent_iff_linearIndependent_vsub k (f ∘ p) i, Function.comp_apply, ← f.linearMap_vsub] at hai exact LinearIndependent.of_comp f.linear hai /-- The image of a family of points in affine space, under an injective affine transformation, is affine-independent. -/ theorem AffineIndependent.map' {p : ι → P} (hai : AffineIndependent k p) (f : P →ᵃ[k] P₂) (hf : Function.Injective f) : AffineIndependent k (f ∘ p) := by rcases isEmpty_or_nonempty ι with h | h · apply affineIndependent_of_subsingleton obtain ⟨i⟩ := h rw [affineIndependent_iff_linearIndependent_vsub k p i] at hai simp_rw [affineIndependent_iff_linearIndependent_vsub k (f ∘ p) i, Function.comp_apply, ← f.linearMap_vsub] have hf' : LinearMap.ker f.linear = ⊥ := by rwa [LinearMap.ker_eq_bot, f.linear_injective_iff] exact LinearIndependent.map' hai f.linear hf' /-- Injective affine maps preserve affine independence. -/ theorem AffineMap.affineIndependent_iff {p : ι → P} (f : P →ᵃ[k] P₂) (hf : Function.Injective f) : AffineIndependent k (f ∘ p) ↔ AffineIndependent k p := ⟨AffineIndependent.of_comp f, fun hai => AffineIndependent.map' hai f hf⟩ /-- Affine equivalences preserve affine independence of families of points. -/ theorem AffineEquiv.affineIndependent_iff {p : ι → P} (e : P ≃ᵃ[k] P₂) : AffineIndependent k (e ∘ p) ↔ AffineIndependent k p := e.toAffineMap.affineIndependent_iff e.toEquiv.injective /-- Affine equivalences preserve affine independence of subsets. -/ theorem AffineEquiv.affineIndependent_set_of_eq_iff {s : Set P} (e : P ≃ᵃ[k] P₂) : AffineIndependent k ((↑) : e '' s → P₂) ↔ AffineIndependent k ((↑) : s → P) := by have : e ∘ ((↑) : s → P) = ((↑) : e '' s → P₂) ∘ (e : P ≃ P₂).image s := rfl simp [← e.affineIndependent_iff, this, affineIndependent_equiv] end Composition /-- If a family is affinely independent, the infimum of the affine spans of points indexed by two subsets equals the affine span of points indexed by the intersection of those subsets, if the underlying ring is nontrivial. -/ lemma AffineIndependent.inf_affineSpan_eq_affineSpan_inter [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) (s₁ s₂ : Set ι) : affineSpan k (p '' s₁) ⊓ affineSpan k (p '' s₂) = affineSpan k (p '' (s₁ ∩ s₂)) := by classical ext p' simp_rw [AffineSubspace.mem_inf_iff, Set.image_eq_range, mem_affineSpan_iff_eq_affineCombination, ← Finset.eq_affineCombination_subset_iff_eq_affineCombination_subtype] constructor · rintro ⟨⟨fs₁, hfs₁, w₁, hw₁, rfl⟩, ⟨fs₂, hfs₂, w₂, hw₂, hw₁₂⟩⟩ rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq] at ha replace ha := ha fs₁ fs₂ w₁ w₂ hw₁ hw₂ hw₁₂ refine ⟨fs₁ ∩ fs₂, by grind, w₁, ?_, ?_⟩ · rw [← hw₁, ← fs₁.sum_inter_add_sum_diff fs₂, eq_comm] convert add_zero _ refine Finset.sum_eq_zero ?_ intro i hi rw [← Set.indicator_of_mem (s := ↑fs₁) (by grind) w₁, ha, Set.indicator_of_notMem (by grind)] · rw [affineCombination_indicator_subset w₁ p Finset.inter_subset_left] refine affineCombination_congr (k := k) (P := P) _ ?_ (fun _ _ ↦ rfl) intro i hi rw [coe_inter, ← Set.indicator_indicator, Set.indicator_of_mem (by simpa using hi), Set.indicator_apply] simp only [mem_coe, left_eq_ite_iff] intro hi₂ rw [← Set.indicator_of_mem (s := ↑fs₁) (by simpa using hi) w₁, ha] simp [hi₂] · grind /-- If a family is affinely independent, and the spans of points indexed by two subsets of the index type have a point in common, those subsets of the index type have an element in common, if the underlying ring is nontrivial. -/ theorem AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) {s1 s2 : Set ι} {p0 : P} (hp0s1 : p0 ∈ affineSpan k (p '' s1)) (hp0s2 : p0 ∈ affineSpan k (p '' s2)) : ∃ i : ι, i ∈ s1 ∩ s2 := by have hp0' : p0 ∈ affineSpan k (p '' s1) ⊓ affineSpan k (p '' s2) := ⟨hp0s1, hp0s2⟩ rw [ha.inf_affineSpan_eq_affineSpan_inter] at hp0' rw [← Set.Nonempty] by_contra he rw [Set.not_nonempty_iff_eq_empty] at he simp [he, AffineSubspace.notMem_bot] at hp0' /-- If a family is affinely independent, the spans of points indexed by disjoint subsets of the index type are disjoint, if the underlying ring is nontrivial. -/ theorem AffineIndependent.affineSpan_disjoint_of_disjoint [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) {s1 s2 : Set ι} (hd : Disjoint s1 s2) : Disjoint (affineSpan k (p '' s1) : Set P) (affineSpan k (p '' s2)) := by refine Set.disjoint_left.2 fun p0 hp0s1 hp0s2 => ?_ obtain ⟨i, hi⟩ := ha.exists_mem_inter_of_exists_mem_inter_affineSpan hp0s1 hp0s2 exact Set.disjoint_iff.1 hd hi /-- If a family is affinely independent, a point in the family is in the span of some of the points given by a subset of the index type if and only if that point's index is in the subset, if the underlying ring is nontrivial. -/ @[simp] protected theorem AffineIndependent.mem_affineSpan_iff [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) (i : ι) (s : Set ι) : p i ∈ affineSpan k (p '' s) ↔ i ∈ s := by constructor · intro hs have h := AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan ha hs (mem_affineSpan k (Set.mem_image_of_mem _ (Set.mem_singleton _))) rwa [← Set.nonempty_def, Set.inter_singleton_nonempty] at h · exact fun h => mem_affineSpan k (Set.mem_image_of_mem p h) /-- If a family is affinely independent, a point in the family is not in the affine span of the other points, if the underlying ring is nontrivial. -/ theorem AffineIndependent.notMem_affineSpan_diff [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) (i : ι) (s : Set ι) : p i ∉ affineSpan k (p '' (s \ {i})) := by simp [ha] @[deprecated (since := "2025-05-23")] alias AffineIndependent.not_mem_affineSpan_diff := AffineIndependent.notMem_affineSpan_diff theorem exists_nontrivial_relation_sum_zero_of_not_affine_ind {t : Finset V} (h : ¬AffineIndependent k ((↑) : t → V)) : ∃ f : V → k, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by classical rw [affineIndependent_iff_of_fintype] at h simp only [exists_prop, not_forall] at h obtain ⟨w, hw, hwt, i, hi⟩ := h simp only [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ w ((↑) : t → V) hw 0, vsub_eq_sub, Finset.weightedVSubOfPoint_apply, sub_zero] at hwt let f : ∀ x : V, x ∈ t → k := fun x hx => w ⟨x, hx⟩ refine ⟨fun x => if hx : x ∈ t then f x hx else (0 : k), ?_, ?_, by use i; simp [f, hi]⟩ on_goal 1 => suffices (∑ e ∈ t, dite (e ∈ t) (fun hx => f e hx • e) fun _ => 0) = 0 by convert this rename V => x by_cases hx : x ∈ t <;> simp [hx] all_goals simp only [f, Finset.sum_dite_of_true fun _ h => h, Finset.mk_coe, hwt, hw] variable {s : Finset ι} {w w₁ w₂ : ι → k} {p : ι → V} /-- Viewing a module as an affine space modelled on itself, we can characterise affine independence in terms of linear combinations. -/ theorem affineIndependent_iff {ι} {p : ι → V} : AffineIndependent k p ↔ ∀ (s : Finset ι) (w : ι → k), s.sum w = 0 → ∑ e ∈ s, w e • p e = 0 → ∀ e ∈ s, w e = 0 := forall₃_congr fun s w hw => by simp [s.weightedVSub_eq_linear_combination hw] lemma AffineIndependent.eq_zero_of_sum_eq_zero (hp : AffineIndependent k p) (hw₀ : ∑ i ∈ s, w i = 0) (hw₁ : ∑ i ∈ s, w i • p i = 0) : ∀ i ∈ s, w i = 0 := affineIndependent_iff.1 hp _ _ hw₀ hw₁ lemma AffineIndependent.eq_of_sum_eq_sum (hp : AffineIndependent k p) (hw : ∑ i ∈ s, w₁ i = ∑ i ∈ s, w₂ i) (hwp : ∑ i ∈ s, w₁ i • p i = ∑ i ∈ s, w₂ i • p i) : ∀ i ∈ s, w₁ i = w₂ i := by refine fun i hi ↦ sub_eq_zero.1 (hp.eq_zero_of_sum_eq_zero (w := w₁ - w₂) ?_ ?_ _ hi) <;> simpa [sub_mul, sub_smul, sub_eq_zero] lemma AffineIndependent.eq_zero_of_sum_eq_zero_subtype {s : Finset V} (hp : AffineIndependent k ((↑) : s → V)) {w : V → k} (hw₀ : ∑ x ∈ s, w x = 0) (hw₁ : ∑ x ∈ s, w x • x = 0) : ∀ x ∈ s, w x = 0 := by rw [← sum_attach] at hw₀ hw₁ exact fun x hx ↦ hp.eq_zero_of_sum_eq_zero hw₀ hw₁ ⟨x, hx⟩ (mem_univ _) lemma AffineIndependent.eq_of_sum_eq_sum_subtype {s : Finset V} (hp : AffineIndependent k ((↑) : s → V)) {w₁ w₂ : V → k} (hw : ∑ i ∈ s, w₁ i = ∑ i ∈ s, w₂ i) (hwp : ∑ i ∈ s, w₁ i • i = ∑ i ∈ s, w₂ i • i) : ∀ i ∈ s, w₁ i = w₂ i := by refine fun i hi => sub_eq_zero.1 (hp.eq_zero_of_sum_eq_zero_subtype (w := w₁ - w₂) ?_ ?_ _ hi) <;> simpa [sub_mul, sub_smul, sub_eq_zero] /-- Given an affinely independent family of points, a weighted subtraction lies in the `vectorSpan` of two points given as affine combinations if and only if it is a weighted subtraction with weights a multiple of the difference between the weights of the two points. -/ theorem weightedVSub_mem_vectorSpan_pair {p : ι → P} (h : AffineIndependent k p) {w w₁ w₂ : ι → k} {s : Finset ι} (hw : ∑ i ∈ s, w i = 0) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) : s.weightedVSub p w ∈ vectorSpan k ({s.affineCombination k p w₁, s.affineCombination k p w₂} : Set P) ↔ ∃ r : k, ∀ i ∈ s, w i = r * (w₁ i - w₂ i) := by rw [mem_vectorSpan_pair] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with ⟨r, hr⟩ refine ⟨r, fun i hi => ?_⟩ rw [s.affineCombination_vsub, ← s.weightedVSub_const_smul, ← sub_eq_zero, ← map_sub] at hr have hw' : (∑ j ∈ s, (r • (w₁ - w₂) - w) j) = 0 := by simp_rw [Pi.sub_apply, Pi.smul_apply, Pi.sub_apply, smul_sub, Finset.sum_sub_distrib, ← Finset.smul_sum, hw, hw₁, hw₂, sub_self] have hr' := h s _ hw' hr i hi rw [eq_comm, ← sub_eq_zero, ← smul_eq_mul] exact hr' · rcases h with ⟨r, hr⟩ refine ⟨r, ?_⟩ let w' i := r * (w₁ i - w₂ i) change ∀ i ∈ s, w i = w' i at hr rw [s.weightedVSub_congr hr fun _ _ => rfl, s.affineCombination_vsub, ← s.weightedVSub_const_smul] congr /-- Given an affinely independent family of points, an affine combination lies in the span of two points given as affine combinations if and only if it is an affine combination with weights those of one point plus a multiple of the difference between the weights of the two points. -/ theorem affineCombination_mem_affineSpan_pair {p : ι → P} (h : AffineIndependent k p) {w w₁ w₂ : ι → k} {s : Finset ι} (_ : ∑ i ∈ s, w i = 1) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) : s.affineCombination k p w ∈ line[k, s.affineCombination k p w₁, s.affineCombination k p w₂] ↔ ∃ r : k, ∀ i ∈ s, w i = r * (w₂ i - w₁ i) + w₁ i := by rw [← vsub_vadd (s.affineCombination k p w) (s.affineCombination k p w₁), AffineSubspace.vadd_mem_iff_mem_direction _ (left_mem_affineSpan_pair _ _ _), direction_affineSpan, s.affineCombination_vsub, Set.pair_comm, weightedVSub_mem_vectorSpan_pair h _ hw₂ hw₁] · simp only [Pi.sub_apply, sub_eq_iff_eq_add] · simp_all only [Pi.sub_apply, Finset.sum_sub_distrib, sub_self] end AffineIndependent section DivisionRing variable {k : Type*} {V : Type*} {P : Type*} [DivisionRing k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] {ι : Type*} /-- An affinely independent set of points can be extended to such a set that spans the whole space. -/ theorem exists_subset_affineIndependent_affineSpan_eq_top {s : Set P} (h : AffineIndependent k (fun p => p : s → P)) : ∃ t : Set P, s ⊆ t ∧ AffineIndependent k (fun p => p : t → P) ∧ affineSpan k t = ⊤ := by rcases s.eq_empty_or_nonempty with (rfl | ⟨p₁, hp₁⟩) · have p₁ : P := AddTorsor.nonempty.some let hsv := Basis.ofVectorSpace k V have hsvi := hsv.linearIndependent have hsvt := hsv.span_eq rw [Basis.coe_ofVectorSpace] at hsvi hsvt have h0 : ∀ v : V, v ∈ Basis.ofVectorSpaceIndex k V → v ≠ 0 := by intro v hv simpa [hsv] using hsv.ne_zero ⟨v, hv⟩ rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k h0 p₁] at hsvi exact ⟨{p₁} ∪ (fun v => v +ᵥ p₁) '' _, Set.empty_subset _, hsvi, affineSpan_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt⟩ · rw [affineIndependent_set_iff_linearIndependent_vsub k hp₁] at h let bsv := Basis.extend h have hsvi := bsv.linearIndependent have hsvt := bsv.span_eq rw [Basis.coe_extend] at hsvi hsvt rw [linearIndependent_subtype_iff] at hsvi h have hsv := h.subset_extend (Set.subset_univ _) have h0 : ∀ v : V, v ∈ h.extend (Set.subset_univ _) → v ≠ 0 := by intro v hv simpa [bsv] using bsv.ne_zero ⟨v, hv⟩ rw [← linearIndependent_subtype_iff, linearIndependent_set_iff_affineIndependent_vadd_union_singleton k h0 p₁] at hsvi refine ⟨{p₁} ∪ (fun v => v +ᵥ p₁) '' h.extend (Set.subset_univ _), ?_, ?_⟩ · refine Set.Subset.trans ?_ (Set.union_subset_union_right _ (Set.image_mono hsv)) simp [Set.image_image] · use hsvi exact affineSpan_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt variable (k V) theorem exists_affineIndependent (s : Set P) : ∃ t ⊆ s, affineSpan k t = affineSpan k s ∧ AffineIndependent k ((↑) : t → P) := by rcases s.eq_empty_or_nonempty with (rfl | ⟨p, hp⟩) · exact ⟨∅, Set.empty_subset ∅, rfl, affineIndependent_of_subsingleton k _⟩ obtain ⟨b, hb₁, hb₂, hb₃⟩ := exists_linearIndependent k ((Equiv.vaddConst p).symm '' s) have hb₀ : ∀ v : V, v ∈ b → v ≠ 0 := fun v hv => hb₃.ne_zero (⟨v, hv⟩ : b) rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k hb₀ p] at hb₃ refine ⟨{p} ∪ Equiv.vaddConst p '' b, ?_, ?_, hb₃⟩ · apply Set.union_subset (Set.singleton_subset_iff.mpr hp) rwa [← (Equiv.vaddConst p).subset_symm_image b s] · rw [Equiv.coe_vaddConst_symm, ← vectorSpan_eq_span_vsub_set_right k hp] at hb₂ apply AffineSubspace.ext_of_direction_eq · have : Submodule.span k b = Submodule.span k (insert 0 b) := by simp simp only [direction_affineSpan, ← hb₂, Equiv.coe_vaddConst, Set.singleton_union, vectorSpan_eq_span_vsub_set_right k (Set.mem_insert p _), this] congr change (Equiv.vaddConst p).symm '' insert p (Equiv.vaddConst p '' b) = _ rw [Set.image_insert_eq, ← Set.image_comp] simp · use p simp only [Equiv.coe_vaddConst, Set.singleton_union, Set.mem_inter_iff] exact ⟨mem_affineSpan k (Set.mem_insert p _), mem_affineSpan k hp⟩ variable {V} /-- Two different points are affinely independent. -/ theorem affineIndependent_of_ne {p₁ p₂ : P} (h : p₁ ≠ p₂) : AffineIndependent k ![p₁, p₂] := by rw [affineIndependent_iff_linearIndependent_vsub k ![p₁, p₂] 0] let i₁ : { x // x ≠ (0 : Fin 2) } := ⟨1, by simp⟩ have he' : ∀ i, i = i₁ := by rintro ⟨i, hi⟩ ext fin_cases i · simp at hi · simp [i₁] haveI : Unique { x // x ≠ (0 : Fin 2) } := ⟨⟨i₁⟩, he'⟩ refine .of_subsingleton default ?_ rw [he' default] simpa using h.symm variable {k} /-- If all but one point of a family are affinely independent, and that point does not lie in the affine span of that family, the family is affinely independent. -/ theorem AffineIndependent.affineIndependent_of_notMem_span {p : ι → P} {i : ι} (ha : AffineIndependent k fun x : { y // y ≠ i } => p x) (hi : p i ∉ affineSpan k (p '' { x | x ≠ i })) : AffineIndependent k p := by classical intro s w hw hs let s' : Finset { y // y ≠ i } := s.subtype (· ≠ i) let p' : { y // y ≠ i } → P := fun x => p x by_cases his : i ∈ s ∧ w i ≠ 0 · refine False.elim (hi ?_) let wm : ι → k := -(w i)⁻¹ • w have hms : s.weightedVSub p wm = (0 : V) := by simp [wm, hs] have hwm : ∑ i ∈ s, wm i = 0 := by simp [wm, ← Finset.mul_sum, hw] have hwmi : wm i = -1 := by simp [wm, his.2] let w' : { y // y ≠ i } → k := fun x => wm x have hw' : ∑ x ∈ s', w' x = 1 := by simp_rw [w', s', Finset.sum_subtype_eq_sum_filter] rw [← s.sum_filter_add_sum_filter_not (· ≠ i)] at hwm simpa only [not_not, Finset.filter_eq' _ i, if_pos his.1, sum_singleton, hwmi, add_neg_eq_zero] using hwm rw [← s.affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one hms his.1 hwmi, ← (Subtype.range_coe : _ = { x | x ≠ i }), ← Set.range_comp, ← s.affineCombination_subtype_eq_filter] exact affineCombination_mem_affineSpan hw' p' · rw [not_and_or, Classical.not_not] at his let w' : { y // y ≠ i } → k := fun x => w x have hw' : ∑ x ∈ s', w' x = 0 := by simp_rw [w', s', Finset.sum_subtype_eq_sum_filter] rw [Finset.sum_filter_of_ne, hw] rintro x hxs hwx rfl exact hwx (his.neg_resolve_left hxs) have hs' : s'.weightedVSub p' w' = (0 : V) := by simp_rw [w', s', p', Finset.weightedVSub_subtype_eq_filter] rw [Finset.weightedVSub_filter_of_ne, hs] rintro x hxs hwx rfl exact hwx (his.neg_resolve_left hxs) intro j hj by_cases hji : j = i · rw [hji] at hj exact hji.symm ▸ his.neg_resolve_left hj · exact ha s' w' hw' hs' ⟨j, hji⟩ (Finset.mem_subtype.2 hj) @[deprecated (since := "2025-05-23")] alias AffineIndependent.affineIndependent_of_not_mem_span := AffineIndependent.affineIndependent_of_notMem_span /-- If distinct points `p₁` and `p₂` lie in `s` but `p₃` does not, the three points are affinely independent. -/ theorem affineIndependent_of_ne_of_mem_of_mem_of_notMem {s : AffineSubspace k P} {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∉ s) : AffineIndependent k ![p₁, p₂, p₃] := by have ha : AffineIndependent k fun x : { x : Fin 3 // x ≠ 2 } => ![p₁, p₂, p₃] x := by rw [← affineIndependent_equiv (finSuccAboveEquiv (2 : Fin 3))] convert affineIndependent_of_ne k hp₁p₂ ext x fin_cases x <;> rfl refine ha.affineIndependent_of_notMem_span ?_ intro h refine hp₃ ((AffineSubspace.le_def' _ s).1 ?_ p₃ h) simp_rw [affineSpan_le, Set.image_subset_iff, Set.subset_def, Set.mem_preimage] intro x fin_cases x <;> simp +decide [hp₁, hp₂] @[deprecated (since := "2025-05-23")] alias affineIndependent_of_ne_of_mem_of_mem_of_not_mem := affineIndependent_of_ne_of_mem_of_mem_of_notMem /-- If distinct points `p₁` and `p₃` lie in `s` but `p₂` does not, the three points are affinely independent. -/ theorem affineIndependent_of_ne_of_mem_of_notMem_of_mem {s : AffineSubspace k P} {p₁ p₂ p₃ : P} (hp₁p₃ : p₁ ≠ p₃) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∉ s) (hp₃ : p₃ ∈ s) : AffineIndependent k ![p₁, p₂, p₃] := by rw [← affineIndependent_equiv (Equiv.swap (1 : Fin 3) 2)] convert affineIndependent_of_ne_of_mem_of_mem_of_notMem hp₁p₃ hp₁ hp₃ hp₂ using 1 ext x fin_cases x <;> rfl @[deprecated (since := "2025-05-23")] alias affineIndependent_of_ne_of_mem_of_not_mem_of_mem := affineIndependent_of_ne_of_mem_of_notMem_of_mem /-- If distinct points `p₂` and `p₃` lie in `s` but `p₁` does not, the three points are affinely independent. -/ theorem affineIndependent_of_ne_of_notMem_of_mem_of_mem {s : AffineSubspace k P} {p₁ p₂ p₃ : P} (hp₂p₃ : p₂ ≠ p₃) (hp₁ : p₁ ∉ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) : AffineIndependent k ![p₁, p₂, p₃] := by rw [← affineIndependent_equiv (Equiv.swap (0 : Fin 3) 2)] convert affineIndependent_of_ne_of_mem_of_mem_of_notMem hp₂p₃.symm hp₃ hp₂ hp₁ using 1 ext x fin_cases x <;> rfl @[deprecated (since := "2025-05-23")] alias affineIndependent_of_ne_of_not_mem_of_mem_of_mem := affineIndependent_of_ne_of_notMem_of_mem_of_mem /-- If a family is affinely independent, we update any one point with a new point does not lie in the affine span of that family, the new family is affinely independent. -/ theorem AffineIndependent.affineIndependent_update_of_notMem_affineSpan [DecidableEq ι] {p : ι → P} (ha : AffineIndependent k p) {i : ι} {p₀ : P} (hp₀ : p₀ ∉ affineSpan k (p '' {x | x ≠ i})) : AffineIndependent k (Function.update p i p₀) := by set f : ι → P := Function.update p i p₀ with hf have h₁ : (fun x : {x | x ≠ i} ↦ p x) = fun x : {x | x ≠ i} ↦ f x := by ext x; aesop have h₂ : p '' {x | x ≠ i} = f '' {x | x ≠ i} := Set.image_congr <| by simpa using congr_fun h₁ replace ha : AffineIndependent k fun x : {x | x ≠ i} ↦ f x := h₁ ▸ AffineIndependent.subtype ha _ exact AffineIndependent.affineIndependent_of_notMem_span ha <| by aesop end DivisionRing section Ordered variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [LinearOrder k] [IsStrictOrderedRing k] [AddCommGroup V] variable [Module k V] [AffineSpace V P] {ι : Type*} /-- Given an affinely independent family of points, suppose that an affine combination lies in the span of two points given as affine combinations, and suppose that, for two indices, the coefficients in the first point in the span are zero and those in the second point in the span have the same sign. Then the coefficients in the combination lying in the span have the same sign. -/ theorem sign_eq_of_affineCombination_mem_affineSpan_pair {p : ι → P} (h : AffineIndependent k p) {w w₁ w₂ : ι → k} {s : Finset ι} (hw : ∑ i ∈ s, w i = 1) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) (hs : s.affineCombination k p w ∈ line[k, s.affineCombination k p w₁, s.affineCombination k p w₂]) {i j : ι} (hi : i ∈ s) (hj : j ∈ s) (hi0 : w₁ i = 0) (hj0 : w₁ j = 0) (hij : SignType.sign (w₂ i) = SignType.sign (w₂ j)) : SignType.sign (w i) = SignType.sign (w j) := by rw [affineCombination_mem_affineSpan_pair h hw hw₁ hw₂] at hs rcases hs with ⟨r, hr⟩ rw [hr i hi, hr j hj, hi0, hj0, add_zero, add_zero, sub_zero, sub_zero, sign_mul, sign_mul, hij] /-- Given an affinely independent family of points, suppose that an affine combination lies in the span of one point of that family and a combination of another two points of that family given by `lineMap` with coefficient between 0 and 1. Then the coefficients of those two points in the combination lying in the span have the same sign. -/ theorem sign_eq_of_affineCombination_mem_affineSpan_single_lineMap {p : ι → P} (h : AffineIndependent k p) {w : ι → k} {s : Finset ι} (hw : ∑ i ∈ s, w i = 1) {i₁ i₂ i₃ : ι} (h₁ : i₁ ∈ s) (h₂ : i₂ ∈ s) (h₃ : i₃ ∈ s) (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) {c : k} (hc0 : 0 < c) (hc1 : c < 1) (hs : s.affineCombination k p w ∈ line[k, p i₁, AffineMap.lineMap (p i₂) (p i₃) c]) : SignType.sign (w i₂) = SignType.sign (w i₃) := by classical rw [← s.affineCombination_affineCombinationSingleWeights k p h₁, ← s.affineCombination_affineCombinationLineMapWeights p h₂ h₃ c] at hs refine sign_eq_of_affineCombination_mem_affineSpan_pair h hw (s.sum_affineCombinationSingleWeights k h₁) (s.sum_affineCombinationLineMapWeights h₂ h₃ c) hs h₂ h₃ (Finset.affineCombinationSingleWeights_apply_of_ne k h₁₂.symm) (Finset.affineCombinationSingleWeights_apply_of_ne k h₁₃.symm) ?_ rw [Finset.affineCombinationLineMapWeights_apply_left h₂₃, Finset.affineCombinationLineMapWeights_apply_right h₂₃] simp_all only [sub_pos, sign_pos] end Ordered
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/AffineMap.lean
import Mathlib.Algebra.Order.Group.Pointwise.Interval import Mathlib.Algebra.Order.Module.Defs import Mathlib.LinearAlgebra.BilinearMap import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Prod import Mathlib.Tactic.Abel import Mathlib.Algebra.AddTorsor.Basic import Mathlib.LinearAlgebra.AffineSpace.Defs /-! # Affine maps This file defines affine maps. ## Main definitions * `AffineMap` is the type of affine maps between two affine spaces with the same ring `k`. Various basic examples of affine maps are defined, including `const`, `id`, `lineMap` and `homothety`. ## Notation * `P1 →ᵃ[k] P2` is a notation for `AffineMap k P1 P2`; * `AffineSpace V P`: a localized notation for `AddTorsor V P` defined in `LinearAlgebra.AffineSpace.Basic`. ## Implementation notes `outParam` is used in the definition of `[AddTorsor V P]` to make `V` an implicit argument (deduced from `P`) in most cases. As for modules, `k` is an explicit argument rather than implied by `P` or `V`. This file only provides purely algebraic definitions and results. Those depending on analysis or topology are defined elsewhere; see `Analysis.Normed.Affine.AddTorsor` and `Topology.Algebra.Affine`. ## References * https://en.wikipedia.org/wiki/Affine_space * https://en.wikipedia.org/wiki/Principal_homogeneous_space -/ open Affine /-- An `AffineMap k P1 P2` (notation: `P1 →ᵃ[k] P2`) is a map from `P1` to `P2` that induces a corresponding linear map from `V1` to `V2`. -/ structure AffineMap (k : Type*) {V1 : Type*} (P1 : Type*) {V2 : Type*} (P2 : Type*) [Ring k] [AddCommGroup V1] [Module k V1] [AffineSpace V1 P1] [AddCommGroup V2] [Module k V2] [AffineSpace V2 P2] where /-- The underlying function between the affine spaces `P1` and `P2`. -/ toFun : P1 → P2 /-- The linear map between the corresponding vector spaces `V1` and `V2`. This represents how the affine map acts on differences of points. -/ linear : V1 →ₗ[k] V2 map_vadd' : ∀ (p : P1) (v : V1), toFun (v +ᵥ p) = linear v +ᵥ toFun p /-- An `AffineMap k P1 P2` (notation: `P1 →ᵃ[k] P2`) is a map from `P1` to `P2` that induces a corresponding linear map from `V1` to `V2`. -/ notation:25 P1 " →ᵃ[" k:25 "] " P2:0 => AffineMap k P1 P2 instance AffineMap.instFunLike (k : Type*) {V1 : Type*} (P1 : Type*) {V2 : Type*} (P2 : Type*) [Ring k] [AddCommGroup V1] [Module k V1] [AffineSpace V1 P1] [AddCommGroup V2] [Module k V2] [AffineSpace V2 P2] : FunLike (P1 →ᵃ[k] P2) P1 P2 where coe := AffineMap.toFun coe_injective' := fun ⟨f, f_linear, f_add⟩ ⟨g, g_linear, g_add⟩ => fun (h : f = g) => by obtain ⟨p⟩ := (AddTorsor.nonempty : Nonempty P1) congr with v apply vadd_right_cancel (f p) rw [← f_add, h, ← g_add] namespace LinearMap variable {k : Type*} {V₁ : Type*} {V₂ : Type*} [Ring k] [AddCommGroup V₁] [Module k V₁] [AddCommGroup V₂] [Module k V₂] (f : V₁ →ₗ[k] V₂) /-- Reinterpret a linear map as an affine map. -/ def toAffineMap : V₁ →ᵃ[k] V₂ where toFun := f linear := f map_vadd' p v := f.map_add v p @[simp] theorem coe_toAffineMap : ⇑f.toAffineMap = f := rfl @[simp] theorem toAffineMap_linear : f.toAffineMap.linear = f := rfl end LinearMap namespace AffineMap variable {k : Type*} {V1 : Type*} {P1 : Type*} {V2 : Type*} {P2 : Type*} {V3 : Type*} {P3 : Type*} {V4 : Type*} {P4 : Type*} [Ring k] [AddCommGroup V1] [Module k V1] [AffineSpace V1 P1] [AddCommGroup V2] [Module k V2] [AffineSpace V2 P2] [AddCommGroup V3] [Module k V3] [AffineSpace V3 P3] [AddCommGroup V4] [Module k V4] [AffineSpace V4 P4] /-- Constructing an affine map and coercing back to a function produces the same map. -/ @[simp] theorem coe_mk (f : P1 → P2) (linear add) : ((mk f linear add : P1 →ᵃ[k] P2) : P1 → P2) = f := rfl /-- `toFun` is the same as the result of coercing to a function. -/ @[simp] theorem toFun_eq_coe (f : P1 →ᵃ[k] P2) : f.toFun = ⇑f := rfl /-- An affine map on the result of adding a vector to a point produces the same result as the linear map applied to that vector, added to the affine map applied to that point. -/ @[simp] theorem map_vadd (f : P1 →ᵃ[k] P2) (p : P1) (v : V1) : f (v +ᵥ p) = f.linear v +ᵥ f p := f.map_vadd' p v /-- The linear map on the result of subtracting two points is the result of subtracting the result of the affine map on those two points. -/ @[simp] theorem linearMap_vsub (f : P1 →ᵃ[k] P2) (p1 p2 : P1) : f.linear (p1 -ᵥ p2) = f p1 -ᵥ f p2 := by conv_rhs => rw [← vsub_vadd p1 p2, map_vadd, vadd_vsub] /-- Two affine maps are equal if they coerce to the same function. -/ @[ext] theorem ext {f g : P1 →ᵃ[k] P2} (h : ∀ p, f p = g p) : f = g := DFunLike.ext _ _ h theorem coeFn_injective : @Function.Injective (P1 →ᵃ[k] P2) (P1 → P2) (⇑) := DFunLike.coe_injective protected theorem congr_arg (f : P1 →ᵃ[k] P2) {x y : P1} (h : x = y) : f x = f y := congr_arg _ h protected theorem congr_fun {f g : P1 →ᵃ[k] P2} (h : f = g) (x : P1) : f x = g x := h ▸ rfl /-- Two affine maps are equal if they have equal linear maps and are equal at some point. -/ theorem ext_linear {f g : P1 →ᵃ[k] P2} (h₁ : f.linear = g.linear) {p : P1} (h₂ : f p = g p) : f = g := by ext q have hgl : g.linear (q -ᵥ p) = toFun g ((q -ᵥ p) +ᵥ q) -ᵥ toFun g q := by simp have := f.map_vadd' q (q -ᵥ p) rw [h₁, hgl, toFun_eq_coe, map_vadd, linearMap_vsub, h₂] at this simpa /-- Two affine maps are equal if they have equal linear maps and are equal at some point. -/ theorem ext_linear_iff {f g : P1 →ᵃ[k] P2} : f = g ↔ (f.linear = g.linear) ∧ (∃ p, f p = g p) := ⟨fun h ↦ ⟨congrArg _ h, by inhabit P1; exact default, by rw [h]⟩, fun h ↦ Exists.casesOn h.2 fun _ hp ↦ ext_linear h.1 hp⟩ variable (k P1) /-- The constant function as an `AffineMap`. -/ def const (p : P2) : P1 →ᵃ[k] P2 where toFun := Function.const P1 p linear := 0 map_vadd' _ _ := letI : AddAction V2 P2 := inferInstance by simp @[simp] theorem coe_const (p : P2) : ⇑(const k P1 p) = Function.const P1 p := rfl @[simp] theorem const_apply (p : P2) (q : P1) : (const k P1 p) q = p := rfl @[simp] theorem const_linear (p : P2) : (const k P1 p).linear = 0 := rfl variable {k P1} theorem linear_eq_zero_iff_exists_const (f : P1 →ᵃ[k] P2) : f.linear = 0 ↔ ∃ q, f = const k P1 q := by refine ⟨fun h => ?_, fun h => ?_⟩ · use f (Classical.arbitrary P1) ext rw [coe_const, Function.const_apply, ← @vsub_eq_zero_iff_eq V2, ← f.linearMap_vsub, h, LinearMap.zero_apply] · rcases h with ⟨q, rfl⟩ exact const_linear k P1 q instance nonempty : Nonempty (P1 →ᵃ[k] P2) := (AddTorsor.nonempty : Nonempty P2).map <| const k P1 /-- Construct an affine map by verifying the relation between the map and its linear part at one base point. Namely, this function takes a map `f : P₁ → P₂`, a linear map `f' : V₁ →ₗ[k] V₂`, and a point `p` such that for any other point `p'` we have `f p' = f' (p' -ᵥ p) +ᵥ f p`. -/ def mk' (f : P1 → P2) (f' : V1 →ₗ[k] V2) (p : P1) (h : ∀ p' : P1, f p' = f' (p' -ᵥ p) +ᵥ f p) : P1 →ᵃ[k] P2 where toFun := f linear := f' map_vadd' p' v := by rw [h, h p', vadd_vsub_assoc, f'.map_add, vadd_vadd] @[simp] theorem coe_mk' (f : P1 → P2) (f' : V1 →ₗ[k] V2) (p h) : ⇑(mk' f f' p h) = f := rfl @[simp] theorem mk'_linear (f : P1 → P2) (f' : V1 →ₗ[k] V2) (p h) : (mk' f f' p h).linear = f' := rfl section SMul variable {R : Type*} [Monoid R] [DistribMulAction R V2] [SMulCommClass k R V2] /-- The space of affine maps to a module inherits an `R`-action from the action on its codomain. -/ instance mulAction : MulAction R (P1 →ᵃ[k] V2) where smul c f := ⟨c • ⇑f, c • f.linear, fun p v => by simp [smul_add]⟩ one_smul _ := ext fun _ => one_smul _ _ mul_smul _ _ _ := ext fun _ => mul_smul _ _ _ @[simp, norm_cast] theorem coe_smul (c : R) (f : P1 →ᵃ[k] V2) : ⇑(c • f) = c • ⇑f := rfl @[simp] theorem smul_linear (t : R) (f : P1 →ᵃ[k] V2) : (t • f).linear = t • f.linear := rfl instance isCentralScalar [DistribMulAction Rᵐᵒᵖ V2] [IsCentralScalar R V2] : IsCentralScalar R (P1 →ᵃ[k] V2) where op_smul_eq_smul _r _x := ext fun _ => op_smul_eq_smul _ _ end SMul instance : Zero (P1 →ᵃ[k] V2) where zero := ⟨0, 0, fun _ _ => (zero_vadd _ _).symm⟩ instance : Add (P1 →ᵃ[k] V2) where add f g := ⟨f + g, f.linear + g.linear, fun p v => by simp [add_add_add_comm]⟩ instance : Sub (P1 →ᵃ[k] V2) where sub f g := ⟨f - g, f.linear - g.linear, fun p v => by simp [sub_add_sub_comm]⟩ instance : Neg (P1 →ᵃ[k] V2) where neg f := ⟨-f, -f.linear, fun p v => by simp [add_comm, map_vadd f]⟩ @[simp, norm_cast] theorem coe_zero : ⇑(0 : P1 →ᵃ[k] V2) = 0 := rfl @[simp, norm_cast] theorem coe_add (f g : P1 →ᵃ[k] V2) : ⇑(f + g) = f + g := rfl @[simp, norm_cast] theorem coe_neg (f : P1 →ᵃ[k] V2) : ⇑(-f) = -f := rfl @[simp, norm_cast] theorem coe_sub (f g : P1 →ᵃ[k] V2) : ⇑(f - g) = f - g := rfl @[simp] theorem zero_linear : (0 : P1 →ᵃ[k] V2).linear = 0 := rfl @[simp] theorem add_linear (f g : P1 →ᵃ[k] V2) : (f + g).linear = f.linear + g.linear := rfl @[simp] theorem sub_linear (f g : P1 →ᵃ[k] V2) : (f - g).linear = f.linear - g.linear := rfl @[simp] theorem neg_linear (f : P1 →ᵃ[k] V2) : (-f).linear = -f.linear := rfl /-- The set of affine maps to a vector space is an additive commutative group. -/ instance : AddCommGroup (P1 →ᵃ[k] V2) := coeFn_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _ /-- The space of affine maps from `P1` to `P2` is an affine space over the space of affine maps from `P1` to the vector space `V2` corresponding to `P2`. -/ instance : AffineSpace (P1 →ᵃ[k] V2) (P1 →ᵃ[k] P2) where vadd f g := ⟨fun p => f p +ᵥ g p, f.linear + g.linear, fun p v => by simp [vadd_vadd, add_right_comm]⟩ zero_vadd f := ext fun p => zero_vadd _ (f p) add_vadd f₁ f₂ f₃ := ext fun p => add_vadd (f₁ p) (f₂ p) (f₃ p) vsub f g := ⟨fun p => f p -ᵥ g p, f.linear - g.linear, fun p v => by simp [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, sub_add_eq_add_sub]⟩ vsub_vadd' f g := ext fun p => vsub_vadd (f p) (g p) vadd_vsub' f g := ext fun p => vadd_vsub (f p) (g p) @[simp] theorem vadd_apply (f : P1 →ᵃ[k] V2) (g : P1 →ᵃ[k] P2) (p : P1) : (f +ᵥ g) p = f p +ᵥ g p := rfl @[simp] theorem vadd_linear (f : P1 →ᵃ[k] V2) (g : P1 →ᵃ[k] P2) : (f +ᵥ g).linear = f.linear + g.linear := rfl @[simp] theorem vsub_apply (f g : P1 →ᵃ[k] P2) (p : P1) : (f -ᵥ g : P1 →ᵃ[k] V2) p = f p -ᵥ g p := rfl @[simp] theorem vsub_linear (f g : P1 →ᵃ[k] P2) : (f -ᵥ g).linear = f.linear - g.linear := rfl /-- `Prod.fst` as an `AffineMap`. -/ def fst : P1 × P2 →ᵃ[k] P1 where toFun := Prod.fst linear := LinearMap.fst k V1 V2 map_vadd' _ _ := rfl @[simp] theorem coe_fst : ⇑(fst : P1 × P2 →ᵃ[k] P1) = Prod.fst := rfl @[simp] theorem fst_linear : (fst : P1 × P2 →ᵃ[k] P1).linear = LinearMap.fst k V1 V2 := rfl /-- `Prod.snd` as an `AffineMap`. -/ def snd : P1 × P2 →ᵃ[k] P2 where toFun := Prod.snd linear := LinearMap.snd k V1 V2 map_vadd' _ _ := rfl @[simp] theorem coe_snd : ⇑(snd : P1 × P2 →ᵃ[k] P2) = Prod.snd := rfl @[simp] theorem snd_linear : (snd : P1 × P2 →ᵃ[k] P2).linear = LinearMap.snd k V1 V2 := rfl variable (k P1) /-- Identity map as an affine map. -/ nonrec def id : P1 →ᵃ[k] P1 where toFun := id linear := LinearMap.id map_vadd' _ _ := rfl /-- The identity affine map acts as the identity. -/ @[simp, norm_cast] theorem coe_id : ⇑(id k P1) = _root_.id := rfl @[simp] theorem id_linear : (id k P1).linear = LinearMap.id := rfl variable {P1} /-- The identity affine map acts as the identity. -/ theorem id_apply (p : P1) : id k P1 p = p := rfl variable {k} instance : Inhabited (P1 →ᵃ[k] P1) := ⟨id k P1⟩ /-- Composition of affine maps. -/ @[simps linear] def comp (f : P2 →ᵃ[k] P3) (g : P1 →ᵃ[k] P2) : P1 →ᵃ[k] P3 where toFun := f ∘ g linear := f.linear.comp g.linear map_vadd' := by intro p v rw [Function.comp_apply, g.map_vadd, f.map_vadd] rfl /-- Composition of affine maps acts as applying the two functions. -/ @[simp] theorem coe_comp (f : P2 →ᵃ[k] P3) (g : P1 →ᵃ[k] P2) : ⇑(f.comp g) = f ∘ g := rfl /-- Composition of affine maps acts as applying the two functions. -/ theorem comp_apply (f : P2 →ᵃ[k] P3) (g : P1 →ᵃ[k] P2) (p : P1) : f.comp g p = f (g p) := rfl @[simp] theorem comp_id (f : P1 →ᵃ[k] P2) : f.comp (id k P1) = f := ext fun _ => rfl @[simp] theorem id_comp (f : P1 →ᵃ[k] P2) : (id k P2).comp f = f := ext fun _ => rfl theorem comp_assoc (f₃₄ : P3 →ᵃ[k] P4) (f₂₃ : P2 →ᵃ[k] P3) (f₁₂ : P1 →ᵃ[k] P2) : (f₃₄.comp f₂₃).comp f₁₂ = f₃₄.comp (f₂₃.comp f₁₂) := rfl instance : Monoid (P1 →ᵃ[k] P1) where one := id k P1 mul := comp one_mul := id_comp mul_one := comp_id mul_assoc := comp_assoc @[simp] theorem coe_mul (f g : P1 →ᵃ[k] P1) : ⇑(f * g) = f ∘ g := rfl @[simp] theorem coe_one : ⇑(1 : P1 →ᵃ[k] P1) = _root_.id := rfl /-- `AffineMap.linear` on endomorphisms is a `MonoidHom`. -/ @[simps] def linearHom : (P1 →ᵃ[k] P1) →* V1 →ₗ[k] V1 where toFun := linear map_one' := rfl map_mul' _ _ := rfl @[simp] theorem linear_injective_iff (f : P1 →ᵃ[k] P2) : Function.Injective f.linear ↔ Function.Injective f := by obtain ⟨p⟩ := (inferInstance : Nonempty P1) have h : ⇑f.linear = (Equiv.vaddConst (f p)).symm ∘ f ∘ Equiv.vaddConst p := by ext v simp [f.map_vadd] rw [h, Equiv.comp_injective, Equiv.injective_comp] @[simp] theorem linear_surjective_iff (f : P1 →ᵃ[k] P2) : Function.Surjective f.linear ↔ Function.Surjective f := by obtain ⟨p⟩ := (inferInstance : Nonempty P1) have h : ⇑f.linear = (Equiv.vaddConst (f p)).symm ∘ f ∘ Equiv.vaddConst p := by ext v simp [f.map_vadd] rw [h, Equiv.comp_surjective, Equiv.surjective_comp] @[simp] theorem linear_bijective_iff (f : P1 →ᵃ[k] P2) : Function.Bijective f.linear ↔ Function.Bijective f := and_congr f.linear_injective_iff f.linear_surjective_iff theorem image_vsub_image {s t : Set P1} (f : P1 →ᵃ[k] P2) : f '' s -ᵥ f '' t = f.linear '' (s -ᵥ t) := by ext v simp only [Set.mem_vsub, Set.mem_image, exists_exists_and_eq_and, ← f.linearMap_vsub] grind /-- The product of two affine maps is an affine map. -/ @[simps linear] def prod (f : P1 →ᵃ[k] P2) (g : P1 →ᵃ[k] P3) : P1 →ᵃ[k] P2 × P3 where toFun := Pi.prod f g linear := f.linear.prod g.linear map_vadd' := by simp theorem coe_prod (f : P1 →ᵃ[k] P2) (g : P1 →ᵃ[k] P3) : prod f g = Pi.prod f g := rfl @[simp] theorem prod_apply (f : P1 →ᵃ[k] P2) (g : P1 →ᵃ[k] P3) (p : P1) : prod f g p = (f p, g p) := rfl /-- `Prod.map` of two affine maps. -/ @[simps linear] def prodMap (f : P1 →ᵃ[k] P2) (g : P3 →ᵃ[k] P4) : P1 × P3 →ᵃ[k] P2 × P4 where toFun := Prod.map f g linear := f.linear.prodMap g.linear map_vadd' := by simp theorem coe_prodMap (f : P1 →ᵃ[k] P2) (g : P3 →ᵃ[k] P4) : ⇑(f.prodMap g) = Prod.map f g := rfl @[simp] theorem prodMap_apply (f : P1 →ᵃ[k] P2) (g : P3 →ᵃ[k] P4) (x) : f.prodMap g x = (f x.1, g x.2) := rfl /-! ### Definition of `AffineMap.lineMap` and lemmas about it -/ /-- The affine map from `k` to `P1` sending `0` to `p₀` and `1` to `p₁`. -/ def lineMap (p₀ p₁ : P1) : k →ᵃ[k] P1 := ((LinearMap.id : k →ₗ[k] k).smulRight (p₁ -ᵥ p₀)).toAffineMap +ᵥ const k k p₀ theorem coe_lineMap (p₀ p₁ : P1) : (lineMap p₀ p₁ : k → P1) = fun c => c • (p₁ -ᵥ p₀) +ᵥ p₀ := rfl theorem lineMap_apply (p₀ p₁ : P1) (c : k) : lineMap p₀ p₁ c = c • (p₁ -ᵥ p₀) +ᵥ p₀ := rfl theorem lineMap_apply_module' (p₀ p₁ : V1) (c : k) : lineMap p₀ p₁ c = c • (p₁ - p₀) + p₀ := rfl theorem lineMap_apply_module (p₀ p₁ : V1) (c : k) : lineMap p₀ p₁ c = (1 - c) • p₀ + c • p₁ := by simp [lineMap_apply_module', smul_sub, sub_smul]; abel theorem lineMap_apply_ring' (a b c : k) : lineMap a b c = c * (b - a) + a := rfl theorem lineMap_apply_ring (a b c : k) : lineMap a b c = (1 - c) * a + c * b := lineMap_apply_module a b c theorem lineMap_vadd_apply (p : P1) (v : V1) (c : k) : lineMap p (v +ᵥ p) c = c • v +ᵥ p := by rw [lineMap_apply, vadd_vsub] @[simp] theorem lineMap_linear (p₀ p₁ : P1) : (lineMap p₀ p₁ : k →ᵃ[k] P1).linear = LinearMap.id.smulRight (p₁ -ᵥ p₀) := add_zero _ theorem lineMap_same_apply (p : P1) (c : k) : lineMap p p c = p := by simp [lineMap_apply] @[simp] theorem lineMap_same (p : P1) : lineMap p p = const k k p := ext <| lineMap_same_apply p @[simp] theorem lineMap_apply_zero (p₀ p₁ : P1) : lineMap p₀ p₁ (0 : k) = p₀ := by simp [lineMap_apply] @[simp] theorem lineMap_apply_one (p₀ p₁ : P1) : lineMap p₀ p₁ (1 : k) = p₁ := by simp [lineMap_apply] @[simp] theorem lineMap_eq_lineMap_iff [NoZeroSMulDivisors k V1] {p₀ p₁ : P1} {c₁ c₂ : k} : lineMap p₀ p₁ c₁ = lineMap p₀ p₁ c₂ ↔ p₀ = p₁ ∨ c₁ = c₂ := by rw [lineMap_apply, lineMap_apply, ← @vsub_eq_zero_iff_eq V1, vadd_vsub_vadd_cancel_right, ← sub_smul, smul_eq_zero, sub_eq_zero, vsub_eq_zero_iff_eq, or_comm, eq_comm] @[simp] theorem lineMap_eq_left_iff [NoZeroSMulDivisors k V1] {p₀ p₁ : P1} {c : k} : lineMap p₀ p₁ c = p₀ ↔ p₀ = p₁ ∨ c = 0 := by rw [← @lineMap_eq_lineMap_iff k V1, lineMap_apply_zero] @[simp] theorem lineMap_eq_right_iff [NoZeroSMulDivisors k V1] {p₀ p₁ : P1} {c : k} : lineMap p₀ p₁ c = p₁ ↔ p₀ = p₁ ∨ c = 1 := by rw [← @lineMap_eq_lineMap_iff k V1, lineMap_apply_one] variable (k) in theorem lineMap_injective [NoZeroSMulDivisors k V1] {p₀ p₁ : P1} (h : p₀ ≠ p₁) : Function.Injective (lineMap p₀ p₁ : k → P1) := fun _c₁ _c₂ hc => (lineMap_eq_lineMap_iff.mp hc).resolve_left h @[simp] theorem apply_lineMap (f : P1 →ᵃ[k] P2) (p₀ p₁ : P1) (c : k) : f (lineMap p₀ p₁ c) = lineMap (f p₀) (f p₁) c := by simp [lineMap_apply] @[simp] theorem comp_lineMap (f : P1 →ᵃ[k] P2) (p₀ p₁ : P1) : f.comp (lineMap p₀ p₁) = lineMap (f p₀) (f p₁) := ext <| f.apply_lineMap p₀ p₁ @[simp] theorem fst_lineMap (p₀ p₁ : P1 × P2) (c : k) : (lineMap p₀ p₁ c).1 = lineMap p₀.1 p₁.1 c := fst.apply_lineMap p₀ p₁ c @[simp] theorem snd_lineMap (p₀ p₁ : P1 × P2) (c : k) : (lineMap p₀ p₁ c).2 = lineMap p₀.2 p₁.2 c := snd.apply_lineMap p₀ p₁ c theorem lineMap_symm (p₀ p₁ : P1) : lineMap p₀ p₁ = (lineMap p₁ p₀).comp (lineMap (1 : k) (0 : k)) := by simp @[simp] theorem lineMap_apply_one_sub (p₀ p₁ : P1) (c : k) : lineMap p₀ p₁ (1 - c) = lineMap p₁ p₀ c := by rw [lineMap_symm p₀, comp_apply] congr simp [lineMap_apply] @[simp] theorem lineMap_vsub_left (p₀ p₁ : P1) (c : k) : lineMap p₀ p₁ c -ᵥ p₀ = c • (p₁ -ᵥ p₀) := vadd_vsub _ _ @[simp] theorem left_vsub_lineMap (p₀ p₁ : P1) (c : k) : p₀ -ᵥ lineMap p₀ p₁ c = c • (p₀ -ᵥ p₁) := by rw [← neg_vsub_eq_vsub_rev, lineMap_vsub_left, ← smul_neg, neg_vsub_eq_vsub_rev] @[simp] theorem lineMap_vsub_right (p₀ p₁ : P1) (c : k) : lineMap p₀ p₁ c -ᵥ p₁ = (1 - c) • (p₀ -ᵥ p₁) := by rw [← lineMap_apply_one_sub, lineMap_vsub_left] @[simp] theorem right_vsub_lineMap (p₀ p₁ : P1) (c : k) : p₁ -ᵥ lineMap p₀ p₁ c = (1 - c) • (p₁ -ᵥ p₀) := by rw [← lineMap_apply_one_sub, left_vsub_lineMap] theorem lineMap_vadd_lineMap (v₁ v₂ : V1) (p₁ p₂ : P1) (c : k) : lineMap v₁ v₂ c +ᵥ lineMap p₁ p₂ c = lineMap (v₁ +ᵥ p₁) (v₂ +ᵥ p₂) c := ((fst : V1 × P1 →ᵃ[k] V1) +ᵥ (snd : V1 × P1 →ᵃ[k] P1)).apply_lineMap (v₁, p₁) (v₂, p₂) c theorem lineMap_vsub_lineMap (p₁ p₂ p₃ p₄ : P1) (c : k) : lineMap p₁ p₂ c -ᵥ lineMap p₃ p₄ c = lineMap (p₁ -ᵥ p₃) (p₂ -ᵥ p₄) c := ((fst : P1 × P1 →ᵃ[k] P1) -ᵥ (snd : P1 × P1 →ᵃ[k] P1)).apply_lineMap (_, _) (_, _) c @[simp] lemma lineMap_lineMap_right (p₀ p₁ : P1) (c d : k) : lineMap p₀ (lineMap p₀ p₁ c) d = lineMap p₀ p₁ (d * c) := by simp [lineMap_apply, mul_smul] @[simp] lemma lineMap_lineMap_left (p₀ p₁ : P1) (c d : k) : lineMap (lineMap p₀ p₁ c) p₁ d = lineMap p₀ p₁ (1 - (1 - d) * (1 - c)) := by simp_rw [lineMap_apply_one_sub, ← lineMap_apply_one_sub p₁, lineMap_lineMap_right] lemma lineMap_mono [LinearOrder k] [Preorder V1] [AddRightMono V1] [SMulPosMono k V1] {p₀ p₁ : V1} (h : p₀ ≤ p₁) : Monotone (lineMap (k := k) p₀ p₁) := by intro x y hxy suffices x • (p₁ - p₀) ≤ y • (p₁ - p₀) by simpa [lineMap] gcongr simpa lemma lineMap_anti [LinearOrder k] [Preorder V1] [AddLeftMono V1] [SMulPosMono k V1] {p₀ p₁ : V1} (h : p₁ ≤ p₀) : Antitone (lineMap (k := k) p₀ p₁) := by intro x y hxy suffices y • (p₁ - p₀) ≤ x • (p₁ - p₀) by simpa [lineMap] rw [← neg_le_neg_iff, ← smul_neg, ← smul_neg] gcongr simpa /-- Decomposition of an affine map in the special case when the point space and vector space are the same. -/ theorem decomp (f : V1 →ᵃ[k] V2) : (f : V1 → V2) = ⇑f.linear + fun _ => f 0 := by ext x calc f x = f.linear x +ᵥ f 0 := by rw [← f.map_vadd, vadd_eq_add, add_zero] _ = (f.linear + fun _ : V1 => f 0) x := rfl /-- Decomposition of an affine map in the special case when the point space and vector space are the same. -/ theorem decomp' (f : V1 →ᵃ[k] V2) : (f.linear : V1 → V2) = ⇑f - fun _ => f 0 := by rw [decomp] simp only [LinearMap.map_zero, Pi.add_apply, add_sub_cancel_right, zero_add] theorem image_uIcc {k : Type*} [Field k] [LinearOrder k] [IsStrictOrderedRing k] (f : k →ᵃ[k] k) (a b : k) : f '' Set.uIcc a b = Set.uIcc (f a) (f b) := by have : ⇑f = (fun x => x + f 0) ∘ fun x => x * (f 1 - f 0) := by ext x change f x = x • (f 1 -ᵥ f 0) +ᵥ f 0 rw [← f.linearMap_vsub, ← f.linear.map_smul, ← f.map_vadd] simp only [vsub_eq_sub, add_zero, mul_one, vadd_eq_add, sub_zero, smul_eq_mul] rw [this, Set.image_comp] simp only [Set.image_add_const_uIcc, Set.image_mul_const_uIcc, Function.comp_apply] section variable {ι : Type*} {V : ι → Type*} {P : ι → Type*} [∀ i, AddCommGroup (V i)] [∀ i, Module k (V i)] [∀ i, AddTorsor (V i) (P i)] /-- Evaluation at a point as an affine map. -/ def proj (i : ι) : (∀ i : ι, P i) →ᵃ[k] P i where toFun f := f i linear := @LinearMap.proj k ι _ V _ _ i map_vadd' _ _ := rfl @[simp] theorem proj_apply (i : ι) (f : ∀ i, P i) : @proj k _ ι V P _ _ _ i f = f i := rfl @[simp] theorem proj_linear (i : ι) : (@proj k _ ι V P _ _ _ i).linear = @LinearMap.proj k ι _ V _ _ i := rfl theorem pi_lineMap_apply (f g : ∀ i, P i) (c : k) (i : ι) : lineMap f g c i = lineMap (f i) (g i) c := (proj i : (∀ i, P i) →ᵃ[k] P i).apply_lineMap f g c end end AffineMap namespace AffineMap variable {R k V1 P1 V2 P2 V3 P3 : Type*} section Ring variable [Ring k] [AddCommGroup V1] [AffineSpace V1 P1] [AddCommGroup V2] [AffineSpace V2 P2] variable [AddCommGroup V3] [AffineSpace V3 P3] [Module k V1] [Module k V2] [Module k V3] section DistribMulAction variable [Monoid R] [DistribMulAction R V2] [SMulCommClass k R V2] /-- The space of affine maps to a module inherits an `R`-action from the action on its codomain. -/ instance distribMulAction : DistribMulAction R (P1 →ᵃ[k] V2) where smul_add _ _ _ := ext fun _ => smul_add _ _ _ smul_zero _ := ext fun _ => smul_zero _ end DistribMulAction section Module variable [Semiring R] [Module R V2] [SMulCommClass k R V2] /-- The space of affine maps taking values in an `R`-module is an `R`-module. -/ instance : Module R (P1 →ᵃ[k] V2) := { AffineMap.distribMulAction with add_smul := fun _ _ _ => ext fun _ => add_smul _ _ _ zero_smul := fun _ => ext fun _ => zero_smul _ _ } variable (R) /-- The space of affine maps between two modules is linearly equivalent to the product of the domain with the space of linear maps, by taking the value of the affine map at `(0 : V1)` and the linear part. See note [bundled maps over different rings] -/ @[simps] def toConstProdLinearMap : (V1 →ᵃ[k] V2) ≃ₗ[R] V2 × (V1 →ₗ[k] V2) where toFun f := ⟨f 0, f.linear⟩ invFun p := p.2.toAffineMap + const k V1 p.1 left_inv f := by ext rw [f.decomp] simp right_inv := by rintro ⟨v, f⟩ ext <;> simp [const_linear] map_add' := by simp map_smul' := by simp end Module section Pi variable {ι : Type*} {φv φp : ι → Type*} [(i : ι) → AddCommGroup (φv i)] [(i : ι) → Module k (φv i)] [(i : ι) → AffineSpace (φv i) (φp i)] /-- `pi` construction for affine maps. From a family of affine maps it produces an affine map into a family of affine spaces. This is the affine version of `LinearMap.pi`. -/ @[simps linear] def pi (f : (i : ι) → (P1 →ᵃ[k] φp i)) : P1 →ᵃ[k] ((i : ι) → φp i) where toFun m a := f a m linear := LinearMap.pi (fun a ↦ (f a).linear) map_vadd' _ _ := funext fun _ ↦ map_vadd _ _ _ --fp for when the image is a dependent AffineSpace φp i, fv for when the --image is a Module φv i, f' for when the image isn't dependent. variable (fp : (i : ι) → (P1 →ᵃ[k] φp i)) (fv : (i : ι) → (P1 →ᵃ[k] φv i)) (f' : ι → P1 →ᵃ[k] P2) @[simp] theorem pi_apply (c : P1) (i : ι) : pi fp c i = fp i c := rfl theorem pi_comp (g : P3 →ᵃ[k] P1) : (pi fp).comp g = pi (fun i => (fp i).comp g) := rfl theorem pi_eq_zero : pi fv = 0 ↔ ∀ i, fv i = 0 := by simp only [AffineMap.ext_iff, funext_iff, pi_apply] exact forall_comm theorem pi_zero : pi (fun _ ↦ 0 : (i : ι) → P1 →ᵃ[k] φv i) = 0 := by ext; rfl theorem proj_pi (i : ι) : (proj i).comp (pi fp) = fp i := ext fun _ => rfl section Ext variable [Finite ι] [DecidableEq ι] {f g : ((i : ι) → φv i) →ᵃ[k] P2} /-- Two affine maps from a Pi-type of modules `(i : ι) → φv i` are equal if they are equal in their operation on `Pi.single` and at zero. Analogous to `LinearMap.pi_ext`. See also `pi_ext_nonempty`, which instead of agreement at zero requires `Nonempty ι`. -/ theorem pi_ext_zero (h : ∀ i x, f (Pi.single i x) = g (Pi.single i x)) (h₂ : f 0 = g 0) : f = g := by apply ext_linear · apply LinearMap.pi_ext intro i x have s₁ := h i x have s₂ := f.map_vadd 0 (Pi.single i x) have s₃ := g.map_vadd 0 (Pi.single i x) rw [vadd_eq_add, add_zero] at s₂ s₃ replace h₂ := h i 0 simp only [Pi.single_zero] at h₂ rwa [s₂, s₃, h₂, vadd_right_cancel_iff] at s₁ · exact h₂ /-- Two affine maps from a Pi-type of modules `(i : ι) → φv i` are equal if they are equal in their operation on `Pi.single` and `ι` is nonempty. Analogous to `LinearMap.pi_ext`. See also `pi_ext_zero`, which instead of `Nonempty ι` requires agreement at 0. -/ theorem pi_ext_nonempty [Nonempty ι] (h : ∀ i x, f (Pi.single i x) = g (Pi.single i x)) : f = g := by apply pi_ext_zero h inhabit ι rw [← Pi.single_zero default] apply h /-- This is used as the ext lemma instead of `AffineMap.pi_ext_nonempty` for reasons explained in note [partially-applied ext lemmas]. Analogous to `LinearMap.pi_ext'` -/ @[ext (iff := false)] theorem pi_ext_nonempty' [Nonempty ι] (h : ∀ i, f.comp (LinearMap.single _ _ i).toAffineMap = g.comp (LinearMap.single _ _ i).toAffineMap) : f = g := by refine pi_ext_nonempty fun i x => ?_ convert AffineMap.congr_fun (h i) x end Ext end Pi end Ring section CommRing variable [CommRing k] [AddCommGroup V1] [AffineSpace V1 P1] [AddCommGroup V2] variable [Module k V1] [Module k V2] /-- `homothety c r` is the homothety (also known as dilation) about `c` with scale factor `r`. -/ def homothety (c : P1) (r : k) : P1 →ᵃ[k] P1 := r • (id k P1 -ᵥ const k P1 c) +ᵥ const k P1 c theorem homothety_def (c : P1) (r : k) : homothety c r = r • (id k P1 -ᵥ const k P1 c) +ᵥ const k P1 c := rfl theorem coe_homothety (c : P1) (r : k) : homothety c r = fun p => r • (p -ᵥ c) +ᵥ c := rfl theorem homothety_apply (c : P1) (r : k) (p : P1) : homothety c r p = r • (p -ᵥ c : V1) +ᵥ c := rfl @[simp] theorem homothety_linear (c : P1) (r : k) : (homothety c r).linear = r • LinearMap.id := by simp [homothety] theorem homothety_eq_lineMap (c : P1) (r : k) (p : P1) : homothety c r p = lineMap c p r := rfl @[simp] theorem homothety_one (c : P1) : homothety c (1 : k) = id k P1 := by ext p simp [homothety_apply] @[simp] theorem homothety_apply_same (c : P1) (r : k) : homothety c r c = c := lineMap_same_apply c r theorem homothety_mul_apply (c : P1) (r₁ r₂ : k) (p : P1) : homothety c (r₁ * r₂) p = homothety c r₁ (homothety c r₂ p) := by simp only [homothety_apply, mul_smul, vadd_vsub] theorem homothety_mul (c : P1) (r₁ r₂ : k) : homothety c (r₁ * r₂) = (homothety c r₁).comp (homothety c r₂) := ext <| homothety_mul_apply c r₁ r₂ @[simp] theorem homothety_zero (c : P1) : homothety c (0 : k) = const k P1 c := by ext p simp [homothety_apply] @[simp] theorem homothety_add (c : P1) (r₁ r₂ : k) : homothety c (r₁ + r₂) = r₁ • (id k P1 -ᵥ const k P1 c) +ᵥ homothety c r₂ := by simp only [homothety_def, add_smul, vadd_vadd] /-- `homothety` as a multiplicative monoid homomorphism. -/ def homothetyHom (c : P1) : k →* P1 →ᵃ[k] P1 where toFun := homothety c map_one' := homothety_one c map_mul' := homothety_mul c @[simp] theorem coe_homothetyHom (c : P1) : ⇑(homothetyHom c : k →* _) = homothety c := rfl /-- `homothety` as an affine map. -/ def homothetyAffine (c : P1) : k →ᵃ[k] P1 →ᵃ[k] P1 := ⟨homothety c, (LinearMap.lsmul k _).flip (id k P1 -ᵥ const k P1 c), Function.swap (homothety_add c)⟩ @[simp] theorem coe_homothetyAffine (c : P1) : ⇑(homothetyAffine c : k →ᵃ[k] _) = homothety c := rfl end CommRing end AffineMap section variable {𝕜 E F : Type*} [Ring 𝕜] [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] /-- Applying an affine map to an affine combination of two points yields an affine combination of the images. -/ theorem Convex.combo_affine_apply {x y : E} {a b : 𝕜} {f : E →ᵃ[𝕜] F} (h : a + b = 1) : f (a • x + b • y) = a • f x + b • f y := by simp only [Convex.combo_eq_smul_sub_add h, ← vsub_eq_sub] exact f.apply_lineMap _ _ _ end
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Pointwise.lean
import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic /-! # Pointwise instances on `AffineSubspace`s This file provides the additive action `AffineSubspace.pointwiseAddAction` in the `Pointwise` locale. -/ open Affine Pointwise open Set variable {M k V P V₁ P₁ V₂ P₂ : Type*} namespace AffineSubspace section Ring variable [Ring k] variable [AddCommGroup V] [Module k V] [AffineSpace V P] variable [AddCommGroup V₁] [Module k V₁] [AddTorsor V₁ P₁] variable [AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂] /-- The additive action on an affine subspace corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseVAdd : VAdd V (AffineSubspace k P) where vadd x s := s.map (AffineEquiv.constVAdd k P x) scoped[Pointwise] attribute [instance] AffineSubspace.pointwiseVAdd @[simp, norm_cast] lemma coe_pointwise_vadd (v : V) (s : AffineSubspace k P) : ((v +ᵥ s : AffineSubspace k P) : Set P) = v +ᵥ (s : Set P) := rfl /-- The additive action on an affine subspace corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseAddAction : AddAction V (AffineSubspace k P) := SetLike.coe_injective.addAction _ coe_pointwise_vadd scoped[Pointwise] attribute [instance] AffineSubspace.pointwiseAddAction theorem pointwise_vadd_eq_map (v : V) (s : AffineSubspace k P) : v +ᵥ s = s.map (AffineEquiv.constVAdd k P v) := rfl theorem vadd_mem_pointwise_vadd_iff {v : V} {s : AffineSubspace k P} {p : P} : v +ᵥ p ∈ v +ᵥ s ↔ p ∈ s := vadd_mem_vadd_set_iff @[simp] theorem pointwise_vadd_bot (v : V) : v +ᵥ (⊥ : AffineSubspace k P) = ⊥ := by ext; simp [pointwise_vadd_eq_map, map_bot] @[simp] lemma pointwise_vadd_top (v : V) : v +ᵥ (⊤ : AffineSubspace k P) = ⊤ := by ext; simp [pointwise_vadd_eq_map, vadd_eq_iff_eq_neg_vadd] theorem pointwise_vadd_direction (v : V) (s : AffineSubspace k P) : (v +ᵥ s).direction = s.direction := by rw [pointwise_vadd_eq_map, map_direction] exact Submodule.map_id _ theorem pointwise_vadd_span (v : V) (s : Set P) : v +ᵥ affineSpan k s = affineSpan k (v +ᵥ s) := map_span _ s theorem map_pointwise_vadd (f : P₁ →ᵃ[k] P₂) (v : V₁) (s : AffineSubspace k P₁) : (v +ᵥ s).map f = f.linear v +ᵥ s.map f := by rw [pointwise_vadd_eq_map, pointwise_vadd_eq_map, map_map, map_map] congr 1 ext exact f.map_vadd _ _ section SMul variable [Monoid M] [DistribMulAction M V] [SMulCommClass M k V] {a : M} {s : AffineSubspace k V} {p : V} /-- The multiplicative action on an affine subspace corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. TODO: generalize to include `SMul (P ≃ᵃ[k] P) (AffineSubspace k P)`, which acts on `P` with a `VAdd` version of a `DistribMulAction`. -/ protected def pointwiseSMul : SMul M (AffineSubspace k V) where smul a s := s.map (DistribMulAction.toLinearMap k _ a).toAffineMap scoped[Pointwise] attribute [instance] AffineSubspace.pointwiseSMul @[simp, norm_cast] lemma coe_smul (a : M) (s : AffineSubspace k V) : ↑(a • s) = a • (s : Set V) := rfl /-- The multiplicative action on an affine subspace corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. TODO: generalize to include `SMul (P ≃ᵃ[k] P) (AffineSubspace k P)`, which acts on `P` with a `VAdd` version of a `DistribMulAction`. -/ protected def mulAction : MulAction M (AffineSubspace k V) := SetLike.coe_injective.mulAction _ coe_smul scoped[Pointwise] attribute [instance] AffineSubspace.mulAction lemma smul_eq_map (a : M) (s : AffineSubspace k V) : a • s = s.map (DistribMulAction.toLinearMap k _ a).toAffineMap := rfl lemma smul_mem_smul_iff {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] {a : G} : a • p ∈ a • s ↔ p ∈ s := smul_mem_smul_set_iff lemma smul_mem_smul_iff_of_isUnit (ha : IsUnit a) : a • p ∈ a • s ↔ p ∈ s := smul_mem_smul_iff (a := ha.unit) lemma smul_mem_smul_iff₀ {G₀ : Type*} [GroupWithZero G₀] [DistribMulAction G₀ V] [SMulCommClass G₀ k V] {a : G₀} (ha : a ≠ 0) : a • p ∈ a • s ↔ p ∈ s := smul_mem_smul_iff_of_isUnit ha.isUnit @[simp] lemma smul_bot (a : M) : a • (⊥ : AffineSubspace k V) = ⊥ := by ext; simp [smul_eq_map, map_bot] @[simp] lemma smul_top (ha : IsUnit a) : a • (⊤ : AffineSubspace k V) = ⊤ := by ext x; simpa [smul_eq_map, map_top] using ⟨ha.unit⁻¹ • x, smul_inv_smul ha.unit _⟩ lemma smul_span (a : M) (s : Set V) : a • affineSpan k s = affineSpan k (a • s) := map_span _ s end SMul end Ring section Field variable [Field k] [AddCommGroup V] [Module k V] {a : k} @[simp] lemma direction_smul (ha : a ≠ 0) (s : AffineSubspace k V) : (a • s).direction = s.direction := by have : DistribMulAction.toLinearMap k V a = a • LinearMap.id := by ext; simp simp [smul_eq_map, map_direction, this, Submodule.map_smul, ha] end Field end AffineSubspace
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Centroid.lean
import Mathlib.LinearAlgebra.AffineSpace.Combination /-! # Centroid of a Finite Set of Points in Affine Space This file defines the centroid of a finite set of points in an affine space over a division ring. ## Main definitions * `centroidWeights`: A constant weight function assigning to each index in a `Finset` the same weight, equal to the reciprocal of the number of elements. * `centroid`: the centroid of a `Finset` of points, defined as the affine combination using `centroidWeights`. -/ assert_not_exists Affine.Simplex noncomputable section open Affine namespace Finset variable (k : Type*) {V : Type*} {P : Type*} [DivisionRing k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] {ι : Type*} (s : Finset ι) {ι₂ : Type*} (s₂ : Finset ι₂) /-- The weights for the centroid of some points. -/ def centroidWeights : ι → k := Function.const ι (#s : k)⁻¹ /-- `centroidWeights` at any point. -/ @[simp] theorem centroidWeights_apply (i : ι) : s.centroidWeights k i = (#s : k)⁻¹ := rfl /-- `centroidWeights` equals a constant function. -/ theorem centroidWeights_eq_const : s.centroidWeights k = Function.const ι (#s : k)⁻¹ := rfl variable {k} in /-- The weights in the centroid sum to 1, if the number of points, converted to `k`, is not zero. -/ theorem sum_centroidWeights_eq_one_of_cast_card_ne_zero (h : (#s : k) ≠ 0) : ∑ i ∈ s, s.centroidWeights k i = 1 := by simp [h] /-- In the characteristic zero case, the weights in the centroid sum to 1 if the number of points is not zero. -/ theorem sum_centroidWeights_eq_one_of_card_ne_zero [CharZero k] (h : #s ≠ 0) : ∑ i ∈ s, s.centroidWeights k i = 1 := by simp_all /-- In the characteristic zero case, the weights in the centroid sum to 1 if the set is nonempty. -/ theorem sum_centroidWeights_eq_one_of_nonempty [CharZero k] (h : s.Nonempty) : ∑ i ∈ s, s.centroidWeights k i = 1 := s.sum_centroidWeights_eq_one_of_card_ne_zero k (ne_of_gt (card_pos.2 h)) /-- In the characteristic zero case, the weights in the centroid sum to 1 if the number of points is `n + 1`. -/ theorem sum_centroidWeights_eq_one_of_card_eq_add_one [CharZero k] {n : ℕ} (h : #s = n + 1) : ∑ i ∈ s, s.centroidWeights k i = 1 := s.sum_centroidWeights_eq_one_of_card_ne_zero k (h.symm ▸ Nat.succ_ne_zero n) /-- The centroid of some points. Although defined for any `s`, this is intended to be used in the case where the number of points, converted to `k`, is not zero. -/ def centroid (p : ι → P) : P := s.affineCombination k p (s.centroidWeights k) /-- The definition of the centroid. -/ theorem centroid_def (p : ι → P) : s.centroid k p = s.affineCombination k p (s.centroidWeights k) := rfl theorem centroid_univ (s : Finset P) : univ.centroid k ((↑) : s → P) = s.centroid k id := by rw [centroid, centroid, ← s.attach_affineCombination_coe] congr ext simp /-- The centroid of a single point. -/ @[simp] theorem centroid_singleton (p : ι → P) (i : ι) : ({i} : Finset ι).centroid k p = p i := by simp [centroid_def, affineCombination_apply] /-- The centroid of two points, expressed directly as adding a vector to a point. -/ theorem centroid_pair [DecidableEq ι] [Invertible (2 : k)] (p : ι → P) (i₁ i₂ : ι) : ({i₁, i₂} : Finset ι).centroid k p = (2⁻¹ : k) • (p i₂ -ᵥ p i₁) +ᵥ p i₁ := by by_cases h : i₁ = i₂ · simp [h] · have hc : (#{i₁, i₂} : k) ≠ 0 := by rw [card_insert_of_notMem (notMem_singleton.2 h), card_singleton] norm_num exact Invertible.ne_zero _ rw [centroid_def, affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one _ _ _ (sum_centroidWeights_eq_one_of_cast_card_ne_zero _ hc) (p i₁)] simp [h, one_add_one_eq_two] /-- The centroid of two points indexed by `Fin 2`, expressed directly as adding a vector to the first point. -/ theorem centroid_pair_fin [Invertible (2 : k)] (p : Fin 2 → P) : univ.centroid k p = (2⁻¹ : k) • (p 1 -ᵥ p 0) +ᵥ p 0 := by rw [univ_fin2] convert centroid_pair k p 0 1 /-- A centroid, over the image of an embedding, equals a centroid with the same points and weights over the original `Finset`. -/ theorem centroid_map (e : ι₂ ↪ ι) (p : ι → P) : (s₂.map e).centroid k p = s₂.centroid k (p ∘ e) := by simp [centroid_def, affineCombination_map, centroidWeights] /-- `centroidWeights` gives the weights for the centroid as a constant function, which is suitable when summing over the points whose centroid is being taken. This function gives the weights in a form suitable for summing over a larger set of points, as an indicator function that is zero outside the set whose centroid is being taken. In the case of a `Fintype`, the sum may be over `univ`. -/ def centroidWeightsIndicator : ι → k := Set.indicator (↑s) (s.centroidWeights k) /-- The definition of `centroidWeightsIndicator`. -/ theorem centroidWeightsIndicator_def : s.centroidWeightsIndicator k = Set.indicator (↑s) (s.centroidWeights k) := rfl /-- The sum of the weights for the centroid indexed by a `Fintype`. -/ theorem sum_centroidWeightsIndicator [Fintype ι] : ∑ i, s.centroidWeightsIndicator k i = ∑ i ∈ s, s.centroidWeights k i := sum_indicator_subset _ (subset_univ _) /-- In the characteristic zero case, the weights in the centroid indexed by a `Fintype` sum to 1 if the number of points is not zero. -/ theorem sum_centroidWeightsIndicator_eq_one_of_card_ne_zero [CharZero k] [Fintype ι] (h : #s ≠ 0) : ∑ i, s.centroidWeightsIndicator k i = 1 := by rw [sum_centroidWeightsIndicator] exact s.sum_centroidWeights_eq_one_of_card_ne_zero k h /-- In the characteristic zero case, the weights in the centroid indexed by a `Fintype` sum to 1 if the set is nonempty. -/ theorem sum_centroidWeightsIndicator_eq_one_of_nonempty [CharZero k] [Fintype ι] (h : s.Nonempty) : ∑ i, s.centroidWeightsIndicator k i = 1 := by rw [sum_centroidWeightsIndicator] exact s.sum_centroidWeights_eq_one_of_nonempty k h /-- In the characteristic zero case, the weights in the centroid indexed by a `Fintype` sum to 1 if the number of points is `n + 1`. -/ theorem sum_centroidWeightsIndicator_eq_one_of_card_eq_add_one [CharZero k] [Fintype ι] {n : ℕ} (h : #s = n + 1) : ∑ i, s.centroidWeightsIndicator k i = 1 := by rw [sum_centroidWeightsIndicator] exact s.sum_centroidWeights_eq_one_of_card_eq_add_one k h /-- The centroid as an affine combination over a `Fintype`. -/ theorem centroid_eq_affineCombination_fintype [Fintype ι] (p : ι → P) : s.centroid k p = univ.affineCombination k p (s.centroidWeightsIndicator k) := affineCombination_indicator_subset _ _ (subset_univ _) /-- An indexed family of points that is injective on the given `Finset` has the same centroid as the image of that `Finset`. This is stated in terms of a set equal to the image to provide control of definitional equality for the index type used for the centroid of the image. -/ theorem centroid_eq_centroid_image_of_inj_on {p : ι → P} (hi : ∀ i ∈ s, ∀ j ∈ s, p i = p j → i = j) {ps : Set P} [Fintype ps] (hps : ps = p '' ↑s) : s.centroid k p = (univ : Finset ps).centroid k fun x => (x : P) := by let f : p '' ↑s → ι := fun x => x.property.choose have hf : ∀ x, f x ∈ s ∧ p (f x) = x := fun x => x.property.choose_spec let f' : ps → ι := fun x => f ⟨x, hps ▸ x.property⟩ have hf' : ∀ x, f' x ∈ s ∧ p (f' x) = x := fun x => hf ⟨x, hps ▸ x.property⟩ have hf'i : Function.Injective f' := by intro x y h rw [Subtype.ext_iff, ← (hf' x).2, ← (hf' y).2, h] let f'e : ps ↪ ι := ⟨f', hf'i⟩ have hu : Finset.univ.map f'e = s := by ext x rw [mem_map] constructor · rintro ⟨i, _, rfl⟩ exact (hf' i).1 · intro hx use ⟨p x, hps.symm ▸ Set.mem_image_of_mem _ hx⟩, mem_univ _ refine hi _ (hf' _).1 _ hx ?_ rw [(hf' _).2] rw [← hu, centroid_map] congr with x change p (f' x) = ↑x rw [(hf' x).2] /-- Two indexed families of points that are injective on the given `Finset`s and with the same points in the image of those `Finset`s have the same centroid. -/ theorem centroid_eq_of_inj_on_of_image_eq {p : ι → P} (hi : ∀ i ∈ s, ∀ j ∈ s, p i = p j → i = j) {p₂ : ι₂ → P} (hi₂ : ∀ i ∈ s₂, ∀ j ∈ s₂, p₂ i = p₂ j → i = j) (he : p '' ↑s = p₂ '' ↑s₂) : s.centroid k p = s₂.centroid k p₂ := by classical rw [s.centroid_eq_centroid_image_of_inj_on k hi rfl, s₂.centroid_eq_centroid_image_of_inj_on k hi₂ he] end Finset section DivisionRing variable {k : Type*} {V : Type*} {P : Type*} [DivisionRing k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] {ι : Type*} open Set Finset /-- The centroid lies in the affine span if the number of points, converted to `k`, is not zero. -/ theorem centroid_mem_affineSpan_of_cast_card_ne_zero {s : Finset ι} (p : ι → P) (h : (#s : k) ≠ 0) : s.centroid k p ∈ affineSpan k (range p) := affineCombination_mem_affineSpan (s.sum_centroidWeights_eq_one_of_cast_card_ne_zero h) p variable (k) /-- In the characteristic zero case, the centroid lies in the affine span if the number of points is not zero. -/ theorem centroid_mem_affineSpan_of_card_ne_zero [CharZero k] {s : Finset ι} (p : ι → P) (h : #s ≠ 0) : s.centroid k p ∈ affineSpan k (range p) := affineCombination_mem_affineSpan (s.sum_centroidWeights_eq_one_of_card_ne_zero k h) p /-- In the characteristic zero case, the centroid lies in the affine span if the set is nonempty. -/ theorem centroid_mem_affineSpan_of_nonempty [CharZero k] {s : Finset ι} (p : ι → P) (h : s.Nonempty) : s.centroid k p ∈ affineSpan k (range p) := affineCombination_mem_affineSpan (s.sum_centroidWeights_eq_one_of_nonempty k h) p /-- In the characteristic zero case, the centroid lies in the affine span if the number of points is `n + 1`. -/ theorem centroid_mem_affineSpan_of_card_eq_add_one [CharZero k] {s : Finset ι} (p : ι → P) {n : ℕ} (h : #s = n + 1) : s.centroid k p ∈ affineSpan k (range p) := affineCombination_mem_affineSpan (s.sum_centroidWeights_eq_one_of_card_eq_add_one k h) p end DivisionRing
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Restrict.lean
import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic /-! # Affine map restrictions This file defines restrictions of affine maps. ## Main definitions * The domain and codomain of an affine map can be restricted using `AffineMap.restrict`. ## Main theorems * The associated linear map of the restriction is the restriction of the linear map associated to the original affine map. * The restriction is injective if the original map is injective. * The restriction in surjective if the codomain is the image of the domain. -/ variable {k V₁ P₁ V₂ P₂ : Type*} [Ring k] [AddCommGroup V₁] [AddCommGroup V₂] [Module k V₁] [Module k V₂] [AddTorsor V₁ P₁] [AddTorsor V₂ P₂] instance AffineSubspace.nonempty_map {E : AffineSubspace k P₁} [Ene : Nonempty E] {φ : P₁ →ᵃ[k] P₂} : Nonempty (E.map φ) := by obtain ⟨x, hx⟩ := id Ene exact ⟨⟨φ x, AffineSubspace.mem_map.mpr ⟨x, hx, rfl⟩⟩⟩ /-- Restrict domain and codomain of an affine map to the given subspaces. -/ def AffineMap.restrict (φ : P₁ →ᵃ[k] P₂) {E : AffineSubspace k P₁} {F : AffineSubspace k P₂} [Nonempty E] [Nonempty F] (hEF : E.map φ ≤ F) : E →ᵃ[k] F := by refine ⟨?_, ?_, ?_⟩ · exact fun x => ⟨φ x, hEF <| AffineSubspace.mem_map.mpr ⟨x, x.property, rfl⟩⟩ · refine φ.linear.restrict (?_ : E.direction ≤ F.direction.comap φ.linear) rw [← Submodule.map_le_iff_le_comap, ← AffineSubspace.map_direction] exact AffineSubspace.direction_le hEF · intro p v simp only [Subtype.ext_iff, AffineSubspace.coe_vadd] apply AffineMap.map_vadd theorem AffineMap.restrict.coe_apply (φ : P₁ →ᵃ[k] P₂) {E : AffineSubspace k P₁} {F : AffineSubspace k P₂} [Nonempty E] [Nonempty F] (hEF : E.map φ ≤ F) (x : E) : ↑(φ.restrict hEF x) = φ x := rfl theorem AffineMap.restrict.linear_aux {φ : P₁ →ᵃ[k] P₂} {E : AffineSubspace k P₁} {F : AffineSubspace k P₂} (hEF : E.map φ ≤ F) : E.direction ≤ F.direction.comap φ.linear := by rw [← Submodule.map_le_iff_le_comap, ← AffineSubspace.map_direction] exact AffineSubspace.direction_le hEF theorem AffineMap.restrict.linear (φ : P₁ →ᵃ[k] P₂) {E : AffineSubspace k P₁} {F : AffineSubspace k P₂} [Nonempty E] [Nonempty F] (hEF : E.map φ ≤ F) : (φ.restrict hEF).linear = φ.linear.restrict (AffineMap.restrict.linear_aux hEF) := rfl theorem AffineMap.restrict.injective {φ : P₁ →ᵃ[k] P₂} (hφ : Function.Injective φ) {E : AffineSubspace k P₁} {F : AffineSubspace k P₂} [Nonempty E] [Nonempty F] (hEF : E.map φ ≤ F) : Function.Injective (AffineMap.restrict φ hEF) := by intro x y h simp only [Subtype.ext_iff, AffineMap.restrict.coe_apply] at h ⊢ exact hφ h theorem AffineMap.restrict.surjective (φ : P₁ →ᵃ[k] P₂) {E : AffineSubspace k P₁} {F : AffineSubspace k P₂} [Nonempty E] [Nonempty F] (h : E.map φ = F) : Function.Surjective (AffineMap.restrict φ (le_of_eq h)) := by rintro ⟨x, hx : x ∈ F⟩ rw [← h, AffineSubspace.mem_map] at hx obtain ⟨y, hy, rfl⟩ := hx exact ⟨⟨y, hy⟩, rfl⟩ theorem AffineMap.restrict.bijective {E : AffineSubspace k P₁} [Nonempty E] {φ : P₁ →ᵃ[k] P₂} (hφ : Function.Injective φ) : Function.Bijective (φ.restrict (le_refl (E.map φ))) := ⟨AffineMap.restrict.injective hφ _, AffineMap.restrict.surjective _ rfl⟩
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Slope.lean
import Mathlib.LinearAlgebra.AffineSpace.AffineMap import Mathlib.Tactic.Field import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Module /-! # Slope of a function In this file we define the slope of a function `f : k → PE` taking values in an affine space over `k` and prove some basic theorems about `slope`. The `slope` function naturally appears in the Mean Value Theorem, and in the proof of the fact that a function with nonnegative second derivative on an interval is convex on this interval. ## Tags affine space, slope -/ open AffineMap variable {k E PE : Type*} [Field k] [AddCommGroup E] [Module k E] [AddTorsor E PE] /-- `slope f a b = (b - a)⁻¹ • (f b -ᵥ f a)` is the slope of a function `f` on the interval `[a, b]`. Note that `slope f a a = 0`, not the derivative of `f` at `a`. -/ def slope (f : k → PE) (a b : k) : E := (b - a)⁻¹ • (f b -ᵥ f a) theorem slope_fun_def (f : k → PE) : slope f = fun a b => (b - a)⁻¹ • (f b -ᵥ f a) := rfl theorem slope_def_field (f : k → k) (a b : k) : slope f a b = (f b - f a) / (b - a) := (div_eq_inv_mul _ _).symm theorem slope_fun_def_field (f : k → k) (a : k) : slope f a = fun b => (f b - f a) / (b - a) := (div_eq_inv_mul _ _).symm @[simp] theorem slope_same (f : k → PE) (a : k) : (slope f a a : E) = 0 := by rw [slope, sub_self, inv_zero, zero_smul] theorem slope_def_module (f : k → E) (a b : k) : slope f a b = (b - a)⁻¹ • (f b - f a) := rfl @[simp] theorem sub_smul_slope (f : k → PE) (a b : k) : (b - a) • slope f a b = f b -ᵥ f a := by rcases eq_or_ne a b with (rfl | hne) · rw [sub_self, zero_smul, vsub_self] · rw [slope, smul_inv_smul₀ (sub_ne_zero.2 hne.symm)] theorem sub_smul_slope_vadd (f : k → PE) (a b : k) : (b - a) • slope f a b +ᵥ f a = f b := by rw [sub_smul_slope, vsub_vadd] @[simp] theorem slope_vadd_const (f : k → E) (c : PE) : (slope fun x => f x +ᵥ c) = slope f := by ext a b simp only [slope, vadd_vsub_vadd_cancel_right, vsub_eq_sub] @[simp] theorem slope_sub_smul (f : k → E) {a b : k} (h : a ≠ b) : slope (fun x => (x - a) • f x) a b = f b := by simp [slope, inv_smul_smul₀ (sub_ne_zero.2 h.symm)] theorem eq_of_slope_eq_zero {f : k → PE} {a b : k} (h : slope f a b = (0 : E)) : f a = f b := by rw [← sub_smul_slope_vadd f a b, h, smul_zero, zero_vadd] theorem AffineMap.slope_comp {F PF : Type*} [AddCommGroup F] [Module k F] [AddTorsor F PF] (f : PE →ᵃ[k] PF) (g : k → PE) (a b : k) : slope (f ∘ g) a b = f.linear (slope g a b) := by simp only [slope, (· ∘ ·), f.linear.map_smul, f.linearMap_vsub] theorem LinearMap.slope_comp {F : Type*} [AddCommGroup F] [Module k F] (f : E →ₗ[k] F) (g : k → E) (a b : k) : slope (f ∘ g) a b = f (slope g a b) := f.toAffineMap.slope_comp g a b theorem slope_comm (f : k → PE) (a b : k) : slope f a b = slope f b a := by rw [slope, slope, ← neg_vsub_eq_vsub_rev, smul_neg, ← neg_smul, neg_inv, neg_sub] @[simp] lemma slope_neg (f : k → E) (x y : k) : slope (fun t ↦ -f t) x y = -slope f x y := by simp only [slope_def_module, neg_sub_neg, ← smul_neg, neg_sub] @[simp] lemma slope_neg_fun (f : k → E) : slope (-f) = -slope f := by ext x y; exact slope_neg f x y lemma slope_eq_zero_iff {f : k → E} {a b : k} : slope f a b = 0 ↔ f a = f b := by simp [slope, sub_eq_zero, eq_comm, or_iff_right_of_imp (congr_arg _)] /-- `slope f a c` is a linear combination of `slope f a b` and `slope f b c`. This version explicitly provides coefficients. If `a ≠ c`, then the sum of the coefficients is `1`, so it is actually an affine combination, see `lineMap_slope_slope_sub_div_sub`. -/ theorem sub_div_sub_smul_slope_add_sub_div_sub_smul_slope (f : k → PE) (a b c : k) : ((b - a) / (c - a)) • slope f a b + ((c - b) / (c - a)) • slope f b c = slope f a c := by by_cases hab : a = b · subst hab rw [sub_self, zero_div, zero_smul, zero_add] by_cases hac : a = c · simp [hac] · rw [div_self (sub_ne_zero.2 <| Ne.symm hac), one_smul] by_cases hbc : b = c · subst hbc simp [sub_ne_zero.2 (Ne.symm hab)] rw [add_comm] simp_rw [slope, div_eq_inv_mul, mul_smul, ← smul_add, smul_inv_smul₀ (sub_ne_zero.2 <| Ne.symm hab), smul_inv_smul₀ (sub_ne_zero.2 <| Ne.symm hbc), vsub_add_vsub_cancel] /-- `slope f a c` is an affine combination of `slope f a b` and `slope f b c`. This version uses `lineMap` to express this property. -/ theorem lineMap_slope_slope_sub_div_sub (f : k → PE) (a b c : k) (h : a ≠ c) : lineMap (slope f a b) (slope f b c) ((c - b) / (c - a)) = slope f a c := by simp only [lineMap_apply_module, ← sub_div_sub_smul_slope_add_sub_div_sub_smul_slope f a b c, add_left_inj] match_scalars field [sub_ne_zero.2 h.symm] /-- `slope f a b` is an affine combination of `slope f a (lineMap a b r)` and `slope f (lineMap a b r) b`. We use `lineMap` to express this property. -/ theorem lineMap_slope_lineMap_slope_lineMap (f : k → PE) (a b r : k) : lineMap (slope f (lineMap a b r) b) (slope f a (lineMap a b r)) r = slope f a b := by obtain rfl | hab : a = b ∨ a ≠ b := Classical.em _; · simp rw [slope_comm _ a, slope_comm _ a, slope_comm _ _ b] convert lineMap_slope_slope_sub_div_sub f b (lineMap a b r) a hab.symm using 2 rw [lineMap_apply_ring, eq_div_iff (sub_ne_zero.2 hab), sub_mul, one_mul, mul_sub, ← sub_sub, sub_sub_cancel] section Order variable [LinearOrder k] [IsStrictOrderedRing k] [PartialOrder E] [IsOrderedAddMonoid E] [PosSMulMono k E] {f : k → E} {x y : k} lemma slope_nonneg_iff_of_le (hxy : x ≤ y) : 0 ≤ slope f x y ↔ f x ≤ f y := by by_cases hxeqy : x = y · simp [hxeqy] refine ⟨fun h ↦ ?_, fun h ↦ smul_nonneg (inv_nonneg.2 (sub_nonneg.2 hxy)) ?_⟩ · have := smul_nonneg (sub_nonneg.2 hxy) h rwa [slope, ← mul_smul, mul_inv_cancel₀ (mt sub_eq_zero.1 (Ne.symm hxeqy)), one_smul, vsub_eq_sub, sub_nonneg] at this · rwa [vsub_eq_sub, sub_nonneg] lemma MonotoneOn.slope_nonneg {s : Set k} (hf : MonotoneOn f s) (hx : x ∈ s) (hy : y ∈ s) : 0 ≤ slope f x y := by rcases le_total x y with hxy | hxy · exact (slope_nonneg_iff_of_le hxy).mpr (hf hx hy hxy) · exact slope_comm f x y ▸ (slope_nonneg_iff_of_le hxy).mpr (hf hy hx hxy) lemma slope_nonpos_iff_of_le (hxy : x ≤ y) : slope f x y ≤ 0 ↔ f y ≤ f x := by simpa using slope_nonneg_iff_of_le (f := -f) hxy lemma AntitoneOn.slope_nonpos {s : Set k} (hf : AntitoneOn f s) (hx : x ∈ s) (hy : y ∈ s) : slope f x y ≤ 0:= by simpa using hf.neg.slope_nonneg hx hy lemma slope_pos_iff_of_le (hxy : x ≤ y) : 0 < slope f x y ↔ f x < f y := by simp_rw [lt_iff_le_and_ne, slope_nonneg_iff_of_le hxy, Ne, eq_comm, slope_eq_zero_iff] lemma StrictMonoOn.slope_pos {s : Set k} (hf : StrictMonoOn f s) (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) : 0 < slope f x y := by rcases lt_or_gt_of_ne hxy with hxy | hxy · exact (slope_pos_iff_of_le hxy.le).mpr (hf hx hy hxy) · exact slope_comm f x y ▸ (slope_pos_iff_of_le hxy.le).mpr (hf hy hx hxy) lemma slope_neg_iff_of_le (hxy : x ≤ y) : slope f x y < 0 ↔ f y < f x := by simpa using slope_pos_iff_of_le (f := -f) hxy lemma StrictAntiOn.slope_neg {s : Set k} (hf : StrictAntiOn f s) (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) : slope f x y < 0:= by simpa using hf.neg.slope_pos hx hy hxy end Order
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Defs.lean
import Mathlib.Algebra.AddTorsor.Defs /-! # Affine space In this file we introduce the following notation: * `AffineSpace V P` is an alternative notation for `AddTorsor V P` introduced at the end of this file. We tried to use an `abbreviation` instead of a `notation` but this led to hard-to-debug elaboration errors. So, we introduce a localized notation instead. When this notation is enabled with `open Affine`, Lean will use `AffineSpace` instead of `AddTorsor` both in input and in the proof state. Here is an incomplete list of notions related to affine spaces, all of them are defined in other files: * `AffineMap`: a map between affine spaces that preserves the affine structure; * `AffineEquiv`: an equivalence between affine spaces that preserves the affine structure; * `AffineSubspace`: a subset of an affine space closed w.r.t. affine combinations of points; * `AffineCombination`: an affine combination of points; * `AffineIndependent`: affine independent set of points; * `AffineBasis.coord`: the barycentric coordinate of a point. ## TODO Some key definitions are not yet present. * Affine frames. An affine frame might perhaps be represented as an `AffineEquiv` to a `Finsupp` (in the general case) or function type (in the finite-dimensional case) that gives the coordinates, with appropriate proofs of existence when `k` is a field. -/ assert_not_exists MonoidWithZero @[inherit_doc] scoped[Affine] notation "AffineSpace" => AddTorsor
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Ordered.lean
import Mathlib.Algebra.CharP.Invertible import Mathlib.Algebra.Order.Module.Synonym import Mathlib.LinearAlgebra.AffineSpace.Midpoint import Mathlib.LinearAlgebra.AffineSpace.Slope /-! # Ordered modules as affine spaces In this file we prove some theorems about `slope` and `lineMap` in the case when the module `E` acting on the codomain `PE` of a function is an ordered module over its domain `k`. We also prove inequalities that can be used to link convexity of a function on an interval to monotonicity of the slope, see section docstring below for details. ## Implementation notes We do not introduce the notion of ordered affine spaces (yet?). Instead, we prove various theorems for an ordered module interpreted as an affine space. ## Tags affine space, ordered module, slope -/ open AffineMap variable {k E PE : Type*} /-! ### Monotonicity of `lineMap` In this section we prove that `lineMap a b r` is monotone (strictly or not) in its arguments if other arguments belong to specific domains. -/ section OrderedRing variable [Ring k] [PartialOrder k] [IsOrderedRing k] [AddCommGroup E] [PartialOrder E] [IsOrderedAddMonoid E] [Module k E] [IsStrictOrderedModule k E] variable {a a' b b' : E} {r r' : k} theorem lineMap_mono_left (ha : a ≤ a') (hr : r ≤ 1) : lineMap a b r ≤ lineMap a' b r := by simp only [lineMap_apply_module] gcongr exact sub_nonneg.2 hr theorem lineMap_strict_mono_left (ha : a < a') (hr : r < 1) : lineMap a b r < lineMap a' b r := by simp only [lineMap_apply_module] gcongr exact sub_pos.2 hr omit [IsOrderedRing k] in theorem lineMap_mono_right (hb : b ≤ b') (hr : 0 ≤ r) : lineMap a b r ≤ lineMap a b' r := by simp only [lineMap_apply_module] gcongr omit [IsOrderedRing k] in theorem lineMap_strict_mono_right (hb : b < b') (hr : 0 < r) : lineMap a b r < lineMap a b' r := by simp only [lineMap_apply_module]; gcongr theorem lineMap_mono_endpoints (ha : a ≤ a') (hb : b ≤ b') (h₀ : 0 ≤ r) (h₁ : r ≤ 1) : lineMap a b r ≤ lineMap a' b' r := (lineMap_mono_left ha h₁).trans (lineMap_mono_right hb h₀) theorem lineMap_strict_mono_endpoints (ha : a < a') (hb : b < b') (h₀ : 0 ≤ r) (h₁ : r ≤ 1) : lineMap a b r < lineMap a' b' r := by rcases h₀.eq_or_lt with (rfl | h₀); · simpa exact (lineMap_mono_left ha.le h₁).trans_lt (lineMap_strict_mono_right hb h₀) variable [PosSMulReflectLT k E] theorem lineMap_lt_lineMap_iff_of_lt (h : r < r') : lineMap a b r < lineMap a b r' ↔ a < b := by simp only [lineMap_apply_module] rw [← lt_sub_iff_add_lt, add_sub_assoc, ← sub_lt_iff_lt_add', ← sub_smul, ← sub_smul, sub_sub_sub_cancel_left, smul_lt_smul_iff_of_pos_left (sub_pos.2 h)] theorem left_lt_lineMap_iff_lt (h : 0 < r) : a < lineMap a b r ↔ a < b := Iff.trans (by rw [lineMap_apply_zero]) (lineMap_lt_lineMap_iff_of_lt h) theorem lineMap_lt_left_iff_lt (h : 0 < r) : lineMap a b r < a ↔ b < a := left_lt_lineMap_iff_lt (E := Eᵒᵈ) h theorem lineMap_lt_right_iff_lt (h : r < 1) : lineMap a b r < b ↔ a < b := Iff.trans (by rw [lineMap_apply_one]) (lineMap_lt_lineMap_iff_of_lt h) theorem right_lt_lineMap_iff_lt (h : r < 1) : b < lineMap a b r ↔ b < a := lineMap_lt_right_iff_lt (E := Eᵒᵈ) h end OrderedRing section LinearOrderedRing variable [Ring k] [LinearOrder k] [IsStrictOrderedRing k] [AddCommGroup E] [PartialOrder E] [IsOrderedAddMonoid E] [Module k E] [IsStrictOrderedModule k E] {a a' b b' : E} {r r' : k} theorem lineMap_le_lineMap_iff_of_lt' (h : a < b) : lineMap a b r ≤ lineMap a b r' ↔ r ≤ r' := by simp only [lineMap_apply_module'] rw [add_le_add_iff_right, smul_le_smul_iff_of_pos_right (sub_pos.mpr h)] theorem left_le_lineMap_iff_nonneg (h : a < b) : a ≤ lineMap a b r ↔ 0 ≤ r := by rw [← lineMap_le_lineMap_iff_of_lt' h, lineMap_apply_zero,] theorem lineMap_le_left_iff_nonpos (h : a < b) : lineMap a b r ≤ a ↔ r ≤ 0 := by rw [← lineMap_le_lineMap_iff_of_lt' h, lineMap_apply_zero] theorem right_le_lineMap_iff_one_le (h : a < b) : b ≤ lineMap a b r ↔ 1 ≤ r := by rw [← lineMap_le_lineMap_iff_of_lt' h, lineMap_apply_one] theorem lineMap_le_right_iff_le_one (h : a < b) : lineMap a b r ≤ b ↔ r ≤ 1 := by rw [← lineMap_le_lineMap_iff_of_lt' h, lineMap_apply_one] theorem lineMap_lt_lineMap_iff_of_lt' (h : a < b) : lineMap a b r < lineMap a b r' ↔ r < r' := by simp only [lineMap_apply_module'] rw [add_lt_add_iff_right, smul_lt_smul_iff_of_pos_right (sub_pos.mpr h)] theorem left_lt_lineMap_iff_pos (h : a < b) : a < lineMap a b r ↔ 0 < r := by rw [← lineMap_lt_lineMap_iff_of_lt' h, lineMap_apply_zero] theorem lineMap_lt_left_iff_neg (h : a < b) : lineMap a b r < a ↔ r < 0 := by rw [← lineMap_lt_lineMap_iff_of_lt' h, lineMap_apply_zero] theorem right_lt_lineMap_iff_one_lt (h : a < b) : b < lineMap a b r ↔ 1 < r := by rw [← lineMap_lt_lineMap_iff_of_lt' h, lineMap_apply_one] theorem lineMap_lt_right_iff_lt_one (h : a < b) : lineMap a b r < b ↔ r < 1 := by rw [← lineMap_lt_lineMap_iff_of_lt' h, lineMap_apply_one] theorem midpoint_le_midpoint [Invertible (2 : k)] (ha : a ≤ a') (hb : b ≤ b') : midpoint k a b ≤ midpoint k a' b' := lineMap_mono_endpoints ha hb (invOf_nonneg.2 zero_le_two) <| invOf_le_one one_le_two end LinearOrderedRing section LinearOrderedField variable [Field k] [LinearOrder k] [IsStrictOrderedRing k] [AddCommGroup E] [PartialOrder E] [IsOrderedAddMonoid E] variable [Module k E] [IsStrictOrderedModule k E] [PosSMulReflectLE k E] section variable {a b : E} {r r' : k} theorem lineMap_le_lineMap_iff_of_lt (h : r < r') : lineMap a b r ≤ lineMap a b r' ↔ a ≤ b := by simp only [lineMap_apply_module] rw [← le_sub_iff_add_le, add_sub_assoc, ← sub_le_iff_le_add', ← sub_smul, ← sub_smul, sub_sub_sub_cancel_left, smul_le_smul_iff_of_pos_left (sub_pos.2 h)] theorem left_le_lineMap_iff_le (h : 0 < r) : a ≤ lineMap a b r ↔ a ≤ b := Iff.trans (by rw [lineMap_apply_zero]) (lineMap_le_lineMap_iff_of_lt h) @[simp] theorem left_le_midpoint : a ≤ midpoint k a b ↔ a ≤ b := left_le_lineMap_iff_le <| inv_pos.2 zero_lt_two theorem lineMap_le_left_iff_le (h : 0 < r) : lineMap a b r ≤ a ↔ b ≤ a := left_le_lineMap_iff_le (E := Eᵒᵈ) h @[simp] theorem midpoint_le_left : midpoint k a b ≤ a ↔ b ≤ a := lineMap_le_left_iff_le <| inv_pos.2 zero_lt_two theorem lineMap_le_right_iff_le (h : r < 1) : lineMap a b r ≤ b ↔ a ≤ b := Iff.trans (by rw [lineMap_apply_one]) (lineMap_le_lineMap_iff_of_lt h) @[simp] theorem midpoint_le_right : midpoint k a b ≤ b ↔ a ≤ b := lineMap_le_right_iff_le two_inv_lt_one theorem right_le_lineMap_iff_le (h : r < 1) : b ≤ lineMap a b r ↔ b ≤ a := lineMap_le_right_iff_le (E := Eᵒᵈ) h @[simp] theorem right_le_midpoint : b ≤ midpoint k a b ↔ b ≤ a := right_le_lineMap_iff_le two_inv_lt_one end /-! ### Convexity and slope Given an interval `[a, b]` and a point `c ∈ (a, b)`, `c = lineMap a b r`, there are a few ways to say that the point `(c, f c)` is above/below the segment `[(a, f a), (b, f b)]`: * compare `f c` to `lineMap (f a) (f b) r`; * compare `slope f a c` to `slope f a b`; * compare `slope f c b` to `slope f a b`; * compare `slope f a c` to `slope f c b`. In this section we prove equivalence of these four approaches. In order to make the statements more readable, we introduce local notation `c = lineMap a b r`. Then we prove lemmas like ``` lemma map_le_lineMap_iff_slope_le_slope_left (h : 0 < r * (b - a)) : f c ≤ lineMap (f a) (f b) r ↔ slope f a c ≤ slope f a b := ``` For each inequality between `f c` and `lineMap (f a) (f b) r` we provide 3 lemmas: * `*_left` relates it to an inequality on `slope f a c` and `slope f a b`; * `*_right` relates it to an inequality on `slope f a b` and `slope f c b`; * no-suffix version relates it to an inequality on `slope f a c` and `slope f c b`. These inequalities can be used to restate `convexOn` in terms of monotonicity of the slope. -/ variable {f : k → E} {a b r : k} local notation "c" => lineMap a b r section omit [IsStrictOrderedRing k] /-- Given `c = lineMap a b r`, `a < c`, the point `(c, f c)` is non-strictly below the segment `[(a, f a), (b, f b)]` if and only if `slope f a c ≤ slope f a b`. -/ theorem map_le_lineMap_iff_slope_le_slope_left (h : 0 < r * (b - a)) : f c ≤ lineMap (f a) (f b) r ↔ slope f a c ≤ slope f a b := by rw [lineMap_apply, lineMap_apply, slope, slope, vsub_eq_sub, vsub_eq_sub, vsub_eq_sub, vadd_eq_add, vadd_eq_add, smul_eq_mul, add_sub_cancel_right, smul_sub, smul_sub, smul_sub, sub_le_iff_le_add, mul_inv_rev, mul_smul, mul_smul, ← smul_sub, ← smul_sub, ← smul_add, smul_smul, ← mul_inv_rev, inv_smul_le_iff_of_pos h, smul_smul, mul_inv_cancel_right₀ (right_ne_zero_of_mul h.ne'), smul_add, smul_inv_smul₀ (left_ne_zero_of_mul h.ne')] /-- Given `c = lineMap a b r`, `a < c`, the point `(c, f c)` is non-strictly above the segment `[(a, f a), (b, f b)]` if and only if `slope f a b ≤ slope f a c`. -/ theorem lineMap_le_map_iff_slope_le_slope_left (h : 0 < r * (b - a)) : lineMap (f a) (f b) r ≤ f c ↔ slope f a b ≤ slope f a c := map_le_lineMap_iff_slope_le_slope_left (E := Eᵒᵈ) (f := f) (a := a) (b := b) (r := r) h /-- Given `c = lineMap a b r`, `a < c`, the point `(c, f c)` is strictly below the segment `[(a, f a), (b, f b)]` if and only if `slope f a c < slope f a b`. -/ theorem map_lt_lineMap_iff_slope_lt_slope_left (h : 0 < r * (b - a)) : f c < lineMap (f a) (f b) r ↔ slope f a c < slope f a b := lt_iff_lt_of_le_iff_le' (lineMap_le_map_iff_slope_le_slope_left h) (map_le_lineMap_iff_slope_le_slope_left h) /-- Given `c = lineMap a b r`, `a < c`, the point `(c, f c)` is strictly above the segment `[(a, f a), (b, f b)]` if and only if `slope f a b < slope f a c`. -/ theorem lineMap_lt_map_iff_slope_lt_slope_left (h : 0 < r * (b - a)) : lineMap (f a) (f b) r < f c ↔ slope f a b < slope f a c := map_lt_lineMap_iff_slope_lt_slope_left (E := Eᵒᵈ) (f := f) (a := a) (b := b) (r := r) h /-- Given `c = lineMap a b r`, `c < b`, the point `(c, f c)` is non-strictly below the segment `[(a, f a), (b, f b)]` if and only if `slope f a b ≤ slope f c b`. -/ theorem map_le_lineMap_iff_slope_le_slope_right (h : 0 < (1 - r) * (b - a)) : f c ≤ lineMap (f a) (f b) r ↔ slope f a b ≤ slope f c b := by rw [← lineMap_apply_one_sub, ← lineMap_apply_one_sub _ _ r] revert h; generalize 1 - r = r'; clear! r; intro h simp_rw [lineMap_apply, slope, vsub_eq_sub, vadd_eq_add, smul_eq_mul] rw [sub_add_eq_sub_sub_swap, sub_self, zero_sub, neg_mul_eq_mul_neg, neg_sub, le_inv_smul_iff_of_pos h, smul_smul, mul_inv_cancel_right₀, le_sub_comm, ← neg_sub (f b), smul_neg, neg_add_eq_sub] · exact right_ne_zero_of_mul h.ne' /-- Given `c = lineMap a b r`, `c < b`, the point `(c, f c)` is non-strictly above the segment `[(a, f a), (b, f b)]` if and only if `slope f c b ≤ slope f a b`. -/ theorem lineMap_le_map_iff_slope_le_slope_right (h : 0 < (1 - r) * (b - a)) : lineMap (f a) (f b) r ≤ f c ↔ slope f c b ≤ slope f a b := map_le_lineMap_iff_slope_le_slope_right (E := Eᵒᵈ) (f := f) (a := a) (b := b) (r := r) h /-- Given `c = lineMap a b r`, `c < b`, the point `(c, f c)` is strictly below the segment `[(a, f a), (b, f b)]` if and only if `slope f a b < slope f c b`. -/ theorem map_lt_lineMap_iff_slope_lt_slope_right (h : 0 < (1 - r) * (b - a)) : f c < lineMap (f a) (f b) r ↔ slope f a b < slope f c b := lt_iff_lt_of_le_iff_le' (lineMap_le_map_iff_slope_le_slope_right h) (map_le_lineMap_iff_slope_le_slope_right h) /-- Given `c = lineMap a b r`, `c < b`, the point `(c, f c)` is strictly above the segment `[(a, f a), (b, f b)]` if and only if `slope f c b < slope f a b`. -/ theorem lineMap_lt_map_iff_slope_lt_slope_right (h : 0 < (1 - r) * (b - a)) : lineMap (f a) (f b) r < f c ↔ slope f c b < slope f a b := map_lt_lineMap_iff_slope_lt_slope_right (E := Eᵒᵈ) (f := f) (a := a) (b := b) (r := r) h end /-- Given `c = lineMap a b r`, `a < c < b`, the point `(c, f c)` is non-strictly below the segment `[(a, f a), (b, f b)]` if and only if `slope f a c ≤ slope f c b`. -/ theorem map_le_lineMap_iff_slope_le_slope (hab : a < b) (h₀ : 0 < r) (h₁ : r < 1) : f c ≤ lineMap (f a) (f b) r ↔ slope f a c ≤ slope f c b := by rw [map_le_lineMap_iff_slope_le_slope_left (mul_pos h₀ (sub_pos.2 hab)), ← lineMap_slope_lineMap_slope_lineMap f a b r, right_le_lineMap_iff_le h₁] /-- Given `c = lineMap a b r`, `a < c < b`, the point `(c, f c)` is non-strictly above the segment `[(a, f a), (b, f b)]` if and only if `slope f c b ≤ slope f a c`. -/ theorem lineMap_le_map_iff_slope_le_slope (hab : a < b) (h₀ : 0 < r) (h₁ : r < 1) : lineMap (f a) (f b) r ≤ f c ↔ slope f c b ≤ slope f a c := map_le_lineMap_iff_slope_le_slope (E := Eᵒᵈ) hab h₀ h₁ /-- Given `c = lineMap a b r`, `a < c < b`, the point `(c, f c)` is strictly below the segment `[(a, f a), (b, f b)]` if and only if `slope f a c < slope f c b`. -/ theorem map_lt_lineMap_iff_slope_lt_slope (hab : a < b) (h₀ : 0 < r) (h₁ : r < 1) : f c < lineMap (f a) (f b) r ↔ slope f a c < slope f c b := lt_iff_lt_of_le_iff_le' (lineMap_le_map_iff_slope_le_slope hab h₀ h₁) (map_le_lineMap_iff_slope_le_slope hab h₀ h₁) /-- Given `c = lineMap a b r`, `a < c < b`, the point `(c, f c)` is strictly above the segment `[(a, f a), (b, f b)]` if and only if `slope f c b < slope f a c`. -/ theorem lineMap_lt_map_iff_slope_lt_slope (hab : a < b) (h₀ : 0 < r) (h₁ : r < 1) : lineMap (f a) (f b) r < f c ↔ slope f c b < slope f a c := map_lt_lineMap_iff_slope_lt_slope (E := Eᵒᵈ) hab h₀ h₁ end LinearOrderedField lemma slope_pos_iff {𝕜} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] {f : 𝕜 → 𝕜} {x₀ b : 𝕜} (hb : x₀ < b) : 0 < slope f x₀ b ↔ f x₀ < f b := by simp [slope, hb] lemma slope_pos_iff_gt {𝕜} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] {f : 𝕜 → 𝕜} {x₀ b : 𝕜} (hb : b < x₀) : 0 < slope f x₀ b ↔ f b < f x₀ := by rw [slope_comm, slope_pos_iff hb] lemma pos_of_slope_pos {𝕜} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] {f : 𝕜 → 𝕜} {x₀ b : 𝕜} (hb : x₀ < b) (hbf : 0 < slope f x₀ b) (hf : f x₀ = 0) : 0 < f b := by simp_all [slope] lemma neg_of_slope_pos {𝕜} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] {f : 𝕜 → 𝕜} {x₀ b : 𝕜} (hb : b < x₀) (hbf : 0 < slope f x₀ b) (hf : f x₀ = 0) : f b < 0 := by rwa [slope_pos_iff_gt, hf] at hbf exact hb
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/MidpointZero.lean
import Mathlib.Algebra.CharP.Invertible import Mathlib.LinearAlgebra.AffineSpace.Midpoint /-! # Midpoint of a segment for characteristic zero We collect lemmas that require that the underlying ring has characteristic zero. ## Tags midpoint -/ open AffineMap AffineEquiv theorem lineMap_inv_two {R : Type*} {V P : Type*} [DivisionRing R] [CharZero R] [AddCommGroup V] [Module R V] [AddTorsor V P] (a b : P) : lineMap a b (2⁻¹ : R) = midpoint R a b := rfl theorem lineMap_one_half {R : Type*} {V P : Type*} [DivisionRing R] [CharZero R] [AddCommGroup V] [Module R V] [AddTorsor V P] (a b : P) : lineMap a b (1 / 2 : R) = midpoint R a b := by rw [one_div, lineMap_inv_two] theorem homothety_invOf_two {R : Type*} {V P : Type*} [CommRing R] [Invertible (2 : R)] [AddCommGroup V] [Module R V] [AddTorsor V P] (a b : P) : homothety a (⅟2 : R) b = midpoint R a b := rfl theorem homothety_inv_two {k : Type*} {V P : Type*} [Field k] [CharZero k] [AddCommGroup V] [Module k V] [AddTorsor V P] (a b : P) : homothety a (2⁻¹ : k) b = midpoint k a b := rfl theorem homothety_one_half {k : Type*} {V P : Type*} [Field k] [CharZero k] [AddCommGroup V] [Module k V] [AddTorsor V P] (a b : P) : homothety a (1 / 2 : k) b = midpoint k a b := by rw [one_div, homothety_inv_two] @[simp] theorem pi_midpoint_apply {k ι : Type*} {V : ι → Type*} {P : ι → Type*} [Ring k] [Invertible (2 : k)] [∀ i, AddCommGroup (V i)] [∀ i, Module k (V i)] [∀ i, AddTorsor (V i) (P i)] (f g : ∀ i, P i) (i : ι) : midpoint k f g i = midpoint k (f i) (g i) := rfl
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Basis.lean
import Mathlib.LinearAlgebra.AffineSpace.Centroid import Mathlib.LinearAlgebra.AffineSpace.Independent import Mathlib.LinearAlgebra.AffineSpace.Pointwise import Mathlib.LinearAlgebra.Basis.SMul /-! # Affine bases and barycentric coordinates Suppose `P` is an affine space modelled on the module `V` over the ring `k`, and `p : ι → P` is an affine-independent family of points spanning `P`. Given this data, each point `q : P` may be written uniquely as an affine combination: `q = w₀ p₀ + w₁ p₁ + ⋯` for some (finitely-supported) weights `wᵢ`. For each `i : ι`, we thus have an affine map `P →ᵃ[k] k`, namely `q ↦ wᵢ`. This family of maps is known as the family of barycentric coordinates. It is defined in this file. ## The construction Fixing `i : ι`, and allowing `j : ι` to range over the values `j ≠ i`, we obtain a basis `bᵢ` of `V` defined by `bᵢ j = p j -ᵥ p i`. Let `fᵢ j : V →ₗ[k] k` be the corresponding dual basis and let `fᵢ = ∑ j, fᵢ j : V →ₗ[k] k` be the corresponding "sum of all coordinates" form. Then the `i`th barycentric coordinate of `q : P` is `1 - fᵢ (q -ᵥ p i)`. ## Main definitions * `AffineBasis`: a structure representing an affine basis of an affine space. * `AffineBasis.coord`: the map `P →ᵃ[k] k` corresponding to `i : ι`. * `AffineBasis.coord_apply_eq`: the behaviour of `AffineBasis.coord i` on `p i`. * `AffineBasis.coord_apply_ne`: the behaviour of `AffineBasis.coord i` on `p j` when `j ≠ i`. * `AffineBasis.coord_apply`: the behaviour of `AffineBasis.coord i` on `p j` for general `j`. * `AffineBasis.coord_apply_combination`: the characterisation of `AffineBasis.coord i` in terms of affine combinations, i.e., `AffineBasis.coord i (w₀ p₀ + w₁ p₁ + ⋯) = wᵢ`. ## TODO * Construct the affine equivalence between `P` and `{ f : ι →₀ k | f.sum = 1 }`. -/ open Affine Module Set open scoped Pointwise universe u₁ u₂ u₃ u₄ /-- An affine basis is a family of affine-independent points whose span is the top subspace. -/ structure AffineBasis (ι : Type u₁) (k : Type u₂) {V : Type u₃} (P : Type u₄) [AddCommGroup V] [AffineSpace V P] [Ring k] [Module k V] where /-- The underlying family of points. Do NOT use directly. Use the coercion instead. -/ protected toFun : ι → P protected ind' : AffineIndependent k toFun protected tot' : affineSpan k (range toFun) = ⊤ variable {ι ι' G G' k V P : Type*} [AddCommGroup V] [AffineSpace V P] namespace AffineBasis section Ring variable [Ring k] [Module k V] (b : AffineBasis ι k P) {s : Finset ι} {i j : ι} (e : ι ≃ ι') /-- The unique point in a single-point space is the simplest example of an affine basis. -/ instance : Inhabited (AffineBasis PUnit k PUnit) := ⟨⟨id, affineIndependent_of_subsingleton k id, by simp⟩⟩ instance instFunLike : FunLike (AffineBasis ι k P) ι P where coe := AffineBasis.toFun coe_injective' f g h := by cases f; cases g; congr @[ext] theorem ext {b₁ b₂ : AffineBasis ι k P} (h : (b₁ : ι → P) = b₂) : b₁ = b₂ := DFunLike.coe_injective h theorem ind : AffineIndependent k b := b.ind' theorem tot : affineSpan k (range b) = ⊤ := b.tot' include b in protected theorem nonempty : Nonempty ι := not_isEmpty_iff.mp fun hι => by simpa only [@range_eq_empty _ _ hι, AffineSubspace.span_empty, bot_ne_top] using b.tot /-- Composition of an affine basis and an equivalence of index types. -/ def reindex (e : ι ≃ ι') : AffineBasis ι' k P := ⟨b ∘ e.symm, b.ind.comp_embedding e.symm.toEmbedding, by rw [e.symm.surjective.range_comp] exact b.3⟩ @[simp, norm_cast] theorem coe_reindex : ⇑(b.reindex e) = b ∘ e.symm := rfl @[simp] theorem reindex_apply (i' : ι') : b.reindex e i' = b (e.symm i') := rfl @[simp] theorem reindex_refl : b.reindex (Equiv.refl _) = b := ext rfl /-- Given an affine basis for an affine space `P`, if we single out one member of the family, we obtain a linear basis for the model space `V`. The linear basis corresponding to the singled-out member `i : ι` is indexed by `{j : ι // j ≠ i}` and its `j`th element is `b j -ᵥ b i`. (See `basisOf_apply`.) -/ noncomputable def basisOf (i : ι) : Basis { j : ι // j ≠ i } k V := Basis.mk ((affineIndependent_iff_linearIndependent_vsub k b i).mp b.ind) (by suffices Submodule.span k (range fun j : { x // x ≠ i } => b ↑j -ᵥ b i) = vectorSpan k (range b) by rw [this, ← direction_affineSpan, b.tot, AffineSubspace.direction_top] conv_rhs => rw [← image_univ] rw [vectorSpan_image_eq_span_vsub_set_right_ne k b (mem_univ i)] congr ext v simp) @[simp] theorem basisOf_apply (i : ι) (j : { j : ι // j ≠ i }) : b.basisOf i j = b ↑j -ᵥ b i := by simp [basisOf] @[simp] theorem basisOf_reindex (i : ι') : (b.reindex e).basisOf i = (b.basisOf <| e.symm i).reindex (e.subtypeEquiv fun _ => e.eq_symm_apply.not) := by ext j simp /-- The `i`th barycentric coordinate of a point. -/ noncomputable def coord (i : ι) : P →ᵃ[k] k where toFun q := 1 - (b.basisOf i).sumCoords (q -ᵥ b i) linear := -(b.basisOf i).sumCoords map_vadd' q v := by rw [vadd_vsub_assoc, LinearMap.map_add, vadd_eq_add, LinearMap.neg_apply, sub_add_eq_sub_sub_swap, add_comm, sub_eq_add_neg] @[simp] theorem linear_eq_sumCoords (i : ι) : (b.coord i).linear = -(b.basisOf i).sumCoords := rfl @[simp] theorem coord_reindex (i : ι') : (b.reindex e).coord i = b.coord (e.symm i) := by ext classical simp [AffineBasis.coord] @[simp] theorem coord_apply_eq (i : ι) : b.coord i (b i) = 1 := by simp only [coord, Basis.coe_sumCoords, LinearEquiv.map_zero, sub_zero, AffineMap.coe_mk, Finsupp.sum_zero_index, vsub_self] @[simp] theorem coord_apply_ne (h : i ≠ j) : b.coord i (b j) = 0 := by rw [coord, AffineMap.coe_mk, ← Subtype.coe_mk (p := (· ≠ i)) j h.symm, ← b.basisOf_apply, Basis.sumCoords_self_apply, sub_self] theorem coord_apply [DecidableEq ι] (i j : ι) : b.coord i (b j) = if i = j then 1 else 0 := by rcases eq_or_ne i j with h | h <;> simp [h] @[simp] theorem coord_apply_combination_of_mem (hi : i ∈ s) {w : ι → k} (hw : s.sum w = 1) : b.coord i (s.affineCombination k b w) = w i := by classical simp only [coord_apply, hi, Finset.affineCombination_eq_linear_combination, if_true, mul_boole, hw, Function.comp_apply, smul_eq_mul, s.sum_ite_eq, s.map_affineCombination b w hw] @[simp] theorem coord_apply_combination_of_notMem (hi : i ∉ s) {w : ι → k} (hw : s.sum w = 1) : b.coord i (s.affineCombination k b w) = 0 := by classical simp only [coord_apply, hi, Finset.affineCombination_eq_linear_combination, if_false, mul_boole, hw, Function.comp_apply, smul_eq_mul, s.sum_ite_eq, s.map_affineCombination b w hw] @[deprecated (since := "2025-05-23")] alias coord_apply_combination_of_not_mem := coord_apply_combination_of_notMem @[simp] theorem sum_coord_apply_eq_one [Fintype ι] (q : P) : ∑ i, b.coord i q = 1 := by have hq : q ∈ affineSpan k (range b) := by rw [b.tot] exact AffineSubspace.mem_top k V q obtain ⟨w, hw, rfl⟩ := eq_affineCombination_of_mem_affineSpan_of_fintype hq convert hw exact b.coord_apply_combination_of_mem (Finset.mem_univ _) hw @[simp] theorem affineCombination_coord_eq_self [Fintype ι] (q : P) : (Finset.univ.affineCombination k b fun i => b.coord i q) = q := by have hq : q ∈ affineSpan k (range b) := by rw [b.tot] exact AffineSubspace.mem_top k V q obtain ⟨w, hw, rfl⟩ := eq_affineCombination_of_mem_affineSpan_of_fintype hq congr ext i exact b.coord_apply_combination_of_mem (Finset.mem_univ i) hw /-- A variant of `AffineBasis.affineCombination_coord_eq_self` for the special case when the affine space is a module so we can talk about linear combinations. -/ @[simp] theorem linear_combination_coord_eq_self [Fintype ι] (b : AffineBasis ι k V) (v : V) : ∑ i, b.coord i v • b i = v := by have hb := b.affineCombination_coord_eq_self v rwa [Finset.univ.affineCombination_eq_linear_combination _ _ (b.sum_coord_apply_eq_one v)] at hb theorem ext_elem [Finite ι] {q₁ q₂ : P} (h : ∀ i, b.coord i q₁ = b.coord i q₂) : q₁ = q₂ := by cases nonempty_fintype ι rw [← b.affineCombination_coord_eq_self q₁, ← b.affineCombination_coord_eq_self q₂] simp only [h] @[simp] theorem coe_coord_of_subsingleton_eq_one [Subsingleton ι] (i : ι) : (b.coord i : P → k) = 1 := by ext q have hp : (range b).Subsingleton := by rw [← image_univ] apply Subsingleton.image apply subsingleton_of_subsingleton haveI := AffineSubspace.subsingleton_of_subsingleton_span_eq_top hp b.tot let s : Finset ι := {i} have hi : i ∈ s := by simp [s] have hw : s.sum (Function.const ι (1 : k)) = 1 := by simp [s] have hq : q = s.affineCombination k b (Function.const ι (1 : k)) := by simp [eq_iff_true_of_subsingleton] rw [Pi.one_apply, hq, b.coord_apply_combination_of_mem hi hw, Function.const_apply] theorem surjective_coord [Nontrivial ι] (i : ι) : Function.Surjective <| b.coord i := by classical intro x obtain ⟨j, hij⟩ := exists_ne i let s : Finset ι := {i, j} have hi : i ∈ s := by simp [s] let w : ι → k := fun j' => if j' = i then x else 1 - x have hw : s.sum w = 1 := by simp [s, w, Finset.sum_ite, Finset.filter_insert, hij, Finset.filter_true_of_mem, Finset.filter_false_of_mem] use s.affineCombination k b w simp [w, b.coord_apply_combination_of_mem hi hw] /-- Barycentric coordinates as an affine map. -/ noncomputable def coords : P →ᵃ[k] ι → k where toFun q i := b.coord i q linear := { toFun := fun v i => -(b.basisOf i).sumCoords v map_add' := fun v w => by ext; simp only [LinearMap.map_add, Pi.add_apply, neg_add] map_smul' := fun t v => by ext; simp } map_vadd' p v := by ext; simp @[simp] theorem coords_apply (q : P) (i : ι) : b.coords q i = b.coord i q := rfl instance instVAdd : VAdd V (AffineBasis ι k P) where vadd x b := { toFun := x +ᵥ ⇑b, ind' := b.ind'.vadd, tot' := by rw [Pi.vadd_def, ← vadd_set_range, ← AffineSubspace.pointwise_vadd_span, b.tot, AffineSubspace.pointwise_vadd_top] } @[simp, norm_cast] lemma coe_vadd (v : V) (b : AffineBasis ι k P) : ⇑(v +ᵥ b) = v +ᵥ ⇑b := rfl @[simp] lemma basisOf_vadd (v : V) (b : AffineBasis ι k P) : (v +ᵥ b).basisOf = b.basisOf := by ext simp instance instAddAction : AddAction V (AffineBasis ι k P) := DFunLike.coe_injective.addAction _ coe_vadd @[simp] lemma coord_vadd (v : V) (b : AffineBasis ι k P) : (v +ᵥ b).coord i = (b.coord i).comp (AffineEquiv.constVAdd k P v).symm := by ext p simp only [coord, ne_eq, basisOf_vadd, coe_vadd, Pi.vadd_apply, Basis.coe_sumCoords, AffineMap.coe_mk, AffineEquiv.constVAdd_symm, AffineMap.coe_comp, AffineEquiv.coe_toAffineMap, Function.comp_apply, AffineEquiv.constVAdd_apply, sub_right_inj] congr! 1 rw [vadd_vsub_assoc, neg_add_eq_sub, vsub_vadd_eq_vsub_sub] section SMul variable [Group G] [Group G'] variable [DistribMulAction G V] [DistribMulAction G' V] variable [SMulCommClass G k V] [SMulCommClass G' k V] /-- In an affine space that is also a vector space, an `AffineBasis` can be scaled. TODO: generalize to include `SMul (P ≃ᵃ[k] P) (AffineBasis ι k P)`, which acts on `P` with a `VAdd` version of a `DistribMulAction`. -/ instance instSMul : SMul G (AffineBasis ι k V) where smul a b := { toFun := a • ⇑b, ind' := b.ind'.smul, tot' := by rw [Pi.smul_def, ← smul_set_range, ← AffineSubspace.smul_span, b.tot, AffineSubspace.smul_top (Group.isUnit a)] } @[simp, norm_cast] lemma coe_smul (a : G) (b : AffineBasis ι k V) : ⇑(a • b) = a • ⇑b := rfl /-- TODO: generalize to include `SMul (P ≃ᵃ[k] P) (AffineBasis ι k P)`, which acts on `P` with a `VAdd` version of a `DistribMulAction`. -/ instance [SMulCommClass G G' V] : SMulCommClass G G' (AffineBasis ι k V) where smul_comm _g _g' _b := DFunLike.ext _ _ fun _ => smul_comm _ _ _ /-- TODO: generalize to include `SMul (P ≃ᵃ[k] P) (AffineBasis ι k P)`, which acts on `P` with a `VAdd` version of a `DistribMulAction`. -/ instance [SMul G G'] [IsScalarTower G G' V] : IsScalarTower G G' (AffineBasis ι k V) where smul_assoc _g _g' _b := DFunLike.ext _ _ fun _ => smul_assoc _ _ _ @[simp] lemma basisOf_smul (a : G) (b : AffineBasis ι k V) (i : ι) : (a • b).basisOf i = a • b.basisOf i := by ext j; simp [smul_sub] @[simp] lemma reindex_smul (a : G) (b : AffineBasis ι k V) (e : ι ≃ ι') : (a • b).reindex e = a • b.reindex e := rfl @[simp] lemma coord_smul (a : G) (b : AffineBasis ι k V) (i : ι) : (a • b).coord i = (b.coord i).comp (DistribMulAction.toLinearEquiv _ _ a).symm.toAffineMap := by ext v; simp [map_sub, coord] /-- TODO: generalize to include `SMul (P ≃ᵃ[k] P) (AffineBasis ι k P)`, which acts on `P` with a `VAdd` version of a `DistribMulAction`. -/ instance instMulAction : MulAction G (AffineBasis ι k V) := DFunLike.coe_injective.mulAction _ coe_smul end SMul end Ring section DivisionRing variable [DivisionRing k] [Module k V] @[simp] theorem coord_apply_centroid [CharZero k] (b : AffineBasis ι k P) {s : Finset ι} {i : ι} (hi : i ∈ s) : b.coord i (s.centroid k b) = (s.card : k)⁻¹ := by rw [Finset.centroid, b.coord_apply_combination_of_mem hi (s.sum_centroidWeights_eq_one_of_nonempty _ ⟨i, hi⟩), Finset.centroidWeights, Function.const_apply] theorem exists_affine_subbasis {t : Set P} (ht : affineSpan k t = ⊤) : ∃ s ⊆ t, ∃ b : AffineBasis s k P, ⇑b = ((↑) : s → P) := by obtain ⟨s, hst, h_tot, h_ind⟩ := exists_affineIndependent k V t refine ⟨s, hst, ⟨(↑), h_ind, ?_⟩, rfl⟩ rw [Subtype.range_coe, h_tot, ht] variable (k V P) theorem exists_affineBasis : ∃ (s : Set P) (b : AffineBasis (↥s) k P), ⇑b = ((↑) : s → P) := let ⟨s, _, hs⟩ := exists_affine_subbasis (AffineSubspace.span_univ k V P) ⟨s, hs⟩ end DivisionRing end AffineBasis
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/ContinuousAffineEquiv.lean
import Mathlib.Topology.Algebra.ContinuousAffineEquiv deprecated_module (since := "2025-09-20")
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/FiniteDimensional.lean
import Mathlib.FieldTheory.Finiteness import Mathlib.LinearAlgebra.AffineSpace.Basis import Mathlib.LinearAlgebra.AffineSpace.Simplex.Basic import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas /-! # Finite-dimensional subspaces of affine spaces. This file provides a few results relating to finite-dimensional subspaces of affine spaces. ## Main definitions * `Collinear` defines collinear sets of points as those that span a subspace of dimension at most 1. -/ noncomputable section open Affine open scoped Finset section AffineSpace' variable (k : Type*) {V : Type*} {P : Type*} variable {ι : Type*} open AffineSubspace Module variable [DivisionRing k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- The `vectorSpan` of a finite set is finite-dimensional. -/ theorem finiteDimensional_vectorSpan_of_finite {s : Set P} (h : Set.Finite s) : FiniteDimensional k (vectorSpan k s) := .span_of_finite k <| h.vsub h /-- The vector span of a singleton is finite-dimensional. -/ instance finiteDimensional_vectorSpan_singleton (p : P) : FiniteDimensional k (vectorSpan k {p}) := finiteDimensional_vectorSpan_of_finite _ (Set.finite_singleton p) /-- The `vectorSpan` of a family indexed by a `Fintype` is finite-dimensional. -/ instance finiteDimensional_vectorSpan_range [Finite ι] (p : ι → P) : FiniteDimensional k (vectorSpan k (Set.range p)) := finiteDimensional_vectorSpan_of_finite k (Set.finite_range _) /-- The `vectorSpan` of a subset of a family indexed by a `Fintype` is finite-dimensional. -/ instance finiteDimensional_vectorSpan_image_of_finite [Finite ι] (p : ι → P) (s : Set ι) : FiniteDimensional k (vectorSpan k (p '' s)) := finiteDimensional_vectorSpan_of_finite k (Set.toFinite _) /-- The direction of the affine span of a finite set is finite-dimensional. -/ theorem finiteDimensional_direction_affineSpan_of_finite {s : Set P} (h : Set.Finite s) : FiniteDimensional k (affineSpan k s).direction := (direction_affineSpan k s).symm ▸ finiteDimensional_vectorSpan_of_finite k h /-- The direction of the affine span of a singleton is finite-dimensional. -/ instance finiteDimensional_direction_affineSpan_singleton (p : P) : FiniteDimensional k (affineSpan k {p}).direction := by rw [direction_affineSpan] infer_instance /-- The direction of the affine span of a family indexed by a `Fintype` is finite-dimensional. -/ instance finiteDimensional_direction_affineSpan_range [Finite ι] (p : ι → P) : FiniteDimensional k (affineSpan k (Set.range p)).direction := finiteDimensional_direction_affineSpan_of_finite k (Set.finite_range _) /-- The direction of the affine span of a subset of a family indexed by a `Fintype` is finite-dimensional. -/ instance finiteDimensional_direction_affineSpan_image_of_finite [Finite ι] (p : ι → P) (s : Set ι) : FiniteDimensional k (affineSpan k (p '' s)).direction := finiteDimensional_direction_affineSpan_of_finite k (Set.toFinite _) /-- An affine-independent family of points in a finite-dimensional affine space is finite. -/ theorem finite_of_fin_dim_affineIndependent [FiniteDimensional k V] {p : ι → P} (hi : AffineIndependent k p) : Finite ι := by nontriviality ι; inhabit ι rw [affineIndependent_iff_linearIndependent_vsub k p default] at hi letI : IsNoetherian k V := IsNoetherian.iff_fg.2 inferInstance exact (Set.finite_singleton default).finite_of_compl (Set.finite_coe_iff.1 hi.finite_of_isNoetherian) /-- An affine-independent subset of a finite-dimensional affine space is finite. -/ theorem finite_set_of_fin_dim_affineIndependent [FiniteDimensional k V] {s : Set ι} {f : s → P} (hi : AffineIndependent k f) : s.Finite := @Set.toFinite _ s (finite_of_fin_dim_affineIndependent k hi) variable {k} /-- The supremum of two finite-dimensional affine subspaces is finite-dimensional. -/ instance AffineSubspace.finiteDimensional_sup (s₁ s₂ : AffineSubspace k P) [FiniteDimensional k s₁.direction] [FiniteDimensional k s₂.direction] : FiniteDimensional k (s₁ ⊔ s₂).direction := by rcases eq_bot_or_nonempty s₁ with rfl | ⟨p₁, hp₁⟩ · rwa [bot_sup_eq] rcases eq_bot_or_nonempty s₂ with rfl | ⟨p₂, hp₂⟩ · rwa [sup_bot_eq] rw [AffineSubspace.direction_sup hp₁ hp₂] infer_instance /-- The `vectorSpan` of a finite subset of an affinely independent family has dimension one less than its cardinality. -/ theorem AffineIndependent.finrank_vectorSpan_image_finset [DecidableEq P] {p : ι → P} (hi : AffineIndependent k p) {s : Finset ι} {n : ℕ} (hc : #s = n + 1) : finrank k (vectorSpan k (s.image p : Set P)) = n := by classical have hi' := hi.range.mono (Set.image_subset_range p ↑s) have hc' : #(s.image p) = n + 1 := by rwa [s.card_image_of_injective hi.injective] have hn : (s.image p).Nonempty := by simp [hc', ← Finset.card_pos] rcases hn with ⟨p₁, hp₁⟩ have hp₁' : p₁ ∈ p '' s := by simpa using hp₁ rw [affineIndependent_set_iff_linearIndependent_vsub k hp₁', ← Finset.coe_singleton, ← Finset.coe_image, ← Finset.coe_sdiff, Finset.sdiff_singleton_eq_erase, ← Finset.coe_image] at hi' have hc : #(((s.image p).erase p₁).image (· -ᵥ p₁)) = n := by rw [Finset.card_image_of_injective _ (vsub_left_injective _), Finset.card_erase_of_mem hp₁] exact Nat.pred_eq_of_eq_succ hc' rwa [vectorSpan_eq_span_vsub_finset_right_ne k hp₁, finrank_span_finset_eq_card, hc] /-- The `vectorSpan` of a finite affinely independent family has dimension one less than its cardinality. -/ theorem AffineIndependent.finrank_vectorSpan [Fintype ι] {p : ι → P} (hi : AffineIndependent k p) {n : ℕ} (hc : Fintype.card ι = n + 1) : finrank k (vectorSpan k (Set.range p)) = n := by classical rw [← Finset.card_univ] at hc rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image] exact hi.finrank_vectorSpan_image_finset hc /-- The `vectorSpan` of a finite affinely independent family has dimension one less than its cardinality. -/ lemma AffineIndependent.finrank_vectorSpan_add_one [Fintype ι] [Nonempty ι] {p : ι → P} (hi : AffineIndependent k p) : finrank k (vectorSpan k (Set.range p)) + 1 = Fintype.card ι := by rw [hi.finrank_vectorSpan (tsub_add_cancel_of_le _).symm, tsub_add_cancel_of_le] <;> exact Fintype.card_pos /-- The `vectorSpan` of a finite affinely independent family whose cardinality is one more than that of the finite-dimensional space is `⊤`. -/ theorem AffineIndependent.vectorSpan_eq_top_of_card_eq_finrank_add_one [FiniteDimensional k V] [Fintype ι] {p : ι → P} (hi : AffineIndependent k p) (hc : Fintype.card ι = finrank k V + 1) : vectorSpan k (Set.range p) = ⊤ := Submodule.eq_top_of_finrank_eq <| hi.finrank_vectorSpan hc variable (k) /-- The `vectorSpan` of `n + 1` points in an indexed family has dimension at most `n`. -/ theorem finrank_vectorSpan_image_finset_le [DecidableEq P] (p : ι → P) (s : Finset ι) {n : ℕ} (hc : #s = n + 1) : finrank k (vectorSpan k (s.image p : Set P)) ≤ n := by classical have hn : (s.image p).Nonempty := by rw [Finset.image_nonempty, ← Finset.card_pos, hc] apply Nat.succ_pos rcases hn with ⟨p₁, hp₁⟩ rw [vectorSpan_eq_span_vsub_finset_right_ne k hp₁] refine le_trans (finrank_span_finset_le_card (((s.image p).erase p₁).image fun p => p -ᵥ p₁)) ?_ rw [Finset.card_image_of_injective _ (vsub_left_injective p₁), Finset.card_erase_of_mem hp₁, tsub_le_iff_right, ← hc] apply Finset.card_image_le /-- The `vectorSpan` of an indexed family of `n + 1` points has dimension at most `n`. -/ theorem finrank_vectorSpan_range_le [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 1) : finrank k (vectorSpan k (Set.range p)) ≤ n := by classical rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image] rw [← Finset.card_univ] at hc exact finrank_vectorSpan_image_finset_le _ _ _ hc /-- The `vectorSpan` of an indexed family of `n + 1` points has dimension at most `n`. -/ lemma finrank_vectorSpan_range_add_one_le [Fintype ι] [Nonempty ι] (p : ι → P) : finrank k (vectorSpan k (Set.range p)) + 1 ≤ Fintype.card ι := (le_tsub_iff_right <| Nat.succ_le_iff.2 Fintype.card_pos).1 <| finrank_vectorSpan_range_le _ _ (tsub_add_cancel_of_le <| Nat.succ_le_iff.2 Fintype.card_pos).symm /-- `n + 1` points are affinely independent if and only if their `vectorSpan` has dimension `n`. -/ theorem affineIndependent_iff_finrank_vectorSpan_eq [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 1) : AffineIndependent k p ↔ finrank k (vectorSpan k (Set.range p)) = n := by classical have hn : Nonempty ι := by simp [← Fintype.card_pos_iff, hc] obtain ⟨i₁⟩ := hn rw [affineIndependent_iff_linearIndependent_vsub _ _ i₁, linearIndependent_iff_card_eq_finrank_span, eq_comm, vectorSpan_range_eq_span_range_vsub_right_ne k p i₁, Set.finrank] rw [← Finset.card_univ] at hc rw [Fintype.subtype_card] simp [Finset.filter_ne', Finset.card_erase_of_mem, hc] /-- `n + 1` points are affinely independent if and only if their `vectorSpan` has dimension at least `n`. -/ theorem affineIndependent_iff_le_finrank_vectorSpan [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 1) : AffineIndependent k p ↔ n ≤ finrank k (vectorSpan k (Set.range p)) := by rw [affineIndependent_iff_finrank_vectorSpan_eq k p hc] constructor · rintro rfl rfl · exact fun hle => le_antisymm (finrank_vectorSpan_range_le k p hc) hle /-- `n + 2` points are affinely independent if and only if their `vectorSpan` does not have dimension at most `n`. -/ theorem affineIndependent_iff_not_finrank_vectorSpan_le [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 2) : AffineIndependent k p ↔ ¬finrank k (vectorSpan k (Set.range p)) ≤ n := by rw [affineIndependent_iff_le_finrank_vectorSpan k p hc, ← Nat.lt_iff_add_one_le, lt_iff_not_ge] /-- `n + 2` points have a `vectorSpan` with dimension at most `n` if and only if they are not affinely independent. -/ theorem finrank_vectorSpan_le_iff_not_affineIndependent [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 2) : finrank k (vectorSpan k (Set.range p)) ≤ n ↔ ¬AffineIndependent k p := (not_iff_comm.1 (affineIndependent_iff_not_finrank_vectorSpan_le k p hc).symm).symm variable {k} lemma AffineIndependent.card_le_finrank_succ [Fintype ι] {p : ι → P} (hp : AffineIndependent k p) : Fintype.card ι ≤ Module.finrank k (vectorSpan k (Set.range p)) + 1 := by cases isEmpty_or_nonempty ι · simp [Fintype.card_eq_zero] rw [← tsub_le_iff_right] exact (affineIndependent_iff_le_finrank_vectorSpan _ _ (tsub_add_cancel_of_le <| Nat.one_le_iff_ne_zero.2 Fintype.card_ne_zero).symm).1 hp open Finset in /-- If an affine independent finset is contained in the affine span of another finset, then its cardinality is at most the cardinality of that finset. -/ lemma AffineIndependent.card_le_card_of_subset_affineSpan {s t : Finset V} (hs : AffineIndependent k ((↑) : s → V)) (hst : (s : Set V) ⊆ affineSpan k (t : Set V)) : #s ≤ #t := by obtain rfl | hs' := s.eq_empty_or_nonempty · simp obtain rfl | ht' := t.eq_empty_or_nonempty · simpa [Set.subset_empty_iff] using hst have := hs'.to_subtype have := ht'.to_set.to_subtype have direction_le := AffineSubspace.direction_le (affineSpan_mono k hst) rw [AffineSubspace.affineSpan_coe, direction_affineSpan, direction_affineSpan, ← @Subtype.range_coe _ (s : Set V), ← @Subtype.range_coe _ (t : Set V)] at direction_le have finrank_le := add_le_add_right (Submodule.finrank_mono direction_le) 1 -- We use `erw` to elide the difference between `↥s` and `↥(s : Set V)}` erw [hs.finrank_vectorSpan_add_one] at finrank_le simpa using finrank_le.trans <| finrank_vectorSpan_range_add_one_le _ _ open Finset in /-- If the affine span of an affine independent finset is strictly contained in the affine span of another finset, then its cardinality is strictly less than the cardinality of that finset. -/ lemma AffineIndependent.card_lt_card_of_affineSpan_lt_affineSpan {s t : Finset V} (hs : AffineIndependent k ((↑) : s → V)) (hst : affineSpan k (s : Set V) < affineSpan k (t : Set V)) : #s < #t := by obtain rfl | hs' := s.eq_empty_or_nonempty · simpa [card_pos] using hst obtain rfl | ht' := t.eq_empty_or_nonempty · simp at hst have := hs'.to_subtype have := ht'.to_set.to_subtype have dir_lt := AffineSubspace.direction_lt_of_nonempty (k := k) hst <| hs'.to_set.affineSpan k rw [direction_affineSpan, direction_affineSpan, ← @Subtype.range_coe _ (s : Set V), ← @Subtype.range_coe _ (t : Set V)] at dir_lt have finrank_lt := add_lt_add_right (Submodule.finrank_lt_finrank_of_lt dir_lt) 1 -- We use `erw` to elide the difference between `↥s` and `↥(s : Set V)}` erw [hs.finrank_vectorSpan_add_one] at finrank_lt simpa using finrank_lt.trans_le <| finrank_vectorSpan_range_add_one_le _ _ /-- If the `vectorSpan` of a finite subset of an affinely independent family lies in a submodule with dimension one less than its cardinality, it equals that submodule. -/ theorem AffineIndependent.vectorSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one [DecidableEq P] {p : ι → P} (hi : AffineIndependent k p) {s : Finset ι} {sm : Submodule k V} [FiniteDimensional k sm] (hle : vectorSpan k (s.image p : Set P) ≤ sm) (hc : #s = finrank k sm + 1) : vectorSpan k (s.image p : Set P) = sm := Submodule.eq_of_le_of_finrank_eq hle <| hi.finrank_vectorSpan_image_finset hc /-- If the `vectorSpan` of a finite affinely independent family lies in a submodule with dimension one less than its cardinality, it equals that submodule. -/ theorem AffineIndependent.vectorSpan_eq_of_le_of_card_eq_finrank_add_one [Fintype ι] {p : ι → P} (hi : AffineIndependent k p) {sm : Submodule k V} [FiniteDimensional k sm] (hle : vectorSpan k (Set.range p) ≤ sm) (hc : Fintype.card ι = finrank k sm + 1) : vectorSpan k (Set.range p) = sm := Submodule.eq_of_le_of_finrank_eq hle <| hi.finrank_vectorSpan hc /-- If the `affineSpan` of a finite subset of an affinely independent family lies in an affine subspace whose direction has dimension one less than its cardinality, it equals that subspace. -/ theorem AffineIndependent.affineSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one [DecidableEq P] {p : ι → P} (hi : AffineIndependent k p) {s : Finset ι} {sp : AffineSubspace k P} [FiniteDimensional k sp.direction] (hle : affineSpan k (s.image p : Set P) ≤ sp) (hc : #s = finrank k sp.direction + 1) : affineSpan k (s.image p : Set P) = sp := by have hn : s.Nonempty := by rw [← Finset.card_pos, hc] apply Nat.succ_pos refine eq_of_direction_eq_of_nonempty_of_le ?_ ((hn.image p).to_set.affineSpan k) hle have hd := direction_le hle rw [direction_affineSpan] at hd ⊢ exact hi.vectorSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one hd hc /-- If the `affineSpan` of a finite affinely independent family lies in an affine subspace whose direction has dimension one less than its cardinality, it equals that subspace. -/ theorem AffineIndependent.affineSpan_eq_of_le_of_card_eq_finrank_add_one [Fintype ι] {p : ι → P} (hi : AffineIndependent k p) {sp : AffineSubspace k P} [FiniteDimensional k sp.direction] (hle : affineSpan k (Set.range p) ≤ sp) (hc : Fintype.card ι = finrank k sp.direction + 1) : affineSpan k (Set.range p) = sp := by classical rw [← Finset.card_univ] at hc rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image] at hle ⊢ exact hi.affineSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one hle hc /-- The `affineSpan` of a finite affinely independent family is `⊤` iff the family's cardinality is one more than that of the finite-dimensional space. -/ theorem AffineIndependent.affineSpan_eq_top_iff_card_eq_finrank_add_one [FiniteDimensional k V] [Fintype ι] {p : ι → P} (hi : AffineIndependent k p) : affineSpan k (Set.range p) = ⊤ ↔ Fintype.card ι = finrank k V + 1 := by constructor · intro h_tot let n := Fintype.card ι - 1 have hn : Fintype.card ι = n + 1 := (Nat.succ_pred_eq_of_pos (card_pos_of_affineSpan_eq_top k V P h_tot)).symm rw [hn, ← finrank_top, ← (vectorSpan_eq_top_of_affineSpan_eq_top k V P) h_tot, ← hi.finrank_vectorSpan hn] · intro hc rw [← finrank_top, ← direction_top k V P] at hc exact hi.affineSpan_eq_of_le_of_card_eq_finrank_add_one le_top hc theorem Affine.Simplex.span_eq_top [FiniteDimensional k V] {n : ℕ} (T : Affine.Simplex k V n) (hrank : finrank k V = n) : affineSpan k (Set.range T.points) = ⊤ := by rw [AffineIndependent.affineSpan_eq_top_iff_card_eq_finrank_add_one T.independent, Fintype.card_fin, hrank] /-- The `vectorSpan` of adding a point to a finite-dimensional subspace is finite-dimensional. -/ instance finiteDimensional_vectorSpan_insert (s : AffineSubspace k P) [FiniteDimensional k s.direction] (p : P) : FiniteDimensional k (vectorSpan k (insert p (s : Set P))) := by rw [← direction_affineSpan, ← affineSpan_insert_affineSpan] rcases (s : Set P).eq_empty_or_nonempty with (hs | ⟨p₀, hp₀⟩) · rw [coe_eq_bot_iff] at hs rw [hs, bot_coe, span_empty, bot_coe, direction_affineSpan] convert finiteDimensional_bot k V <;> simp · rw [affineSpan_coe, direction_affineSpan_insert hp₀] infer_instance /-- The direction of the affine span of adding a point to a finite-dimensional subspace is finite-dimensional. -/ instance finiteDimensional_direction_affineSpan_insert (s : AffineSubspace k P) [FiniteDimensional k s.direction] (p : P) : FiniteDimensional k (affineSpan k (insert p (s : Set P))).direction := (direction_affineSpan k (insert p (s : Set P))).symm ▸ finiteDimensional_vectorSpan_insert s p variable (k) /-- The `vectorSpan` of adding a point to a set with a finite-dimensional `vectorSpan` is finite-dimensional. -/ instance finiteDimensional_vectorSpan_insert_set (s : Set P) [FiniteDimensional k (vectorSpan k s)] (p : P) : FiniteDimensional k (vectorSpan k (insert p s)) := by haveI : FiniteDimensional k (affineSpan k s).direction := (direction_affineSpan k s).symm ▸ inferInstance rw [← direction_affineSpan, ← affineSpan_insert_affineSpan, direction_affineSpan] exact finiteDimensional_vectorSpan_insert (affineSpan k s) p /-- The direction of the affine span of adding a point to a set with a set with finite-dimensional direction of the `affineSpan` is finite-dimensional. -/ instance finiteDimensional_direction_affineSpan_insert_set (s : Set P) [FiniteDimensional k (affineSpan k s).direction] (p : P) : FiniteDimensional k (affineSpan k (insert p s)).direction := by haveI : FiniteDimensional k (vectorSpan k s) := (direction_affineSpan k s) ▸ inferInstance rw [direction_affineSpan] infer_instance /-- A set of points is collinear if their `vectorSpan` has dimension at most `1`. -/ def Collinear (s : Set P) : Prop := Module.rank k (vectorSpan k s) ≤ 1 /-- The definition of `Collinear`. -/ theorem collinear_iff_rank_le_one (s : Set P) : Collinear k s ↔ Module.rank k (vectorSpan k s) ≤ 1 := Iff.rfl variable {k} /-- A set of points, whose `vectorSpan` is finite-dimensional, is collinear if and only if their `vectorSpan` has dimension at most `1`. -/ theorem collinear_iff_finrank_le_one {s : Set P} [FiniteDimensional k (vectorSpan k s)] : Collinear k s ↔ finrank k (vectorSpan k s) ≤ 1 := by have h := collinear_iff_rank_le_one k s rw [← finrank_eq_rank] at h exact mod_cast h alias ⟨Collinear.finrank_le_one, _⟩ := collinear_iff_finrank_le_one /-- A subset of a collinear set is collinear. -/ theorem Collinear.subset {s₁ s₂ : Set P} (hs : s₁ ⊆ s₂) (h : Collinear k s₂) : Collinear k s₁ := (Submodule.rank_mono (vectorSpan_mono k hs)).trans h /-- The `vectorSpan` of collinear points is finite-dimensional. -/ theorem Collinear.finiteDimensional_vectorSpan {s : Set P} (h : Collinear k s) : FiniteDimensional k (vectorSpan k s) := IsNoetherian.iff_fg.1 (IsNoetherian.iff_rank_lt_aleph0.2 (lt_of_le_of_lt h Cardinal.one_lt_aleph0)) /-- The direction of the affine span of collinear points is finite-dimensional. -/ theorem Collinear.finiteDimensional_direction_affineSpan {s : Set P} (h : Collinear k s) : FiniteDimensional k (affineSpan k s).direction := (direction_affineSpan k s).symm ▸ h.finiteDimensional_vectorSpan variable (k P) /-- The empty set is collinear. -/ theorem collinear_empty : Collinear k (∅ : Set P) := by rw [collinear_iff_rank_le_one, vectorSpan_empty] simp variable {P} /-- A single point is collinear. -/ theorem collinear_singleton (p : P) : Collinear k ({p} : Set P) := by rw [collinear_iff_rank_le_one, vectorSpan_singleton] simp variable {k} /-- Given a point `p₀` in a set of points, that set is collinear if and only if the points can all be expressed as multiples of the same vector, added to `p₀`. -/ theorem collinear_iff_of_mem {s : Set P} {p₀ : P} (h : p₀ ∈ s) : Collinear k s ↔ ∃ v : V, ∀ p ∈ s, ∃ r : k, p = r • v +ᵥ p₀ := by simp_rw [collinear_iff_rank_le_one, rank_submodule_le_one_iff', Submodule.le_span_singleton_iff] constructor · rintro ⟨v₀, hv⟩ use v₀ intro p hp obtain ⟨r, hr⟩ := hv (p -ᵥ p₀) (vsub_mem_vectorSpan k hp h) use r rw [eq_vadd_iff_vsub_eq] exact hr.symm · rintro ⟨v, hp₀v⟩ use v intro w hw have hs : vectorSpan k s ≤ k ∙ v := by rw [vectorSpan_eq_span_vsub_set_right k h, Submodule.span_le, Set.subset_def] intro x hx rw [SetLike.mem_coe, Submodule.mem_span_singleton] rw [Set.mem_image] at hx rcases hx with ⟨p, hp, rfl⟩ rcases hp₀v p hp with ⟨r, rfl⟩ use r simp have hw' := SetLike.le_def.1 hs hw rwa [Submodule.mem_span_singleton] at hw' /-- A set of points is collinear if and only if they can all be expressed as multiples of the same vector, added to the same base point. -/ theorem collinear_iff_exists_forall_eq_smul_vadd (s : Set P) : Collinear k s ↔ ∃ (p₀ : P) (v : V), ∀ p ∈ s, ∃ r : k, p = r • v +ᵥ p₀ := by rcases Set.eq_empty_or_nonempty s with (rfl | ⟨⟨p₁, hp₁⟩⟩) · simp [collinear_empty] · rw [collinear_iff_of_mem hp₁] constructor · exact fun h => ⟨p₁, h⟩ · rintro ⟨p, v, hv⟩ use v intro p₂ hp₂ rcases hv p₂ hp₂ with ⟨r, rfl⟩ rcases hv p₁ hp₁ with ⟨r₁, rfl⟩ use r - r₁ simp [vadd_vadd, ← add_smul] variable (k) in /-- Two points are collinear. -/ theorem collinear_pair (p₁ p₂ : P) : Collinear k ({p₁, p₂} : Set P) := by rw [collinear_iff_exists_forall_eq_smul_vadd] use p₁, p₂ -ᵥ p₁ intro p hp rw [Set.mem_insert_iff, Set.mem_singleton_iff] at hp rcases hp with hp | hp · use 0 simp [hp] · use 1 simp [hp] /-- Three points are affinely independent if and only if they are not collinear. -/ theorem affineIndependent_iff_not_collinear {p : Fin 3 → P} : AffineIndependent k p ↔ ¬Collinear k (Set.range p) := by rw [collinear_iff_finrank_le_one, affineIndependent_iff_not_finrank_vectorSpan_le k p (Fintype.card_fin 3)] /-- Three points are collinear if and only if they are not affinely independent. -/ theorem collinear_iff_not_affineIndependent {p : Fin 3 → P} : Collinear k (Set.range p) ↔ ¬AffineIndependent k p := by rw [collinear_iff_finrank_le_one, finrank_vectorSpan_le_iff_not_affineIndependent k p (Fintype.card_fin 3)] /-- Three points are affinely independent if and only if they are not collinear. -/ theorem affineIndependent_iff_not_collinear_set {p₁ p₂ p₃ : P} : AffineIndependent k ![p₁, p₂, p₃] ↔ ¬Collinear k ({p₁, p₂, p₃} : Set P) := by rw [affineIndependent_iff_not_collinear] simp_rw [Matrix.range_cons, Matrix.range_empty, Set.singleton_union, insert_empty_eq] /-- Three points are collinear if and only if they are not affinely independent. -/ theorem collinear_iff_not_affineIndependent_set {p₁ p₂ p₃ : P} : Collinear k ({p₁, p₂, p₃} : Set P) ↔ ¬AffineIndependent k ![p₁, p₂, p₃] := affineIndependent_iff_not_collinear_set.not_left.symm /-- Three points are affinely independent if and only if they are not collinear. -/ theorem affineIndependent_iff_not_collinear_of_ne {p : Fin 3 → P} {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : AffineIndependent k p ↔ ¬Collinear k ({p i₁, p i₂, p i₃} : Set P) := by have hu : (Finset.univ : Finset (Fin 3)) = {i₁, i₂, i₃} := by decide +revert rw [affineIndependent_iff_not_collinear, ← Set.image_univ, ← Finset.coe_univ, hu, Finset.coe_insert, Finset.coe_insert, Finset.coe_singleton, Set.image_insert_eq, Set.image_pair] /-- Three points are collinear if and only if they are not affinely independent. -/ theorem collinear_iff_not_affineIndependent_of_ne {p : Fin 3 → P} {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) : Collinear k ({p i₁, p i₂, p i₃} : Set P) ↔ ¬AffineIndependent k p := (affineIndependent_iff_not_collinear_of_ne h₁₂ h₁₃ h₂₃).not_left.symm /-- If three points are not collinear, the first and second are different. -/ theorem ne₁₂_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear k ({p₁, p₂, p₃} : Set P)) : p₁ ≠ p₂ := by rintro rfl simp [collinear_pair] at h /-- If three points are not collinear, the first and third are different. -/ theorem ne₁₃_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear k ({p₁, p₂, p₃} : Set P)) : p₁ ≠ p₃ := by rintro rfl simp [collinear_pair] at h /-- If three points are not collinear, the second and third are different. -/ theorem ne₂₃_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear k ({p₁, p₂, p₃} : Set P)) : p₂ ≠ p₃ := by rintro rfl simp [collinear_pair] at h /-- A point in a collinear set of points lies in the affine span of any two distinct points of that set. -/ theorem Collinear.mem_affineSpan_of_mem_of_ne {s : Set P} (h : Collinear k s) {p₁ p₂ p₃ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₁p₂ : p₁ ≠ p₂) : p₃ ∈ line[k, p₁, p₂] := by rw [collinear_iff_of_mem hp₁] at h rcases h with ⟨v, h⟩ rcases h p₂ hp₂ with ⟨r₂, rfl⟩ rcases h p₃ hp₃ with ⟨r₃, rfl⟩ rw [vadd_left_mem_affineSpan_pair] refine ⟨r₃ / r₂, ?_⟩ have h₂ : r₂ ≠ 0 := by rintro rfl simp at hp₁p₂ simp [smul_smul, h₂] /-- The affine span of any two distinct points of a collinear set of points equals the affine span of the whole set. -/ theorem Collinear.affineSpan_eq_of_ne {s : Set P} (h : Collinear k s) {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₁p₂ : p₁ ≠ p₂) : line[k, p₁, p₂] = affineSpan k s := le_antisymm (affineSpan_mono _ (Set.insert_subset_iff.2 ⟨hp₁, Set.singleton_subset_iff.2 hp₂⟩)) (affineSpan_le.2 fun _ hp => h.mem_affineSpan_of_mem_of_ne hp₁ hp₂ hp hp₁p₂) /-- Given a collinear set of points, and two distinct points `p₂` and `p₃` in it, a point `p₁` is collinear with the set if and only if it is collinear with `p₂` and `p₃`. -/ theorem Collinear.collinear_insert_iff_of_ne {s : Set P} (h : Collinear k s) {p₁ p₂ p₃ : P} (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₂p₃ : p₂ ≠ p₃) : Collinear k (insert p₁ s) ↔ Collinear k ({p₁, p₂, p₃} : Set P) := by have hv : vectorSpan k (insert p₁ s) = vectorSpan k ({p₁, p₂, p₃} : Set P) := by conv_rhs => rw [← direction_affineSpan, ← affineSpan_insert_affineSpan] rw [← direction_affineSpan, ← affineSpan_insert_affineSpan, h.affineSpan_eq_of_ne hp₂ hp₃ hp₂p₃] rw [Collinear, Collinear, hv] /-- Adding a point in the affine span of a set does not change whether that set is collinear. -/ theorem collinear_insert_iff_of_mem_affineSpan {s : Set P} {p : P} (h : p ∈ affineSpan k s) : Collinear k (insert p s) ↔ Collinear k s := by rw [Collinear, Collinear, vectorSpan_insert_eq_vectorSpan h] /-- If a point lies in the affine span of two points, those three points are collinear. -/ theorem collinear_insert_of_mem_affineSpan_pair {p₁ p₂ p₃ : P} (h : p₁ ∈ line[k, p₂, p₃]) : Collinear k ({p₁, p₂, p₃} : Set P) := by rw [collinear_insert_iff_of_mem_affineSpan h] exact collinear_pair _ _ _ /-- If two points lie in the affine span of two points, those four points are collinear. -/ theorem collinear_insert_insert_of_mem_affineSpan_pair {p₁ p₂ p₃ p₄ : P} (h₁ : p₁ ∈ line[k, p₃, p₄]) (h₂ : p₂ ∈ line[k, p₃, p₄]) : Collinear k ({p₁, p₂, p₃, p₄} : Set P) := by rw [collinear_insert_iff_of_mem_affineSpan ((AffineSubspace.le_def' _ _).1 (affineSpan_mono k (Set.subset_insert _ _)) _ h₁), collinear_insert_iff_of_mem_affineSpan h₂] exact collinear_pair _ _ _ /-- If three points lie in the affine span of two points, those five points are collinear. -/ theorem collinear_insert_insert_insert_of_mem_affineSpan_pair {p₁ p₂ p₃ p₄ p₅ : P} (h₁ : p₁ ∈ line[k, p₄, p₅]) (h₂ : p₂ ∈ line[k, p₄, p₅]) (h₃ : p₃ ∈ line[k, p₄, p₅]) : Collinear k ({p₁, p₂, p₃, p₄, p₅} : Set P) := by rw [collinear_insert_iff_of_mem_affineSpan ((AffineSubspace.le_def' _ _).1 (affineSpan_mono k ((Set.subset_insert _ _).trans (Set.subset_insert _ _))) _ h₁), collinear_insert_iff_of_mem_affineSpan ((AffineSubspace.le_def' _ _).1 (affineSpan_mono k (Set.subset_insert _ _)) _ h₂), collinear_insert_iff_of_mem_affineSpan h₃] exact collinear_pair _ _ _ /-- If three points lie in the affine span of two points, the first four points are collinear. -/ theorem collinear_insert_insert_insert_left_of_mem_affineSpan_pair {p₁ p₂ p₃ p₄ p₅ : P} (h₁ : p₁ ∈ line[k, p₄, p₅]) (h₂ : p₂ ∈ line[k, p₄, p₅]) (h₃ : p₃ ∈ line[k, p₄, p₅]) : Collinear k ({p₁, p₂, p₃, p₄} : Set P) := by refine (collinear_insert_insert_insert_of_mem_affineSpan_pair h₁ h₂ h₃).subset ?_ gcongr; simp /-- If three points lie in the affine span of two points, the first three points are collinear. -/ theorem collinear_triple_of_mem_affineSpan_pair {p₁ p₂ p₃ p₄ p₅ : P} (h₁ : p₁ ∈ line[k, p₄, p₅]) (h₂ : p₂ ∈ line[k, p₄, p₅]) (h₃ : p₃ ∈ line[k, p₄, p₅]) : Collinear k ({p₁, p₂, p₃} : Set P) := by refine (collinear_insert_insert_insert_left_of_mem_affineSpan_pair h₁ h₂ h₃).subset ?_ gcongr; simp /-- Replacing a point in an affine independent triple with a collinear point preserves affine independence. -/ theorem affineIndependent_of_affineIndependent_collinear_ne {p₁ p₂ p₃ p : P} (ha : AffineIndependent k ![p₁, p₂, p₃]) (hcol : Collinear k {p₂, p₃, p}) (hne : p₂ ≠ p) : AffineIndependent k ![p₁, p₂, p] := by rw [affineIndependent_iff_not_collinear_set] by_contra h have h1: Collinear k {p₁, p₃, p₂, p} := by apply collinear_insert_insert_of_mem_affineSpan_pair · apply Collinear.mem_affineSpan_of_mem_of_ne h (by simp) (by simp) (by simp) hne · apply Collinear.mem_affineSpan_of_mem_of_ne hcol (by simp) (by simp) (by simp) hne have h2 : Collinear k {p₁, p₂, p₃} := h1.subset (by grind) rw [affineIndependent_iff_not_collinear_set] at ha exact ha h2 variable (k) in /-- A set of points is coplanar if their `vectorSpan` has dimension at most `2`. -/ def Coplanar (s : Set P) : Prop := Module.rank k (vectorSpan k s) ≤ 2 /-- The `vectorSpan` of coplanar points is finite-dimensional. -/ theorem Coplanar.finiteDimensional_vectorSpan {s : Set P} (h : Coplanar k s) : FiniteDimensional k (vectorSpan k s) := by refine IsNoetherian.iff_fg.1 (IsNoetherian.iff_rank_lt_aleph0.2 (lt_of_le_of_lt h ?_)) exact Cardinal.lt_aleph0.2 ⟨2, rfl⟩ /-- The direction of the affine span of coplanar points is finite-dimensional. -/ theorem Coplanar.finiteDimensional_direction_affineSpan {s : Set P} (h : Coplanar k s) : FiniteDimensional k (affineSpan k s).direction := (direction_affineSpan k s).symm ▸ h.finiteDimensional_vectorSpan /-- A set of points, whose `vectorSpan` is finite-dimensional, is coplanar if and only if their `vectorSpan` has dimension at most `2`. -/ theorem coplanar_iff_finrank_le_two {s : Set P} [FiniteDimensional k (vectorSpan k s)] : Coplanar k s ↔ finrank k (vectorSpan k s) ≤ 2 := by have h : Coplanar k s ↔ Module.rank k (vectorSpan k s) ≤ 2 := Iff.rfl rw [← finrank_eq_rank] at h exact mod_cast h alias ⟨Coplanar.finrank_le_two, _⟩ := coplanar_iff_finrank_le_two /-- A subset of a coplanar set is coplanar. -/ theorem Coplanar.subset {s₁ s₂ : Set P} (hs : s₁ ⊆ s₂) (h : Coplanar k s₂) : Coplanar k s₁ := (Submodule.rank_mono (vectorSpan_mono k hs)).trans h /-- Collinear points are coplanar. -/ theorem Collinear.coplanar {s : Set P} (h : Collinear k s) : Coplanar k s := le_trans h one_le_two variable (k) (P) /-- The empty set is coplanar. -/ theorem coplanar_empty : Coplanar k (∅ : Set P) := (collinear_empty k P).coplanar variable {P} /-- A single point is coplanar. -/ theorem coplanar_singleton (p : P) : Coplanar k ({p} : Set P) := (collinear_singleton k p).coplanar /-- Two points are coplanar. -/ theorem coplanar_pair (p₁ p₂ : P) : Coplanar k ({p₁, p₂} : Set P) := (collinear_pair k p₁ p₂).coplanar variable {k} /-- Adding a point in the affine span of a set does not change whether that set is coplanar. -/ theorem coplanar_insert_iff_of_mem_affineSpan {s : Set P} {p : P} (h : p ∈ affineSpan k s) : Coplanar k (insert p s) ↔ Coplanar k s := by rw [Coplanar, Coplanar, vectorSpan_insert_eq_vectorSpan h] end AffineSpace' section DivisionRing variable {k : Type*} {V : Type*} {P : Type*} open AffineSubspace Module Module variable [DivisionRing k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- Adding a point to a finite-dimensional subspace increases the dimension by at most one. -/ theorem finrank_vectorSpan_insert_le (s : AffineSubspace k P) (p : P) : finrank k (vectorSpan k (insert p (s : Set P))) ≤ finrank k s.direction + 1 := by by_cases hf : FiniteDimensional k s.direction; swap · have hf' : ¬FiniteDimensional k (vectorSpan k (insert p (s : Set P))) := by intro h have h' : s.direction ≤ vectorSpan k (insert p (s : Set P)) := by conv_lhs => rw [← affineSpan_coe s, direction_affineSpan] exact vectorSpan_mono k (Set.subset_insert _ _) exact hf (Submodule.finiteDimensional_of_le h') rw [finrank_of_infinite_dimensional hf, finrank_of_infinite_dimensional hf', zero_add] exact zero_le_one rw [← direction_affineSpan, ← affineSpan_insert_affineSpan] rcases (s : Set P).eq_empty_or_nonempty with (hs | ⟨p₀, hp₀⟩) · rw [coe_eq_bot_iff] at hs rw [hs, bot_coe, span_empty, bot_coe, direction_affineSpan, direction_bot, finrank_bot, zero_add] convert zero_le_one' ℕ rw [← finrank_bot k V] convert rfl <;> simp · rw [affineSpan_coe, direction_affineSpan_insert hp₀, add_comm] refine (Submodule.finrank_add_le_finrank_add_finrank _ _).trans (add_le_add_right ?_ _) refine finrank_le_one ⟨p -ᵥ p₀, Submodule.mem_span_singleton_self _⟩ fun v => ?_ have h := v.property rw [Submodule.mem_span_singleton] at h rcases h with ⟨c, hc⟩ refine ⟨c, ?_⟩ ext exact hc variable (k) in /-- Adding a point to a set with a finite-dimensional span increases the dimension by at most one. -/ theorem finrank_vectorSpan_insert_le_set (s : Set P) (p : P) : finrank k (vectorSpan k (insert p s)) ≤ finrank k (vectorSpan k s) + 1 := by rw [← direction_affineSpan, ← affineSpan_insert_affineSpan, direction_affineSpan, ← direction_affineSpan _ s] exact finrank_vectorSpan_insert_le .. /-- Adding a point to a collinear set produces a coplanar set. -/ theorem Collinear.coplanar_insert {s : Set P} (h : Collinear k s) (p : P) : Coplanar k (insert p s) := by have : FiniteDimensional k { x // x ∈ vectorSpan k s } := h.finiteDimensional_vectorSpan grw [coplanar_iff_finrank_le_two, finrank_vectorSpan_insert_le_set, h.finrank_le_one] /-- A set of points in a two-dimensional space is coplanar. -/ theorem coplanar_of_finrank_eq_two (s : Set P) (h : finrank k V = 2) : Coplanar k s := by have : FiniteDimensional k V := .of_finrank_eq_succ h rw [coplanar_iff_finrank_le_two, ← h] exact Submodule.finrank_le _ /-- A set of points in a two-dimensional space is coplanar. -/ theorem coplanar_of_fact_finrank_eq_two (s : Set P) [h : Fact (finrank k V = 2)] : Coplanar k s := coplanar_of_finrank_eq_two s h.out variable (k) /-- Three points are coplanar. -/ theorem coplanar_triple (p₁ p₂ p₃ : P) : Coplanar k ({p₁, p₂, p₃} : Set P) := (collinear_pair k p₂ p₃).coplanar_insert p₁ end DivisionRing namespace AffineBasis universe u₁ u₂ u₃ u₄ variable {ι : Type u₁} {k : Type u₂} {V : Type u₃} {P : Type u₄} variable [AddCommGroup V] [AffineSpace V P] section DivisionRing variable [DivisionRing k] [Module k V] protected theorem finiteDimensional [Finite ι] (b : AffineBasis ι k P) : FiniteDimensional k V := let ⟨i⟩ := b.nonempty (b.basisOf i).finiteDimensional_of_finite protected theorem finite [FiniteDimensional k V] (b : AffineBasis ι k P) : Finite ι := finite_of_fin_dim_affineIndependent k b.ind protected theorem finite_set [FiniteDimensional k V] {s : Set ι} (b : AffineBasis s k P) : s.Finite := finite_set_of_fin_dim_affineIndependent k b.ind theorem card_eq_finrank_add_one [Fintype ι] (b : AffineBasis ι k P) : Fintype.card ι = Module.finrank k V + 1 := have : FiniteDimensional k V := b.finiteDimensional b.ind.affineSpan_eq_top_iff_card_eq_finrank_add_one.mp b.tot theorem exists_affineBasis_of_finiteDimensional [Fintype ι] [FiniteDimensional k V] (h : Fintype.card ι = Module.finrank k V + 1) : Nonempty (AffineBasis ι k P) := by obtain ⟨s, b, hb⟩ := AffineBasis.exists_affineBasis k V P lift s to Finset P using b.finite_set refine ⟨b.reindex <| Fintype.equivOfCardEq ?_⟩ rw [h, ← b.card_eq_finrank_add_one] end DivisionRing end AffineBasis
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/AffineEquiv.lean
import Mathlib.LinearAlgebra.AffineSpace.AffineMap import Mathlib.LinearAlgebra.GeneralLinearGroup /-! # Affine equivalences In this file we define `AffineEquiv k P₁ P₂` (notation: `P₁ ≃ᵃ[k] P₂`) to be the type of affine equivalences between `P₁` and `P₂`, i.e., equivalences such that both forward and inverse maps are affine maps. We define the following equivalences: * `AffineEquiv.refl k P`: the identity map as an `AffineEquiv`; * `e.symm`: the inverse map of an `AffineEquiv` as an `AffineEquiv`; * `e.trans e'`: composition of two `AffineEquiv`s; note that the order follows `mathlib`'s `CategoryTheory` convention (apply `e`, then `e'`), not the convention used in function composition and compositions of bundled morphisms. We equip `AffineEquiv k P P` with a `Group` structure with multiplication corresponding to composition in `AffineEquiv.group`. ## Tags affine space, affine equivalence -/ open Function Set open Affine /-- An affine equivalence, denoted `P₁ ≃ᵃ[k] P₂`, is an equivalence between affine spaces such that both forward and inverse maps are affine. We define it using an `Equiv` for the map and a `LinearEquiv` for the linear part in order to allow affine equivalences with good definitional equalities. -/ structure AffineEquiv (k P₁ P₂ : Type*) {V₁ V₂ : Type*} [Ring k] [AddCommGroup V₁] [AddCommGroup V₂] [Module k V₁] [Module k V₂] [AddTorsor V₁ P₁] [AddTorsor V₂ P₂] extends P₁ ≃ P₂ where /-- The underlying linear equiv of modules. -/ linear : V₁ ≃ₗ[k] V₂ map_vadd' : ∀ (p : P₁) (v : V₁), toEquiv (v +ᵥ p) = linear v +ᵥ toEquiv p @[inherit_doc] notation:25 P₁ " ≃ᵃ[" k:25 "] " P₂:0 => AffineEquiv k P₁ P₂ variable {k P₁ P₂ P₃ P₄ V₁ V₂ V₃ V₄ : Type*} [Ring k] [AddCommGroup V₁] [AddCommGroup V₂] [AddCommGroup V₃] [AddCommGroup V₄] [Module k V₁] [Module k V₂] [Module k V₃] [Module k V₄] [AddTorsor V₁ P₁] [AddTorsor V₂ P₂] [AddTorsor V₃ P₃] [AddTorsor V₄ P₄] namespace AffineEquiv /-- Reinterpret an `AffineEquiv` as an `AffineMap`. -/ @[coe] def toAffineMap (e : P₁ ≃ᵃ[k] P₂) : P₁ →ᵃ[k] P₂ := { e with } @[simp] theorem toAffineMap_mk (f : P₁ ≃ P₂) (f' : V₁ ≃ₗ[k] V₂) (h) : toAffineMap (mk f f' h) = ⟨f, f', h⟩ := rfl @[simp] theorem linear_toAffineMap (e : P₁ ≃ᵃ[k] P₂) : e.toAffineMap.linear = e.linear := rfl theorem toAffineMap_injective : Injective (toAffineMap : (P₁ ≃ᵃ[k] P₂) → P₁ →ᵃ[k] P₂) := by rintro ⟨e, el, h⟩ ⟨e', el', h'⟩ H simp_all @[simp] theorem toAffineMap_inj {e e' : P₁ ≃ᵃ[k] P₂} : e.toAffineMap = e'.toAffineMap ↔ e = e' := toAffineMap_injective.eq_iff instance equivLike : EquivLike (P₁ ≃ᵃ[k] P₂) P₁ P₂ where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' _ _ h _ := toAffineMap_injective (DFunLike.coe_injective h) instance : CoeOut (P₁ ≃ᵃ[k] P₂) (P₁ ≃ P₂) := ⟨AffineEquiv.toEquiv⟩ @[simp] theorem map_vadd (e : P₁ ≃ᵃ[k] P₂) (p : P₁) (v : V₁) : e (v +ᵥ p) = e.linear v +ᵥ e p := e.map_vadd' p v @[simp] theorem coe_toEquiv (e : P₁ ≃ᵃ[k] P₂) : ⇑e.toEquiv = e := rfl instance : Coe (P₁ ≃ᵃ[k] P₂) (P₁ →ᵃ[k] P₂) := ⟨toAffineMap⟩ @[simp] theorem coe_toAffineMap (e : P₁ ≃ᵃ[k] P₂) : (e.toAffineMap : P₁ → P₂) = (e : P₁ → P₂) := rfl @[norm_cast, simp] theorem coe_coe (e : P₁ ≃ᵃ[k] P₂) : ((e : P₁ →ᵃ[k] P₂) : P₁ → P₂) = e := rfl @[simp] theorem coe_linear (e : P₁ ≃ᵃ[k] P₂) : (e : P₁ →ᵃ[k] P₂).linear = e.linear := rfl @[ext] theorem ext {e e' : P₁ ≃ᵃ[k] P₂} (h : ∀ x, e x = e' x) : e = e' := DFunLike.ext _ _ h theorem coeFn_injective : @Injective (P₁ ≃ᵃ[k] P₂) (P₁ → P₂) (⇑) := DFunLike.coe_injective @[norm_cast] theorem coeFn_inj {e e' : P₁ ≃ᵃ[k] P₂} : (e : P₁ → P₂) = e' ↔ e = e' := by simp theorem toEquiv_injective : Injective (toEquiv : (P₁ ≃ᵃ[k] P₂) → P₁ ≃ P₂) := fun _ _ H => ext <| Equiv.ext_iff.1 H @[simp] theorem toEquiv_inj {e e' : P₁ ≃ᵃ[k] P₂} : e.toEquiv = e'.toEquiv ↔ e = e' := toEquiv_injective.eq_iff @[simp] theorem coe_mk (e : P₁ ≃ P₂) (e' : V₁ ≃ₗ[k] V₂) (h) : ((⟨e, e', h⟩ : P₁ ≃ᵃ[k] P₂) : P₁ → P₂) = e := rfl /-- Construct an affine equivalence by verifying the relation between the map and its linear part at one base point. Namely, this function takes a map `e : P₁ → P₂`, a linear equivalence `e' : V₁ ≃ₗ[k] V₂`, and a point `p` such that for any other point `p'` we have `e p' = e' (p' -ᵥ p) +ᵥ e p`. -/ def mk' (e : P₁ → P₂) (e' : V₁ ≃ₗ[k] V₂) (p : P₁) (h : ∀ p' : P₁, e p' = e' (p' -ᵥ p) +ᵥ e p) : P₁ ≃ᵃ[k] P₂ where toFun := e invFun := fun q' : P₂ => e'.symm (q' -ᵥ e p) +ᵥ p left_inv p' := by simp [h p', vadd_vsub, vsub_vadd] right_inv q' := by simp [h (e'.symm (q' -ᵥ e p) +ᵥ p), vadd_vsub, vsub_vadd] linear := e' map_vadd' p' v := by simp [h p', h (v +ᵥ p'), vadd_vsub_assoc, vadd_vadd] @[simp] theorem coe_mk' (e : P₁ ≃ P₂) (e' : V₁ ≃ₗ[k] V₂) (p h) : ⇑(mk' e e' p h) = e := rfl @[simp] theorem linear_mk' (e : P₁ ≃ P₂) (e' : V₁ ≃ₗ[k] V₂) (p h) : (mk' e e' p h).linear = e' := rfl /-- Inverse of an affine equivalence as an affine equivalence. -/ @[symm] def symm (e : P₁ ≃ᵃ[k] P₂) : P₂ ≃ᵃ[k] P₁ where toEquiv := e.toEquiv.symm linear := e.linear.symm map_vadd' p v := e.toEquiv.symm.apply_eq_iff_eq_symm_apply.2 <| by rw [Equiv.symm_symm, e.map_vadd' ((Equiv.symm e.toEquiv) p) ((LinearEquiv.symm e.linear) v), LinearEquiv.apply_symm_apply, Equiv.apply_symm_apply] @[simp] theorem toEquiv_symm (e : P₁ ≃ᵃ[k] P₂) : e.symm.toEquiv = e.toEquiv.symm := rfl @[deprecated "use instead `toEquiv_symm`, in the reverse direction" (since := "2025-06-08")] theorem symm_toEquiv (e : P₁ ≃ᵃ[k] P₂) : e.toEquiv.symm = e.symm.toEquiv := rfl @[simp] theorem coe_symm_toEquiv (e : P₁ ≃ᵃ[k] P₂) : ⇑e.toEquiv.symm = e.symm := rfl @[simp] theorem linear_symm (e : P₁ ≃ᵃ[k] P₂) : e.symm.linear = e.linear.symm := rfl @[deprecated "use instead `linear_symm`, in the reverse direction" (since := "2025-06-08")] theorem symm_linear (e : P₁ ≃ᵃ[k] P₂) : e.linear.symm = e.symm.linear := rfl /-- See Note [custom simps projection] -/ def Simps.apply (e : P₁ ≃ᵃ[k] P₂) : P₁ → P₂ := e /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : P₁ ≃ᵃ[k] P₂) : P₂ → P₁ := e.symm initialize_simps_projections AffineEquiv (toEquiv_toFun → apply, toEquiv_invFun → symm_apply, linear → linear, as_prefix linear, -toEquiv) protected theorem bijective (e : P₁ ≃ᵃ[k] P₂) : Bijective e := e.toEquiv.bijective protected theorem surjective (e : P₁ ≃ᵃ[k] P₂) : Surjective e := e.toEquiv.surjective protected theorem injective (e : P₁ ≃ᵃ[k] P₂) : Injective e := e.toEquiv.injective /-- Bijective affine maps are affine isomorphisms. -/ @[simps! linear apply] noncomputable def ofBijective {φ : P₁ →ᵃ[k] P₂} (hφ : Function.Bijective φ) : P₁ ≃ᵃ[k] P₂ := { Equiv.ofBijective _ hφ with linear := LinearEquiv.ofBijective φ.linear (φ.linear_bijective_iff.mpr hφ) map_vadd' := φ.map_vadd } theorem ofBijective.symm_eq {φ : P₁ →ᵃ[k] P₂} (hφ : Function.Bijective φ) : (ofBijective hφ).symm.toEquiv = (Equiv.ofBijective _ hφ).symm := rfl theorem range_eq (e : P₁ ≃ᵃ[k] P₂) : range e = univ := by simp @[simp] theorem apply_symm_apply (e : P₁ ≃ᵃ[k] P₂) (p : P₂) : e (e.symm p) = p := e.toEquiv.apply_symm_apply p @[simp] theorem symm_apply_apply (e : P₁ ≃ᵃ[k] P₂) (p : P₁) : e.symm (e p) = p := e.toEquiv.symm_apply_apply p theorem apply_eq_iff_eq_symm_apply (e : P₁ ≃ᵃ[k] P₂) {p₁ p₂} : e p₁ = p₂ ↔ p₁ = e.symm p₂ := e.toEquiv.apply_eq_iff_eq_symm_apply theorem apply_eq_iff_eq (e : P₁ ≃ᵃ[k] P₂) {p₁ p₂ : P₁} : e p₁ = e p₂ ↔ p₁ = p₂ := by simp @[simp] theorem image_symm (f : P₁ ≃ᵃ[k] P₂) (s : Set P₂) : f.symm '' s = f ⁻¹' s := f.symm.toEquiv.image_eq_preimage_symm _ @[simp] theorem preimage_symm (f : P₁ ≃ᵃ[k] P₂) (s : Set P₁) : f.symm ⁻¹' s = f '' s := (f.symm.image_symm _).symm variable (k P₁) /-- Identity map as an `AffineEquiv`. -/ @[refl] def refl : P₁ ≃ᵃ[k] P₁ where toEquiv := Equiv.refl P₁ linear := LinearEquiv.refl k V₁ map_vadd' _ _ := rfl @[simp] theorem coe_refl : ⇑(refl k P₁) = id := rfl @[simp] theorem coe_refl_to_affineMap : ↑(refl k P₁) = AffineMap.id k P₁ := rfl @[simp] theorem refl_apply (x : P₁) : refl k P₁ x = x := rfl @[simp] theorem toEquiv_refl : (refl k P₁).toEquiv = Equiv.refl P₁ := rfl @[simp] theorem linear_refl : (refl k P₁).linear = LinearEquiv.refl k V₁ := rfl @[simp] theorem symm_refl : (refl k P₁).symm = refl k P₁ := rfl variable {k P₁} /-- Composition of two `AffineEquiv`alences, applied left to right. -/ @[trans] def trans (e : P₁ ≃ᵃ[k] P₂) (e' : P₂ ≃ᵃ[k] P₃) : P₁ ≃ᵃ[k] P₃ where toEquiv := e.toEquiv.trans e'.toEquiv linear := e.linear.trans e'.linear map_vadd' p v := by simp only [LinearEquiv.trans_apply, coe_toEquiv, (· ∘ ·), Equiv.coe_trans, map_vadd] @[simp] theorem coe_trans (e : P₁ ≃ᵃ[k] P₂) (e' : P₂ ≃ᵃ[k] P₃) : ⇑(e.trans e') = e' ∘ e := rfl @[simp] theorem coe_trans_to_affineMap (e : P₁ ≃ᵃ[k] P₂) (e' : P₂ ≃ᵃ[k] P₃) : (e.trans e' : P₁ →ᵃ[k] P₃) = (e' : P₂ →ᵃ[k] P₃).comp e := rfl @[simp] theorem trans_apply (e : P₁ ≃ᵃ[k] P₂) (e' : P₂ ≃ᵃ[k] P₃) (p : P₁) : e.trans e' p = e' (e p) := rfl theorem trans_assoc (e₁ : P₁ ≃ᵃ[k] P₂) (e₂ : P₂ ≃ᵃ[k] P₃) (e₃ : P₃ ≃ᵃ[k] P₄) : (e₁.trans e₂).trans e₃ = e₁.trans (e₂.trans e₃) := ext fun _ => rfl @[simp] theorem trans_refl (e : P₁ ≃ᵃ[k] P₂) : e.trans (refl k P₂) = e := ext fun _ => rfl @[simp] theorem refl_trans (e : P₁ ≃ᵃ[k] P₂) : (refl k P₁).trans e = e := ext fun _ => rfl @[simp] theorem self_trans_symm (e : P₁ ≃ᵃ[k] P₂) : e.trans e.symm = refl k P₁ := ext e.symm_apply_apply @[simp] theorem symm_trans_self (e : P₁ ≃ᵃ[k] P₂) : e.symm.trans e = refl k P₂ := ext e.apply_symm_apply @[simp] theorem apply_lineMap (e : P₁ ≃ᵃ[k] P₂) (a b : P₁) (c : k) : e (AffineMap.lineMap a b c) = AffineMap.lineMap (e a) (e b) c := e.toAffineMap.apply_lineMap a b c instance group : Group (P₁ ≃ᵃ[k] P₁) where one := refl k P₁ mul e e' := e'.trans e inv := symm mul_assoc _ _ _ := trans_assoc _ _ _ one_mul := trans_refl mul_one := refl_trans inv_mul_cancel := self_trans_symm theorem one_def : (1 : P₁ ≃ᵃ[k] P₁) = refl k P₁ := rfl @[simp] theorem coe_one : ⇑(1 : P₁ ≃ᵃ[k] P₁) = id := rfl theorem mul_def (e e' : P₁ ≃ᵃ[k] P₁) : e * e' = e'.trans e := rfl @[simp] theorem coe_mul (e e' : P₁ ≃ᵃ[k] P₁) : ⇑(e * e') = e ∘ e' := rfl theorem inv_def (e : P₁ ≃ᵃ[k] P₁) : e⁻¹ = e.symm := rfl /-- `AffineEquiv.linear` on automorphisms is a `MonoidHom`. -/ @[simps] def linearHom : (P₁ ≃ᵃ[k] P₁) →* V₁ ≃ₗ[k] V₁ where toFun := linear map_one' := rfl map_mul' _ _ := rfl /-- The group of `AffineEquiv`s are equivalent to the group of units of `AffineMap`. This is the affine version of `LinearMap.GeneralLinearGroup.generalLinearEquiv`. -/ @[simps] def equivUnitsAffineMap : (P₁ ≃ᵃ[k] P₁) ≃* (P₁ →ᵃ[k] P₁)ˣ where toFun e := { val := e, inv := e.symm, val_inv := congr_arg toAffineMap e.symm_trans_self inv_val := congr_arg toAffineMap e.self_trans_symm } invFun u := { toFun := (u : P₁ →ᵃ[k] P₁) invFun := (↑u⁻¹ : P₁ →ᵃ[k] P₁) left_inv := AffineMap.congr_fun u.inv_mul right_inv := AffineMap.congr_fun u.mul_inv linear := LinearMap.GeneralLinearGroup.generalLinearEquiv _ _ <| Units.map AffineMap.linearHom u map_vadd' := fun _ _ => (u : P₁ →ᵃ[k] P₁).map_vadd _ _ } map_mul' _ _ := rfl section variable (e₁ : P₁ ≃ᵃ[k] P₂) (e₂ : P₃ ≃ᵃ[k] P₄) /-- Product of two affine equivalences. The map comes from `Equiv.prodCongr` -/ @[simps linear] def prodCongr : P₁ × P₃ ≃ᵃ[k] P₂ × P₄ where __ := Equiv.prodCongr e₁ e₂ linear := e₁.linear.prodCongr e₂.linear map_vadd' := by simp @[simp] theorem prodCongr_symm : (e₁.prodCongr e₂).symm = e₁.symm.prodCongr e₂.symm := rfl @[simp] theorem prodCongr_apply (p : P₁ × P₃) : e₁.prodCongr e₂ p = (e₁ p.1, e₂ p.2) := rfl @[simp, norm_cast] theorem coe_prodCongr : (e₁.prodCongr e₂ : P₁ × P₃ →ᵃ[k] P₂ × P₄) = (e₁ : P₁ →ᵃ[k] P₂).prodMap (e₂ : P₃ →ᵃ[k] P₄) := rfl end section variable (k P₁ P₂ P₃) /-- Product of affine spaces is commutative up to affine isomorphism. -/ @[simps! apply linear] def prodComm : P₁ × P₂ ≃ᵃ[k] P₂ × P₁ where __ := Equiv.prodComm P₁ P₂ linear := LinearEquiv.prodComm k V₁ V₂ map_vadd' := by simp @[simp] theorem prodComm_symm : (prodComm k P₁ P₂).symm = prodComm k P₂ P₁ := rfl /-- Product of affine spaces is associative up to affine isomorphism. -/ @[simps! apply symm_apply linear] def prodAssoc : (P₁ × P₂) × P₃ ≃ᵃ[k] P₁ × (P₂ × P₃) where __ := Equiv.prodAssoc P₁ P₂ P₃ linear := LinearEquiv.prodAssoc k V₁ V₂ V₃ map_vadd' := by simp end variable (k) /-- The map `v ↦ v +ᵥ b` as an affine equivalence between a module `V` and an affine space `P` with tangent space `V`. -/ @[simps! linear apply symm_apply] def vaddConst (b : P₁) : V₁ ≃ᵃ[k] P₁ where toEquiv := Equiv.vaddConst b linear := LinearEquiv.refl _ _ map_vadd' _ _ := add_vadd _ _ _ /-- `p' ↦ p -ᵥ p'` as an equivalence. -/ def constVSub (p : P₁) : P₁ ≃ᵃ[k] V₁ where toEquiv := Equiv.constVSub p linear := LinearEquiv.neg k map_vadd' p' v := by simp [vsub_vadd_eq_vsub_sub, neg_add_eq_sub] @[simp] theorem coe_constVSub (p : P₁) : ⇑(constVSub k p) = (p -ᵥ ·) := rfl @[simp] theorem coe_constVSub_symm (p : P₁) : ⇑(constVSub k p).symm = fun v : V₁ => -v +ᵥ p := rfl variable (P₁) /-- The map `p ↦ v +ᵥ p` as an affine automorphism of an affine space. Note that there is no need for an `AffineMap.constVAdd` as it is always an equivalence. This is roughly to `DistribMulAction.toLinearEquiv` as `+ᵥ` is to `•`. -/ @[simps! apply linear] def constVAdd (v : V₁) : P₁ ≃ᵃ[k] P₁ where toEquiv := Equiv.constVAdd P₁ v linear := LinearEquiv.refl _ _ map_vadd' _ _ := vadd_comm _ _ _ @[simp] theorem constVAdd_zero : constVAdd k P₁ 0 = AffineEquiv.refl _ _ := ext <| zero_vadd _ @[simp] theorem constVAdd_add (v w : V₁) : constVAdd k P₁ (v + w) = (constVAdd k P₁ w).trans (constVAdd k P₁ v) := ext <| add_vadd _ _ @[simp] theorem constVAdd_symm (v : V₁) : (constVAdd k P₁ v).symm = constVAdd k P₁ (-v) := ext fun _ => rfl /-- A more bundled version of `AffineEquiv.constVAdd`. -/ @[simps] def constVAddHom : Multiplicative V₁ →* P₁ ≃ᵃ[k] P₁ where toFun v := constVAdd k P₁ v.toAdd map_one' := constVAdd_zero _ _ map_mul' := constVAdd_add _ P₁ theorem constVAdd_nsmul (n : ℕ) (v : V₁) : constVAdd k P₁ (n • v) = constVAdd k P₁ v ^ n := (constVAddHom k P₁).map_pow _ _ theorem constVAdd_zsmul (z : ℤ) (v : V₁) : constVAdd k P₁ (z • v) = constVAdd k P₁ v ^ z := (constVAddHom k P₁).map_zpow _ _ section Homothety variable {R V P : Type*} [CommRing R] [AddCommGroup V] [Module R V] [AffineSpace V P] /-- Fixing a point in affine space, homothety about this point gives a group homomorphism from (the centre of) the units of the scalars into the group of affine equivalences. -/ def homothetyUnitsMulHom (p : P) : Rˣ →* P ≃ᵃ[R] P := equivUnitsAffineMap.symm.toMonoidHom.comp <| Units.map (AffineMap.homothetyHom p) @[simp] theorem coe_homothetyUnitsMulHom_apply (p : P) (t : Rˣ) : (homothetyUnitsMulHom p t : P → P) = AffineMap.homothety p (t : R) := rfl @[simp] theorem coe_homothetyUnitsMulHom_apply_symm (p : P) (t : Rˣ) : ((homothetyUnitsMulHom p t).symm : P → P) = AffineMap.homothety p (↑t⁻¹ : R) := rfl @[simp] theorem coe_homothetyUnitsMulHom_eq_homothetyHom_coe (p : P) : ((↑) : (P ≃ᵃ[R] P) → P →ᵃ[R] P) ∘ homothetyUnitsMulHom p = AffineMap.homothetyHom p ∘ ((↑) : Rˣ → R) := funext fun _ => rfl end Homothety variable {P₁} open Function /-- Point reflection in `x` as a permutation. -/ def pointReflection (x : P₁) : P₁ ≃ᵃ[k] P₁ := (constVSub k x).trans (vaddConst k x) @[simp] lemma pointReflection_apply_eq_equivPointReflection_apply (x y : P₁) : pointReflection k x y = Equiv.pointReflection x y := rfl theorem pointReflection_apply (x y : P₁) : pointReflection k x y = (x -ᵥ y) +ᵥ x := rfl @[simp] theorem pointReflection_symm (x : P₁) : (pointReflection k x).symm = pointReflection k x := toEquiv_injective <| Equiv.pointReflection_symm x @[simp] theorem toEquiv_pointReflection (x : P₁) : (pointReflection k x).toEquiv = Equiv.pointReflection x := rfl theorem pointReflection_self (x : P₁) : pointReflection k x x = x := vsub_vadd _ _ theorem pointReflection_involutive (x : P₁) : Involutive (pointReflection k x : P₁ → P₁) := Equiv.pointReflection_involutive x /-- `x` is the only fixed point of `pointReflection x`. This lemma requires `x + x = y + y ↔ x = y`. There is no typeclass to use here, so we add it as an explicit argument. -/ theorem pointReflection_fixed_iff_of_injective_two_nsmul {x y : P₁} (h : Injective (2 • · : V₁ → V₁)) : pointReflection k x y = y ↔ y = x := Equiv.pointReflection_fixed_iff_of_injective_two_nsmul h theorem injective_pointReflection_left_of_injective_two_nsmul (h : Injective (2 • · : V₁ → V₁)) (y : P₁) : Injective fun x : P₁ => pointReflection k x y := Equiv.injective_pointReflection_left_of_injective_two_nsmul h y theorem injective_pointReflection_left_of_module [Invertible (2 : k)] : ∀ y, Injective fun x : P₁ => pointReflection k x y := injective_pointReflection_left_of_injective_two_nsmul k fun x y h => by dsimp at h rwa [two_nsmul, two_nsmul, ← two_smul k x, ← two_smul k y, (isUnit_of_invertible (2 : k)).smul_left_cancel] at h theorem pointReflection_fixed_iff_of_module [Invertible (2 : k)] {x y : P₁} : pointReflection k x y = y ↔ y = x := ((injective_pointReflection_left_of_module k y).eq_iff' (pointReflection_self k y)).trans eq_comm end AffineEquiv namespace LinearEquiv /-- Interpret a linear equivalence between modules as an affine equivalence. -/ def toAffineEquiv (e : V₁ ≃ₗ[k] V₂) : V₁ ≃ᵃ[k] V₂ where toEquiv := e.toEquiv linear := e map_vadd' p v := e.map_add v p @[simp] theorem coe_toAffineEquiv (e : V₁ ≃ₗ[k] V₂) : ⇑e.toAffineEquiv = e := rfl end LinearEquiv namespace AffineEquiv section ofLinearEquiv variable {k V P : Type*} variable [Ring k] [AddCommGroup V] [Module k V] [AddTorsor V P] /-- Construct an affine equivalence from a linear equivalence and two base points. Given a linear equivalence `A : V ≃ₗ[k] V` and base points `p₀ p₁ : P`, this constructs the affine equivalence `T x = A (x -ᵥ p₀) +ᵥ p₁`. This is the standard way to convert a linear automorphism into an affine automorphism with specified base point mapping. -/ def ofLinearEquiv (A : V ≃ₗ[k] V) (p₀ p₁ : P) : P ≃ᵃ[k] P := (vaddConst k p₀).symm.trans (A.toAffineEquiv.trans (vaddConst k p₁)) @[simp] theorem ofLinearEquiv_apply (A : V ≃ₗ[k] V) (p₀ p₁ : P) (x : P) : ofLinearEquiv A p₀ p₁ x = A (x -ᵥ p₀) +ᵥ p₁ := rfl @[simp] theorem linear_ofLinearEquiv (A : V ≃ₗ[k] V) (p₀ p₁ : P) : (ofLinearEquiv A p₀ p₁).linear = A := rfl @[simp] theorem ofLinearEquiv_refl (p : P) : ofLinearEquiv (.refl k V) p p = .refl k P := by ext x simp [ofLinearEquiv_apply] @[simp] theorem ofLinearEquiv_trans_ofLinearEquiv (A B : V ≃ₗ[k] V) (p₀ p₁ p₂ : P) : (ofLinearEquiv A p₀ p₁).trans (ofLinearEquiv B p₁ p₂) = ofLinearEquiv (A.trans B) p₀ p₂ := by ext x simp end ofLinearEquiv end AffineEquiv namespace AffineMap open AffineEquiv theorem lineMap_vadd (v v' : V₁) (p : P₁) (c : k) : lineMap v v' c +ᵥ p = lineMap (v +ᵥ p) (v' +ᵥ p) c := (vaddConst k p).apply_lineMap v v' c theorem lineMap_vsub (p₁ p₂ p₃ : P₁) (c : k) : lineMap p₁ p₂ c -ᵥ p₃ = lineMap (p₁ -ᵥ p₃) (p₂ -ᵥ p₃) c := (vaddConst k p₃).symm.apply_lineMap p₁ p₂ c theorem vsub_lineMap (p₁ p₂ p₃ : P₁) (c : k) : p₁ -ᵥ lineMap p₂ p₃ c = lineMap (p₁ -ᵥ p₂) (p₁ -ᵥ p₃) c := (constVSub k p₁).apply_lineMap p₂ p₃ c theorem vadd_lineMap (v : V₁) (p₁ p₂ : P₁) (c : k) : v +ᵥ lineMap p₁ p₂ c = lineMap (v +ᵥ p₁) (v +ᵥ p₂) c := (constVAdd k P₁ v).apply_lineMap p₁ p₂ c variable {R' : Type*} [CommRing R'] [Module R' V₁] theorem homothety_neg_one_apply (c p : P₁) : homothety c (-1 : R') p = pointReflection R' c p := by simp [homothety_apply, Equiv.pointReflection_apply] end AffineMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/AffineSubspace/Basic.lean
import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Defs /-! # Affine spaces This file gives further properties of affine subspaces (over modules) and the affine span of a set of points. ## Main definitions * `AffineSubspace.Parallel`, notation `∥`, gives the property of two affine subspaces being parallel (one being a translate of the other). -/ noncomputable section open Affine open Set open scoped Pointwise section variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] @[simp] lemma vectorSpan_vadd (s : Set P) (v : V) : vectorSpan k (v +ᵥ s) = vectorSpan k s := by simp [vectorSpan] end namespace AffineSubspace variable (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] variable {k P} /-- Given a point in an affine subspace, a result of subtracting that point on the right is in the direction if and only if the other point is in the subspace. -/ theorem vsub_right_mem_direction_iff_mem {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (p₂ : P) : p₂ -ᵥ p ∈ s.direction ↔ p₂ ∈ s := by rw [mem_direction_iff_eq_vsub_right hp] simp /-- Given a point in an affine subspace, a result of subtracting that point on the left is in the direction if and only if the other point is in the subspace. -/ theorem vsub_left_mem_direction_iff_mem {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (p₂ : P) : p -ᵥ p₂ ∈ s.direction ↔ p₂ ∈ s := by rw [mem_direction_iff_eq_vsub_left hp] simp instance toAddTorsor (s : AffineSubspace k P) [Nonempty s] : AddTorsor s.direction s where vadd a b := ⟨(a : V) +ᵥ (b : P), vadd_mem_of_mem_direction a.2 b.2⟩ zero_vadd := fun a => by ext exact zero_vadd _ _ add_vadd a b c := by ext apply add_vadd vsub a b := ⟨(a : P) -ᵥ (b : P), (vsub_left_mem_direction_iff_mem a.2 _).mpr b.2⟩ vsub_vadd' a b := by ext apply AddTorsor.vsub_vadd' vadd_vsub' a b := by ext apply AddTorsor.vadd_vsub' @[simp, norm_cast] theorem coe_vsub (s : AffineSubspace k P) [Nonempty s] (a b : s) : ↑(a -ᵥ b) = (a : P) -ᵥ (b : P) := rfl @[simp, norm_cast] theorem coe_vadd (s : AffineSubspace k P) [Nonempty s] (a : s.direction) (b : s) : ↑(a +ᵥ b) = (a : V) +ᵥ (b : P) := rfl /-- Embedding of an affine subspace to the ambient space, as an affine map. -/ protected def subtype (s : AffineSubspace k P) [Nonempty s] : s →ᵃ[k] P where toFun := (↑) linear := s.direction.subtype map_vadd' _ _ := rfl @[simp] theorem subtype_linear (s : AffineSubspace k P) [Nonempty s] : s.subtype.linear = s.direction.subtype := rfl @[simp] theorem subtype_apply {s : AffineSubspace k P} [Nonempty s] (p : s) : s.subtype p = p := rfl theorem subtype_injective (s : AffineSubspace k P) [Nonempty s] : Function.Injective s.subtype := Subtype.coe_injective @[simp] theorem coe_subtype (s : AffineSubspace k P) [Nonempty s] : (s.subtype : s → P) = ((↑) : s → P) := rfl end AffineSubspace theorem AffineMap.lineMap_mem {k V P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AddTorsor V P] {Q : AffineSubspace k P} {p₀ p₁ : P} (c : k) (h₀ : p₀ ∈ Q) (h₁ : p₁ ∈ Q) : AffineMap.lineMap p₀ p₁ c ∈ Q := by rw [AffineMap.lineMap_apply] exact Q.smul_vsub_vadd_mem c h₁ h₀ h₀ namespace AffineSubspace variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [S : AffineSpace V P] variable (k V) {p₁ p₂ : P} /-- The affine span of a single point, coerced to a set, contains just that point. -/ @[simp high] -- This needs to take priority over `coe_affineSpan` theorem coe_affineSpan_singleton (p : P) : (affineSpan k ({p} : Set P) : Set P) = {p} := by ext x rw [mem_coe, ← vsub_right_mem_direction_iff_mem (mem_affineSpan k (Set.mem_singleton p)) _, direction_affineSpan] simp /-- A point is in the affine span of a single point if and only if they are equal. -/ @[simp] theorem mem_affineSpan_singleton : p₁ ∈ affineSpan k ({p₂} : Set P) ↔ p₁ = p₂ := by simp [← mem_coe] instance unique_affineSpan_singleton (p : P) : Unique (affineSpan k {p}) where default := ⟨p, mem_affineSpan _ (Set.mem_singleton _)⟩ uniq := fun x ↦ Subtype.ext ((mem_affineSpan_singleton _ _).1 x.property) @[simp] theorem preimage_coe_affineSpan_singleton (x : P) : ((↑) : affineSpan k ({x} : Set P) → P) ⁻¹' {x} = univ := eq_univ_of_forall fun y => (AffineSubspace.mem_affineSpan_singleton _ _).1 y.2 variable (P) /-- The top affine subspace is linearly equivalent to the affine space. This is the affine version of `Submodule.topEquiv`. -/ @[simps! linear apply symm_apply_coe] def topEquiv : (⊤ : AffineSubspace k P) ≃ᵃ[k] P where toEquiv := Equiv.Set.univ P linear := .ofEq _ _ (direction_top _ _ _) ≪≫ₗ Submodule.topEquiv map_vadd' _ _ := rfl variable {k V P} theorem subsingleton_of_subsingleton_span_eq_top {s : Set P} (h₁ : s.Subsingleton) (h₂ : affineSpan k s = ⊤) : Subsingleton P := by obtain ⟨p, hp⟩ := AffineSubspace.nonempty_of_affineSpan_eq_top k V P h₂ have : s = {p} := Subset.antisymm (fun q hq => h₁ hq hp) (by simp [hp]) rw [this, AffineSubspace.ext_iff, AffineSubspace.coe_affineSpan_singleton, AffineSubspace.top_coe, eq_comm, ← subsingleton_iff_singleton (mem_univ _)] at h₂ exact subsingleton_of_univ_subsingleton h₂ theorem eq_univ_of_subsingleton_span_eq_top {s : Set P} (h₁ : s.Subsingleton) (h₂ : affineSpan k s = ⊤) : s = (univ : Set P) := by obtain ⟨p, hp⟩ := AffineSubspace.nonempty_of_affineSpan_eq_top k V P h₂ have : s = {p} := Subset.antisymm (fun q hq => h₁ hq hp) (by simp [hp]) rw [this, eq_comm, ← subsingleton_iff_singleton (mem_univ p), subsingleton_univ_iff] exact subsingleton_of_subsingleton_span_eq_top h₁ h₂ /-- If one nonempty affine subspace is less than another, the same applies to their directions -/ theorem direction_lt_of_nonempty {s₁ s₂ : AffineSubspace k P} (h : s₁ < s₂) (hn : (s₁ : Set P).Nonempty) : s₁.direction < s₂.direction := by obtain ⟨p, hp⟩ := hn rw [lt_iff_le_and_exists] at h rcases h with ⟨hle, p₂, hp₂, hp₂s₁⟩ rw [SetLike.lt_iff_le_and_exists] use direction_le hle, p₂ -ᵥ p, vsub_mem_direction hp₂ (hle hp) intro hm rw [vsub_right_mem_direction_iff_mem hp p₂] at hm exact hp₂s₁ hm end AffineSubspace section AffineSpace' variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] variable {ι : Type*} open AffineSubspace Set /-- The `vectorSpan` is the span of the pairwise subtractions with a given point on the left. -/ theorem vectorSpan_eq_span_vsub_set_left {s : Set P} {p : P} (hp : p ∈ s) : vectorSpan k s = Submodule.span k ((p -ᵥ ·) '' s) := by rw [vectorSpan_def] refine le_antisymm ?_ (Submodule.span_mono ?_) · rw [Submodule.span_le] rintro v ⟨p₁, hp₁, p₂, hp₂, hv⟩ simp_rw [← vsub_sub_vsub_cancel_left p₁ p₂ p] at hv rw [← hv, SetLike.mem_coe, Submodule.mem_span] exact fun m hm => Submodule.sub_mem _ (hm ⟨p₂, hp₂, rfl⟩) (hm ⟨p₁, hp₁, rfl⟩) · rintro v ⟨p₂, hp₂, hv⟩ exact ⟨p, hp, p₂, hp₂, hv⟩ /-- The `vectorSpan` is the span of the pairwise subtractions with a given point on the right. -/ theorem vectorSpan_eq_span_vsub_set_right {s : Set P} {p : P} (hp : p ∈ s) : vectorSpan k s = Submodule.span k ((· -ᵥ p) '' s) := by rw [vectorSpan_def] refine le_antisymm ?_ (Submodule.span_mono ?_) · rw [Submodule.span_le] rintro v ⟨p₁, hp₁, p₂, hp₂, hv⟩ simp_rw [← vsub_sub_vsub_cancel_right p₁ p₂ p] at hv rw [← hv, SetLike.mem_coe, Submodule.mem_span] exact fun m hm => Submodule.sub_mem _ (hm ⟨p₁, hp₁, rfl⟩) (hm ⟨p₂, hp₂, rfl⟩) · rintro v ⟨p₂, hp₂, hv⟩ exact ⟨p₂, hp₂, p, hp, hv⟩ /-- The `vectorSpan` is the span of the pairwise subtractions with a given point on the left, excluding the subtraction of that point from itself. -/ theorem vectorSpan_eq_span_vsub_set_left_ne {s : Set P} {p : P} (hp : p ∈ s) : vectorSpan k s = Submodule.span k ((p -ᵥ ·) '' (s \ {p})) := by conv_lhs => rw [vectorSpan_eq_span_vsub_set_left k hp, ← Set.insert_eq_of_mem hp, ← Set.insert_diff_singleton, Set.image_insert_eq] simp [Submodule.span_insert_eq_span] /-- The `vectorSpan` is the span of the pairwise subtractions with a given point on the right, excluding the subtraction of that point from itself. -/ theorem vectorSpan_eq_span_vsub_set_right_ne {s : Set P} {p : P} (hp : p ∈ s) : vectorSpan k s = Submodule.span k ((· -ᵥ p) '' (s \ {p})) := by conv_lhs => rw [vectorSpan_eq_span_vsub_set_right k hp, ← Set.insert_eq_of_mem hp, ← Set.insert_diff_singleton, Set.image_insert_eq] simp [Submodule.span_insert_eq_span] /-- The `vectorSpan` is the span of the pairwise subtractions with a given point on the right, excluding the subtraction of that point from itself. -/ theorem vectorSpan_eq_span_vsub_finset_right_ne [DecidableEq P] [DecidableEq V] {s : Finset P} {p : P} (hp : p ∈ s) : vectorSpan k (s : Set P) = Submodule.span k ((s.erase p).image (· -ᵥ p)) := by simp [vectorSpan_eq_span_vsub_set_right_ne _ (Finset.mem_coe.mpr hp)] /-- The `vectorSpan` of the image of a function is the span of the pairwise subtractions with a given point on the left, excluding the subtraction of that point from itself. -/ theorem vectorSpan_image_eq_span_vsub_set_left_ne (p : ι → P) {s : Set ι} {i : ι} (hi : i ∈ s) : vectorSpan k (p '' s) = Submodule.span k ((p i -ᵥ ·) '' (p '' (s \ {i}))) := by conv_lhs => rw [vectorSpan_eq_span_vsub_set_left k (Set.mem_image_of_mem p hi), ← Set.insert_eq_of_mem hi, ← Set.insert_diff_singleton, Set.image_insert_eq, Set.image_insert_eq] simp [Submodule.span_insert_eq_span] /-- The `vectorSpan` of the image of a function is the span of the pairwise subtractions with a given point on the right, excluding the subtraction of that point from itself. -/ theorem vectorSpan_image_eq_span_vsub_set_right_ne (p : ι → P) {s : Set ι} {i : ι} (hi : i ∈ s) : vectorSpan k (p '' s) = Submodule.span k ((· -ᵥ p i) '' (p '' (s \ {i}))) := by conv_lhs => rw [vectorSpan_eq_span_vsub_set_right k (Set.mem_image_of_mem p hi), ← Set.insert_eq_of_mem hi, ← Set.insert_diff_singleton, Set.image_insert_eq, Set.image_insert_eq] simp [Submodule.span_insert_eq_span] /-- The `vectorSpan` of an indexed family is the span of the pairwise subtractions with a given point on the left. -/ theorem vectorSpan_range_eq_span_range_vsub_left (p : ι → P) (i0 : ι) : vectorSpan k (Set.range p) = Submodule.span k (Set.range fun i : ι => p i0 -ᵥ p i) := by rw [vectorSpan_eq_span_vsub_set_left k (Set.mem_range_self i0), ← Set.range_comp] congr /-- The `vectorSpan` of an indexed family is the span of the pairwise subtractions with a given point on the right. -/ theorem vectorSpan_range_eq_span_range_vsub_right (p : ι → P) (i0 : ι) : vectorSpan k (Set.range p) = Submodule.span k (Set.range fun i : ι => p i -ᵥ p i0) := by rw [vectorSpan_eq_span_vsub_set_right k (Set.mem_range_self i0), ← Set.range_comp] congr /-- The `vectorSpan` of an indexed family is the span of the pairwise subtractions with a given point on the left, excluding the subtraction of that point from itself. -/ theorem vectorSpan_range_eq_span_range_vsub_left_ne (p : ι → P) (i₀ : ι) : vectorSpan k (Set.range p) = Submodule.span k (Set.range fun i : { x // x ≠ i₀ } => p i₀ -ᵥ p i) := by rw [← Set.image_univ, vectorSpan_image_eq_span_vsub_set_left_ne k _ (Set.mem_univ i₀)] congr with v simp only [Set.mem_range, Set.mem_image, Set.mem_diff, Set.mem_singleton_iff, Subtype.exists] constructor · rintro ⟨x, ⟨i₁, ⟨⟨_, hi₁⟩, rfl⟩⟩, hv⟩ exact ⟨i₁, hi₁, hv⟩ · exact fun ⟨i₁, hi₁, hv⟩ => ⟨p i₁, ⟨i₁, ⟨Set.mem_univ _, hi₁⟩, rfl⟩, hv⟩ /-- The `vectorSpan` of an indexed family is the span of the pairwise subtractions with a given point on the right, excluding the subtraction of that point from itself. -/ theorem vectorSpan_range_eq_span_range_vsub_right_ne (p : ι → P) (i₀ : ι) : vectorSpan k (Set.range p) = Submodule.span k (Set.range fun i : { x // x ≠ i₀ } => p i -ᵥ p i₀) := by rw [← Set.image_univ, vectorSpan_image_eq_span_vsub_set_right_ne k _ (Set.mem_univ i₀)] congr with v simp only [Set.mem_range, Set.mem_image, Set.mem_diff, Set.mem_singleton_iff, Subtype.exists] constructor · rintro ⟨x, ⟨i₁, ⟨⟨_, hi₁⟩, rfl⟩⟩, hv⟩ exact ⟨i₁, hi₁, hv⟩ · exact fun ⟨i₁, hi₁, hv⟩ => ⟨p i₁, ⟨i₁, ⟨Set.mem_univ _, hi₁⟩, rfl⟩, hv⟩ variable {k} /-- A set, considered as a subset of its spanned affine subspace, spans the whole subspace. -/ @[simp] theorem affineSpan_coe_preimage_eq_top (A : Set P) [Nonempty A] : affineSpan k (((↑) : affineSpan k A → P) ⁻¹' A) = ⊤ := by rw [eq_top_iff] rintro ⟨x, hx⟩ - refine affineSpan_induction' (fun y hy ↦ ?_) (fun c u hu v hv w hw ↦ ?_) hx · exact subset_affineSpan _ _ hy · exact AffineSubspace.smul_vsub_vadd_mem _ _ /-- Suppose a set of vectors spans `V`. Then a point `p`, together with those vectors added to `p`, spans `P`. -/ theorem affineSpan_singleton_union_vadd_eq_top_of_span_eq_top {s : Set V} (p : P) (h : Submodule.span k (Set.range ((↑) : s → V)) = ⊤) : affineSpan k ({p} ∪ (fun v => v +ᵥ p) '' s) = ⊤ := by convert ext_of_direction_eq _ ⟨p, mem_affineSpan k (Set.mem_union_left _ (Set.mem_singleton _)), mem_top k V p⟩ rw [direction_affineSpan, direction_top, vectorSpan_eq_span_vsub_set_right k (Set.mem_union_left _ (Set.mem_singleton _) : p ∈ _), eq_top_iff, ← h] apply Submodule.span_mono rintro v ⟨v', rfl⟩ use (v' : V) +ᵥ p simp variable (k) /-- The `vectorSpan` of two points is the span of their difference. -/ theorem vectorSpan_pair (p₁ p₂ : P) : vectorSpan k ({p₁, p₂} : Set P) = k ∙ p₁ -ᵥ p₂ := by simp_rw [vectorSpan_eq_span_vsub_set_left k (mem_insert p₁ _), image_pair, vsub_self, Submodule.span_insert_zero] /-- The `vectorSpan` of two points is the span of their difference (reversed). -/ theorem vectorSpan_pair_rev (p₁ p₂ : P) : vectorSpan k ({p₁, p₂} : Set P) = k ∙ p₂ -ᵥ p₁ := by rw [pair_comm, vectorSpan_pair] variable {k} /-- A vector lies in the `vectorSpan` of two points if and only if it is a multiple of their difference. -/ theorem mem_vectorSpan_pair {p₁ p₂ : P} {v : V} : v ∈ vectorSpan k ({p₁, p₂} : Set P) ↔ ∃ r : k, r • (p₁ -ᵥ p₂) = v := by rw [vectorSpan_pair, Submodule.mem_span_singleton] /-- A vector lies in the `vectorSpan` of two points if and only if it is a multiple of their difference (reversed). -/ theorem mem_vectorSpan_pair_rev {p₁ p₂ : P} {v : V} : v ∈ vectorSpan k ({p₁, p₂} : Set P) ↔ ∃ r : k, r • (p₂ -ᵥ p₁) = v := by rw [vectorSpan_pair_rev, Submodule.mem_span_singleton] /-- A combination of two points expressed with `lineMap` lies in their affine span. -/ theorem AffineMap.lineMap_mem_affineSpan_pair (r : k) (p₁ p₂ : P) : AffineMap.lineMap p₁ p₂ r ∈ line[k, p₁, p₂] := AffineMap.lineMap_mem _ (left_mem_affineSpan_pair _ _ _) (right_mem_affineSpan_pair _ _ _) /-- A combination of two points expressed with `lineMap` (with the two points reversed) lies in their affine span. -/ theorem AffineMap.lineMap_rev_mem_affineSpan_pair (r : k) (p₁ p₂ : P) : AffineMap.lineMap p₂ p₁ r ∈ line[k, p₁, p₂] := AffineMap.lineMap_mem _ (right_mem_affineSpan_pair _ _ _) (left_mem_affineSpan_pair _ _ _) /-- A multiple of the difference of two points added to the first point lies in their affine span. -/ theorem smul_vsub_vadd_mem_affineSpan_pair (r : k) (p₁ p₂ : P) : r • (p₂ -ᵥ p₁) +ᵥ p₁ ∈ line[k, p₁, p₂] := AffineMap.lineMap_mem_affineSpan_pair _ _ _ /-- A multiple of the difference of two points added to the second point lies in their affine span. -/ theorem smul_vsub_rev_vadd_mem_affineSpan_pair (r : k) (p₁ p₂ : P) : r • (p₁ -ᵥ p₂) +ᵥ p₂ ∈ line[k, p₁, p₂] := AffineMap.lineMap_rev_mem_affineSpan_pair _ _ _ /-- A vector added to the first point lies in the affine span of two points if and only if it is a multiple of their difference. -/ theorem vadd_left_mem_affineSpan_pair {p₁ p₂ : P} {v : V} : v +ᵥ p₁ ∈ line[k, p₁, p₂] ↔ ∃ r : k, r • (p₂ -ᵥ p₁) = v := by rw [vadd_mem_iff_mem_direction _ (left_mem_affineSpan_pair _ _ _), direction_affineSpan, mem_vectorSpan_pair_rev] /-- A vector added to the second point lies in the affine span of two points if and only if it is a multiple of their difference. -/ theorem vadd_right_mem_affineSpan_pair {p₁ p₂ : P} {v : V} : v +ᵥ p₂ ∈ line[k, p₁, p₂] ↔ ∃ r : k, r • (p₁ -ᵥ p₂) = v := by rw [vadd_mem_iff_mem_direction _ (right_mem_affineSpan_pair _ _ _), direction_affineSpan, mem_vectorSpan_pair] end AffineSpace' namespace AffineSubspace variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- The direction of the sup of two nonempty affine subspaces is the sup of the two directions and of any one difference between points in the two subspaces. -/ theorem direction_sup {s₁ s₂ : AffineSubspace k P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s₁) (hp₂ : p₂ ∈ s₂) : (s₁ ⊔ s₂).direction = s₁.direction ⊔ s₂.direction ⊔ k ∙ p₂ -ᵥ p₁ := by refine le_antisymm ?_ ?_ · change (affineSpan k ((s₁ : Set P) ∪ s₂)).direction ≤ _ rw [← mem_coe] at hp₁ rw [direction_affineSpan, vectorSpan_eq_span_vsub_set_right k (Set.mem_union_left _ hp₁), Submodule.span_le] rintro v ⟨p₃, hp₃, rfl⟩ rcases hp₃ with hp₃ | hp₃ · rw [sup_assoc, sup_comm, SetLike.mem_coe, Submodule.mem_sup] use 0, Submodule.zero_mem _, p₃ -ᵥ p₁, vsub_mem_direction hp₃ hp₁ rw [zero_add] · rw [sup_assoc, SetLike.mem_coe, Submodule.mem_sup] use 0, Submodule.zero_mem _, p₃ -ᵥ p₁ rw [and_comm, zero_add] use rfl rw [← vsub_add_vsub_cancel p₃ p₂ p₁, Submodule.mem_sup] use p₃ -ᵥ p₂, vsub_mem_direction hp₃ hp₂, p₂ -ᵥ p₁, Submodule.mem_span_singleton_self _ · refine sup_le (sup_direction_le _ _) ?_ rw [direction_eq_vectorSpan, vectorSpan_def] exact sInf_le_sInf fun p hp => Set.Subset.trans (Set.singleton_subset_iff.2 (vsub_mem_vsub (mem_affineSpan k (Set.mem_union_right _ hp₂)) (mem_affineSpan k (Set.mem_union_left _ hp₁)))) hp /-- The direction of the sup of two affine subspaces with a common point is the sup of the two directions. -/ lemma direction_sup_eq_sup_direction {s₁ s₂ : AffineSubspace k P} {p : P} (hp₁ : p ∈ s₁) (hp₂ : p ∈ s₂) : (s₁ ⊔ s₂).direction = s₁.direction ⊔ s₂.direction := by rw [direction_sup hp₁ hp₂] simp /-- The direction of the span of the result of adding a point to a nonempty affine subspace is the sup of the direction of that subspace and of any one difference between that point and a point in the subspace. -/ theorem direction_affineSpan_insert {s : AffineSubspace k P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) : (affineSpan k (insert p₂ (s : Set P))).direction = Submodule.span k {p₂ -ᵥ p₁} ⊔ s.direction := by rw [sup_comm, ← Set.union_singleton, ← coe_affineSpan_singleton k V p₂] change (s ⊔ affineSpan k {p₂}).direction = _ rw [direction_sup hp₁ (mem_affineSpan k (Set.mem_singleton _)), direction_affineSpan] simp /-- Given a point `p₁` in an affine subspace `s`, and a point `p₂`, a point `p` is in the span of `s` with `p₂` added if and only if it is a multiple of `p₂ -ᵥ p₁` added to a point in `s`. -/ theorem mem_affineSpan_insert_iff {s : AffineSubspace k P} {p₁ : P} (hp₁ : p₁ ∈ s) (p₂ p : P) : p ∈ affineSpan k (insert p₂ (s : Set P)) ↔ ∃ r : k, ∃ p0 ∈ s, p = r • (p₂ -ᵥ p₁ : V) +ᵥ p0 := by rw [← mem_coe] at hp₁ rw [← vsub_right_mem_direction_iff_mem (mem_affineSpan k (Set.mem_insert_of_mem _ hp₁)), direction_affineSpan_insert hp₁, Submodule.mem_sup] constructor · rintro ⟨v₁, hv₁, v₂, hv₂, hp⟩ rw [Submodule.mem_span_singleton] at hv₁ rcases hv₁ with ⟨r, rfl⟩ use r, v₂ +ᵥ p₁, vadd_mem_of_mem_direction hv₂ hp₁ symm at hp rw [← sub_eq_zero, ← vsub_vadd_eq_vsub_sub, vsub_eq_zero_iff_eq] at hp rw [hp, vadd_vadd] · rintro ⟨r, p₃, hp₃, rfl⟩ use r • (p₂ -ᵥ p₁), Submodule.mem_span_singleton.2 ⟨r, rfl⟩, p₃ -ᵥ p₁, vsub_mem_direction hp₃ hp₁ rw [vadd_vsub_assoc] variable (k) in /-- The vector span of a union of sets with a common point is the sup of their vector spans. -/ lemma vectorSpan_union_of_mem_of_mem {s₁ s₂ : Set P} {p : P} (hp₁ : p ∈ s₁) (hp₂ : p ∈ s₂) : vectorSpan k (s₁ ∪ s₂) = vectorSpan k s₁ ⊔ vectorSpan k s₂ := by simp_rw [← direction_affineSpan, span_union, direction_sup_eq_sup_direction (mem_affineSpan k hp₁) (mem_affineSpan k hp₂)] end AffineSubspace section MapComap variable {k V₁ P₁ V₂ P₂ V₃ P₃ : Type*} [Ring k] variable [AddCommGroup V₁] [Module k V₁] [AddTorsor V₁ P₁] variable [AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂] variable [AddCommGroup V₃] [Module k V₃] [AddTorsor V₃ P₃] section variable (f : P₁ →ᵃ[k] P₂) @[simp] theorem AffineMap.vectorSpan_image_eq_submodule_map {s : Set P₁} : Submodule.map f.linear (vectorSpan k s) = vectorSpan k (f '' s) := by simp [vectorSpan_def, f.image_vsub_image] namespace AffineSubspace /-- The image of an affine subspace under an affine map as an affine subspace. -/ def map (s : AffineSubspace k P₁) : AffineSubspace k P₂ where carrier := f '' s smul_vsub_vadd_mem := by rintro t - - - ⟨p₁, h₁, rfl⟩ ⟨p₂, h₂, rfl⟩ ⟨p₃, h₃, rfl⟩ use t • (p₁ -ᵥ p₂) +ᵥ p₃ suffices t • (p₁ -ᵥ p₂) +ᵥ p₃ ∈ s by { simp only [SetLike.mem_coe, true_and, this] rw [AffineMap.map_vadd, map_smul, AffineMap.linearMap_vsub] } exact s.smul_vsub_vadd_mem t h₁ h₂ h₃ @[simp] theorem coe_map (s : AffineSubspace k P₁) : (s.map f : Set P₂) = f '' s := rfl @[simp] theorem mem_map {f : P₁ →ᵃ[k] P₂} {x : P₂} {s : AffineSubspace k P₁} : x ∈ s.map f ↔ ∃ y ∈ s, f y = x := Iff.rfl theorem mem_map_of_mem {x : P₁} {s : AffineSubspace k P₁} (h : x ∈ s) : f x ∈ s.map f := Set.mem_image_of_mem _ h @[simp 1100] theorem mem_map_iff_mem_of_injective {f : P₁ →ᵃ[k] P₂} {x : P₁} {s : AffineSubspace k P₁} (hf : Function.Injective f) : f x ∈ s.map f ↔ x ∈ s := hf.mem_set_image @[simp] theorem map_bot : (⊥ : AffineSubspace k P₁).map f = ⊥ := coe_injective <| image_empty f @[simp] theorem map_eq_bot_iff {s : AffineSubspace k P₁} : s.map f = ⊥ ↔ s = ⊥ := by refine ⟨fun h => ?_, fun h => ?_⟩ · rwa [← coe_eq_bot_iff, coe_map, image_eq_empty, coe_eq_bot_iff] at h · rw [h, map_bot] @[simp] theorem map_id (s : AffineSubspace k P₁) : s.map (AffineMap.id k P₁) = s := coe_injective <| image_id _ theorem map_map (s : AffineSubspace k P₁) (f : P₁ →ᵃ[k] P₂) (g : P₂ →ᵃ[k] P₃) : (s.map f).map g = s.map (g.comp f) := coe_injective <| image_image _ _ _ @[simp] theorem map_direction (s : AffineSubspace k P₁) : (s.map f).direction = s.direction.map f.linear := by simp [direction_eq_vectorSpan, AffineMap.vectorSpan_image_eq_submodule_map] theorem map_span (s : Set P₁) : (affineSpan k s).map f = affineSpan k (f '' s) := by rcases s.eq_empty_or_nonempty with (rfl | ⟨p, hp⟩) · simp apply ext_of_direction_eq · simp [direction_affineSpan] · exact ⟨f p, mem_image_of_mem f (subset_affineSpan k _ hp), subset_affineSpan k _ (mem_image_of_mem f hp)⟩ @[gcongr] theorem map_mono {s₁ s₂ : AffineSubspace k P₁} (h : s₁ ≤ s₂) : s₁.map f ≤ s₂.map f := Set.image_mono h section inclusion variable {S₁ S₂ : AffineSubspace k P₁} [Nonempty S₁] /-- Affine map from a smaller to a larger subspace of the same space. This is the affine version of `Submodule.inclusion`. -/ @[simps linear] def inclusion (h : S₁ ≤ S₂) : letI := Nonempty.map (Set.inclusion h) ‹_› S₁ →ᵃ[k] S₂ := letI := Nonempty.map (Set.inclusion h) ‹_› { toFun := Set.inclusion h linear := Submodule.inclusion <| AffineSubspace.direction_le h map_vadd' := fun ⟨_,_⟩ ⟨_,_⟩ => rfl } @[simp] theorem coe_inclusion_apply (h : S₁ ≤ S₂) (x : S₁) : (inclusion h x : P₁) = x := rfl @[simp] theorem inclusion_rfl : inclusion (le_refl S₁) = AffineMap.id k S₁ := rfl end inclusion end AffineSubspace namespace AffineMap @[simp] theorem map_top_of_surjective (hf : Function.Surjective f) : AffineSubspace.map f ⊤ = ⊤ := by rw [AffineSubspace.ext_iff] exact image_univ_of_surjective hf theorem span_eq_top_of_surjective {s : Set P₁} (hf : Function.Surjective f) (h : affineSpan k s = ⊤) : affineSpan k (f '' s) = ⊤ := by rw [← AffineSubspace.map_span, h, map_top_of_surjective f hf] /-- If two affine maps agree on a set, their linear parts agree on the vector span of that set. -/ theorem linear_eqOn_vectorSpan {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂] {s : Set P₁} {f g : P₁ →ᵃ[k] P₂} (h_agree : s.EqOn f g) : Set.EqOn f.linear g.linear (vectorSpan k s) := by simp only [vectorSpan_def] apply LinearMap.eqOn_span rintro - ⟨x, hx, y, hy, rfl⟩ simp [h_agree hx, h_agree hy] /-- Two affine maps which agree on a set, agree on its affine span. -/ theorem eqOn_affineSpan {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂] {s : Set P₁} {f g : P₁ →ᵃ[k] P₂} (h_agree : s.EqOn f g) : Set.EqOn f g (affineSpan k s) := by rcases s.eq_empty_or_nonempty with rfl | ⟨q, hq⟩; · simp rintro - ⟨x, hx, y, hy, rfl⟩ simp [h_agree hx, linear_eqOn_vectorSpan h_agree hy] /-- If two affine maps agree on a set that spans the entire space, then they are equal. -/ theorem ext_on {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂] {s : Set P₁} {f g : P₁ →ᵃ[k] P₂} (h_span : affineSpan k s = ⊤) (h_agree : s.EqOn f g) : f = g := by simpa [h_span] using eqOn_affineSpan h_agree end AffineMap namespace AffineEquiv /-- If two affine equivalences agree on a set that spans the entire space, then they are equal. -/ theorem ext_on {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂] {s : Set P₁} (h_span : affineSpan k s = ⊤) (T₁ T₂ : P₁ ≃ᵃ[k] P₂) (h_agree : s.EqOn T₁ T₂) : T₁ = T₂ := (AffineEquiv.toAffineMap_inj).mp <| AffineMap.ext_on h_span h_agree section ofEq variable (S₁ S₂ : AffineSubspace k P₁) [Nonempty S₁] [Nonempty S₂] /-- Affine equivalence between two equal affine subspace. This is the affine version of `LinearEquiv.ofEq`. -/ @[simps linear] def ofEq (h : S₁ = S₂) : S₁ ≃ᵃ[k] S₂ where toEquiv := Equiv.setCongr <| congr_arg _ h linear := .ofEq _ _ <| congr_arg _ h map_vadd' := fun ⟨_,_⟩ ⟨_,_⟩ => rfl @[simp] theorem coe_ofEq_apply (h : S₁ = S₂) (x : S₁) : (ofEq S₁ S₂ h x : P₁) = x := rfl @[simp] theorem ofEq_symm (h : S₁ = S₂) : (ofEq S₁ S₂ h).symm = ofEq S₂ S₁ h.symm := by ext rfl @[simp] theorem ofEq_rfl : ofEq S₁ S₁ rfl = AffineEquiv.refl k S₁ := rfl end ofEq theorem span_eq_top_iff {s : Set P₁} (e : P₁ ≃ᵃ[k] P₂) : affineSpan k s = ⊤ ↔ affineSpan k (e '' s) = ⊤ := by refine ⟨(e : P₁ →ᵃ[k] P₂).span_eq_top_of_surjective e.surjective, ?_⟩ intro h have : s = e.symm '' (e '' s) := by rw [← image_comp]; simp rw [this] exact (e.symm : P₂ →ᵃ[k] P₁).span_eq_top_of_surjective e.symm.surjective h end AffineEquiv end namespace AffineSubspace /-- The preimage of an affine subspace under an affine map as an affine subspace. -/ def comap (f : P₁ →ᵃ[k] P₂) (s : AffineSubspace k P₂) : AffineSubspace k P₁ where carrier := f ⁻¹' s smul_vsub_vadd_mem t p₁ p₂ p₃ (hp₁ : f p₁ ∈ s) (hp₂ : f p₂ ∈ s) (hp₃ : f p₃ ∈ s) := show f _ ∈ s by rw [AffineMap.map_vadd, LinearMap.map_smul, AffineMap.linearMap_vsub] apply s.smul_vsub_vadd_mem _ hp₁ hp₂ hp₃ @[simp] theorem coe_comap (f : P₁ →ᵃ[k] P₂) (s : AffineSubspace k P₂) : (s.comap f : Set P₁) = f ⁻¹' ↑s := rfl @[simp] theorem mem_comap {f : P₁ →ᵃ[k] P₂} {x : P₁} {s : AffineSubspace k P₂} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl theorem comap_mono {f : P₁ →ᵃ[k] P₂} {s t : AffineSubspace k P₂} : s ≤ t → s.comap f ≤ t.comap f := preimage_mono @[simp] theorem comap_top {f : P₁ →ᵃ[k] P₂} : (⊤ : AffineSubspace k P₂).comap f = ⊤ := by rw [AffineSubspace.ext_iff] exact preimage_univ (f := f) @[simp] theorem comap_bot (f : P₁ →ᵃ[k] P₂) : comap f ⊥ = ⊥ := rfl @[simp] theorem comap_id (s : AffineSubspace k P₁) : s.comap (AffineMap.id k P₁) = s := rfl theorem comap_comap (s : AffineSubspace k P₃) (f : P₁ →ᵃ[k] P₂) (g : P₂ →ᵃ[k] P₃) : (s.comap g).comap f = s.comap (g.comp f) := rfl -- lemmas about map and comap derived from the Galois connection theorem map_le_iff_le_comap {f : P₁ →ᵃ[k] P₂} {s : AffineSubspace k P₁} {t : AffineSubspace k P₂} : s.map f ≤ t ↔ s ≤ t.comap f := image_subset_iff theorem gc_map_comap (f : P₁ →ᵃ[k] P₂) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap theorem map_comap_le (f : P₁ →ᵃ[k] P₂) (s : AffineSubspace k P₂) : (s.comap f).map f ≤ s := (gc_map_comap f).l_u_le _ theorem le_comap_map (f : P₁ →ᵃ[k] P₂) (s : AffineSubspace k P₁) : s ≤ (s.map f).comap f := (gc_map_comap f).le_u_l _ theorem map_sup (s t : AffineSubspace k P₁) (f : P₁ →ᵃ[k] P₂) : (s ⊔ t).map f = s.map f ⊔ t.map f := (gc_map_comap f).l_sup theorem map_iSup {ι : Sort*} (f : P₁ →ᵃ[k] P₂) (s : ι → AffineSubspace k P₁) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup theorem comap_inf (s t : AffineSubspace k P₂) (f : P₁ →ᵃ[k] P₂) : (s ⊓ t).comap f = s.comap f ⊓ t.comap f := (gc_map_comap f).u_inf theorem comap_supr {ι : Sort*} (f : P₁ →ᵃ[k] P₂) (s : ι → AffineSubspace k P₂) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf @[simp] theorem comap_symm (e : P₁ ≃ᵃ[k] P₂) (s : AffineSubspace k P₁) : s.comap (e.symm : P₂ →ᵃ[k] P₁) = s.map e := coe_injective <| e.preimage_symm _ @[simp] theorem map_symm (e : P₁ ≃ᵃ[k] P₂) (s : AffineSubspace k P₂) : s.map (e.symm : P₂ →ᵃ[k] P₁) = s.comap e := coe_injective <| e.image_symm _ theorem comap_span (f : P₁ ≃ᵃ[k] P₂) (s : Set P₂) : (affineSpan k s).comap (f : P₁ →ᵃ[k] P₂) = affineSpan k (f ⁻¹' s) := by rw [← map_symm, map_span, AffineEquiv.coe_coe, f.image_symm] end AffineSubspace end MapComap namespace AffineSubspace open AffineEquiv variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] /-- Two affine subspaces are parallel if one is related to the other by adding the same vector to all points. -/ def Parallel (s₁ s₂ : AffineSubspace k P) : Prop := ∃ v : V, s₂ = s₁.map (constVAdd k P v) @[inherit_doc] scoped[Affine] infixl:50 " ∥ " => AffineSubspace.Parallel @[symm] theorem Parallel.symm {s₁ s₂ : AffineSubspace k P} (h : s₁ ∥ s₂) : s₂ ∥ s₁ := by rcases h with ⟨v, rfl⟩ refine ⟨-v, ?_⟩ rw [map_map, ← coe_trans_to_affineMap, ← constVAdd_add, neg_add_cancel, constVAdd_zero, coe_refl_to_affineMap, map_id] theorem parallel_comm {s₁ s₂ : AffineSubspace k P} : s₁ ∥ s₂ ↔ s₂ ∥ s₁ := ⟨Parallel.symm, Parallel.symm⟩ @[refl] theorem Parallel.refl (s : AffineSubspace k P) : s ∥ s := ⟨0, by simp⟩ @[trans] theorem Parallel.trans {s₁ s₂ s₃ : AffineSubspace k P} (h₁₂ : s₁ ∥ s₂) (h₂₃ : s₂ ∥ s₃) : s₁ ∥ s₃ := by rcases h₁₂ with ⟨v₁₂, rfl⟩ rcases h₂₃ with ⟨v₂₃, rfl⟩ refine ⟨v₂₃ + v₁₂, ?_⟩ rw [map_map, ← coe_trans_to_affineMap, ← constVAdd_add] theorem Parallel.direction_eq {s₁ s₂ : AffineSubspace k P} (h : s₁ ∥ s₂) : s₁.direction = s₂.direction := by rcases h with ⟨v, rfl⟩ simp @[simp] theorem parallel_bot_iff_eq_bot {s : AffineSubspace k P} : s ∥ ⊥ ↔ s = ⊥ := by refine ⟨fun h => ?_, fun h => h ▸ Parallel.refl _⟩ rcases h with ⟨v, h⟩ rwa [eq_comm, map_eq_bot_iff] at h @[simp] theorem bot_parallel_iff_eq_bot {s : AffineSubspace k P} : ⊥ ∥ s ↔ s = ⊥ := by rw [parallel_comm, parallel_bot_iff_eq_bot] theorem parallel_iff_direction_eq_and_eq_bot_iff_eq_bot {s₁ s₂ : AffineSubspace k P} : s₁ ∥ s₂ ↔ s₁.direction = s₂.direction ∧ (s₁ = ⊥ ↔ s₂ = ⊥) := by refine ⟨fun h => ⟨h.direction_eq, ?_, ?_⟩, fun h => ?_⟩ · rintro rfl exact bot_parallel_iff_eq_bot.1 h · rintro rfl exact parallel_bot_iff_eq_bot.1 h · rcases h with ⟨hd, hb⟩ by_cases hs₁ : s₁ = ⊥ · rw [hs₁, bot_parallel_iff_eq_bot] exact hb.1 hs₁ · have hs₂ : s₂ ≠ ⊥ := hb.not.1 hs₁ rcases (nonempty_iff_ne_bot s₁).2 hs₁ with ⟨p₁, hp₁⟩ rcases (nonempty_iff_ne_bot s₂).2 hs₂ with ⟨p₂, hp₂⟩ refine ⟨p₂ -ᵥ p₁, (eq_iff_direction_eq_of_mem hp₂ ?_).2 ?_⟩ · rw [mem_map] refine ⟨p₁, hp₁, ?_⟩ simp · simpa using hd.symm theorem Parallel.vectorSpan_eq {s₁ s₂ : Set P} (h : affineSpan k s₁ ∥ affineSpan k s₂) : vectorSpan k s₁ = vectorSpan k s₂ := by simp_rw [← direction_affineSpan] exact h.direction_eq theorem affineSpan_parallel_iff_vectorSpan_eq_and_eq_empty_iff_eq_empty {s₁ s₂ : Set P} : affineSpan k s₁ ∥ affineSpan k s₂ ↔ vectorSpan k s₁ = vectorSpan k s₂ ∧ (s₁ = ∅ ↔ s₂ = ∅) := by repeat rw [← direction_affineSpan, ← affineSpan_eq_bot k] exact parallel_iff_direction_eq_and_eq_bot_iff_eq_bot theorem affineSpan_pair_parallel_iff_vectorSpan_eq {p₁ p₂ p₃ p₄ : P} : line[k, p₁, p₂] ∥ line[k, p₃, p₄] ↔ vectorSpan k ({p₁, p₂} : Set P) = vectorSpan k ({p₃, p₄} : Set P) := by simp [affineSpan_parallel_iff_vectorSpan_eq_and_eq_empty_iff_eq_empty, ← not_nonempty_iff_eq_empty] end AffineSubspace section DivisionRing variable {k V P : Type*} [DivisionRing k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- The span of two different points that lie in a line through two points equals that line. -/ lemma affineSpan_pair_eq_of_mem_of_mem_of_ne {p₁ p₂ p₃ p₄ : P} (hp₁ : p₁ ∈ line[k, p₃, p₄]) (hp₂ : p₂ ∈ line[k, p₃, p₄]) (hp₁₂ : p₁ ≠ p₂) : line[k, p₁, p₂] = line[k, p₃, p₄] := by refine le_antisymm (affineSpan_pair_le_of_mem_of_mem hp₁ hp₂) ?_ rw [← vsub_vadd p₁ p₃, vadd_left_mem_affineSpan_pair] at hp₁ rcases hp₁ with ⟨r₁, hp₁⟩ rw [← vsub_vadd p₂ p₃, vadd_left_mem_affineSpan_pair] at hp₂ rcases hp₂ with ⟨r₂, hp₂⟩ have hr₀ : r₂ - r₁ ≠ 0 := by rw [sub_ne_zero] rintro rfl simp_all have hr : (r₂ - r₁) • (p₄ -ᵥ p₃) = p₂ -ᵥ p₁ := by simp [sub_smul, hp₁, hp₂] rw [← eq_inv_smul_iff₀ hr₀] at hr refine affineSpan_pair_le_of_mem_of_mem ?_ ?_ · convert smul_vsub_vadd_mem_affineSpan_pair (-r₁ * (r₂ - r₁)⁻¹) p₁ p₂ simp [mul_smul, ← hr, hp₁] · convert smul_vsub_vadd_mem_affineSpan_pair ((1 - r₁) * (r₂ - r₁)⁻¹) p₁ p₂ simp [mul_smul, ← hr, sub_smul, hp₁] /-- One line equals another differing in the first point if the first point of the first line is contained in the second line and does not equal the second point. -/ lemma affineSpan_pair_eq_of_left_mem_of_ne {p₁ p₂ p₃ : P} (h : p₁ ∈ line[k, p₂, p₃]) (hne : p₁ ≠ p₃) : line[k, p₁, p₃] = line[k, p₂, p₃] := affineSpan_pair_eq_of_mem_of_mem_of_ne h (right_mem_affineSpan_pair _ _ _) hne /-- One line equals another differing in the second point if the second point of the first line is contained in the second line and does not equal the first point. -/ lemma affineSpan_pair_eq_of_right_mem_of_ne {p₁ p₂ p₃ : P} (h : p₁ ∈ line[k, p₂, p₃]) (hne : p₁ ≠ p₂) : line[k, p₂, p₁] = line[k, p₂, p₃] := affineSpan_pair_eq_of_mem_of_mem_of_ne (left_mem_affineSpan_pair _ _ _) h hne.symm end DivisionRing
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/AffineSubspace/Defs.lean
import Mathlib.Order.Atoms import Mathlib.LinearAlgebra.Span.Defs import Mathlib.LinearAlgebra.AffineSpace.Defs /-! # Affine spaces This file defines affine subspaces (over modules) and the affine span of a set of points. ## Main definitions * `AffineSubspace k P` is the type of affine subspaces. Unlike affine spaces, affine subspaces are allowed to be empty, and lemmas that do not apply to empty affine subspaces have `Nonempty` hypotheses. There is a `CompleteLattice` structure on affine subspaces. * `AffineSubspace.direction` gives the `Submodule` spanned by the pairwise differences of points in an `AffineSubspace`. There are various lemmas relating to the set of vectors in the `direction`, and relating the lattice structure on affine subspaces to that on their directions. * `affineSpan` gives the affine subspace spanned by a set of points, with `vectorSpan` giving its direction. The `affineSpan` is defined in terms of `spanPoints`, which gives an explicit description of the points contained in the affine span; `spanPoints` itself should generally only be used when that description is required, with `affineSpan` being the main definition for other purposes. Two other descriptions of the affine span are proved equivalent: it is the `sInf` of affine subspaces containing the points, and (if `[Nontrivial k]`) it contains exactly those points that are affine combinations of points in the given set. ## Implementation notes `outParam` is used in the definition of `AddTorsor V P` to make `V` an implicit argument (deduced from `P`) in most cases. As for modules, `k` is an explicit argument rather than implied by `P` or `V`. This file only provides purely algebraic definitions and results. Those depending on analysis or topology are defined elsewhere; see `Analysis.Normed.Affine.AddTorsor` and `Topology.Algebra.Affine`. ## References * https://en.wikipedia.org/wiki/Affine_space * https://en.wikipedia.org/wiki/Principal_homogeneous_space -/ noncomputable section open Affine open Set open scoped Pointwise section variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] /-- The submodule spanning the differences of a (possibly empty) set of points. -/ def vectorSpan (s : Set P) : Submodule k V := Submodule.span k (s -ᵥ s) /-- The definition of `vectorSpan`, for rewriting. -/ theorem vectorSpan_def (s : Set P) : vectorSpan k s = Submodule.span k (s -ᵥ s) := rfl /-- `vectorSpan` is monotone. -/ theorem vectorSpan_mono {s₁ s₂ : Set P} (h : s₁ ⊆ s₂) : vectorSpan k s₁ ≤ vectorSpan k s₂ := Submodule.span_mono (vsub_self_mono h) variable (P) in /-- The `vectorSpan` of the empty set is `⊥`. -/ @[simp] theorem vectorSpan_empty : vectorSpan k (∅ : Set P) = (⊥ : Submodule k V) := by rw [vectorSpan_def, vsub_empty, Submodule.span_empty] /-- The `vectorSpan` of a single point is `⊥`. -/ @[simp] theorem vectorSpan_singleton (p : P) : vectorSpan k ({p} : Set P) = ⊥ := by simp [vectorSpan_def] /-- The `s -ᵥ s` lies within the `vectorSpan k s`. -/ theorem vsub_set_subset_vectorSpan (s : Set P) : s -ᵥ s ⊆ ↑(vectorSpan k s) := Submodule.subset_span /-- Each pairwise difference is in the `vectorSpan`. -/ theorem vsub_mem_vectorSpan {s : Set P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) : p₁ -ᵥ p₂ ∈ vectorSpan k s := vsub_set_subset_vectorSpan k s (vsub_mem_vsub hp₁ hp₂) /-- The points in the affine span of a (possibly empty) set of points. Use `affineSpan` instead to get an `AffineSubspace k P`. -/ def spanPoints (s : Set P) : Set P := { p | ∃ p₁ ∈ s, ∃ v ∈ vectorSpan k s, p = v +ᵥ p₁ } /-- A point in a set is in its affine span. -/ theorem mem_spanPoints (p : P) (s : Set P) : p ∈ s → p ∈ spanPoints k s | hp => ⟨p, hp, 0, Submodule.zero_mem _, (zero_vadd V p).symm⟩ /-- A set is contained in its `spanPoints`. -/ theorem subset_spanPoints (s : Set P) : s ⊆ spanPoints k s := fun p => mem_spanPoints k p s /-- The `spanPoints` of a set is nonempty if and only if that set is. -/ @[simp] theorem spanPoints_nonempty (s : Set P) : (spanPoints k s).Nonempty ↔ s.Nonempty := by constructor · contrapose rw [Set.not_nonempty_iff_eq_empty, Set.not_nonempty_iff_eq_empty] intro h simp [h, spanPoints] · exact fun h => h.mono (subset_spanPoints _ _) /-- Adding a point in the affine span and a vector in the spanning submodule produces a point in the affine span. -/ theorem vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan {s : Set P} {p : P} {v : V} (hp : p ∈ spanPoints k s) (hv : v ∈ vectorSpan k s) : v +ᵥ p ∈ spanPoints k s := by rcases hp with ⟨p₂, ⟨hp₂, ⟨v₂, ⟨hv₂, hv₂p⟩⟩⟩⟩ rw [hv₂p, vadd_vadd] exact ⟨p₂, hp₂, v + v₂, (vectorSpan k s).add_mem hv hv₂, rfl⟩ /-- Subtracting two points in the affine span produces a vector in the spanning submodule. -/ theorem vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints {s : Set P} {p₁ p₂ : P} (hp₁ : p₁ ∈ spanPoints k s) (hp₂ : p₂ ∈ spanPoints k s) : p₁ -ᵥ p₂ ∈ vectorSpan k s := by rcases hp₁ with ⟨p₁a, ⟨hp₁a, ⟨v₁, ⟨hv₁, hv₁p⟩⟩⟩⟩ rcases hp₂ with ⟨p₂a, ⟨hp₂a, ⟨v₂, ⟨hv₂, hv₂p⟩⟩⟩⟩ rw [hv₁p, hv₂p, vsub_vadd_eq_vsub_sub (v₁ +ᵥ p₁a), vadd_vsub_assoc, add_comm, add_sub_assoc] have hv₁v₂ : v₁ - v₂ ∈ vectorSpan k s := (vectorSpan k s).sub_mem hv₁ hv₂ refine (vectorSpan k s).add_mem ?_ hv₁v₂ exact vsub_mem_vectorSpan k hp₁a hp₂a end /-- An `AffineSubspace k P` is a subset of an `AffineSpace V P` that, if not empty, has an affine space structure induced by a corresponding subspace of the `Module k V`. -/ structure AffineSubspace (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] where /-- The affine subspace seen as a subset. -/ carrier : Set P smul_vsub_vadd_mem : ∀ (c : k) {p₁ p₂ p₃ : P}, p₁ ∈ carrier → p₂ ∈ carrier → p₃ ∈ carrier → c • (p₁ -ᵥ p₂ : V) +ᵥ p₃ ∈ carrier namespace Submodule variable {k V : Type*} [Ring k] [AddCommGroup V] [Module k V] /-- Reinterpret `p : Submodule k V` as an `AffineSubspace k V`. -/ def toAffineSubspace (p : Submodule k V) : AffineSubspace k V where carrier := p smul_vsub_vadd_mem _ _ _ _ h₁ h₂ h₃ := p.add_mem (p.smul_mem _ (p.sub_mem h₁ h₂)) h₃ end Submodule namespace AffineSubspace variable (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] instance : SetLike (AffineSubspace k P) P where coe := carrier coe_injective' p q _ := by cases p; cases q; congr /-- A point is in an affine subspace coerced to a set if and only if it is in that affine subspace. -/ theorem mem_coe (p : P) (s : AffineSubspace k P) : p ∈ (s : Set P) ↔ p ∈ s := by simp variable {k P} /-- The direction of an affine subspace is the submodule spanned by the pairwise differences of points. (Except in the case of an empty affine subspace, where the direction is the zero submodule, every vector in the direction is the difference of two points in the affine subspace.) -/ def direction (s : AffineSubspace k P) : Submodule k V := vectorSpan k (s : Set P) /-- The direction equals the `vectorSpan`. -/ theorem direction_eq_vectorSpan (s : AffineSubspace k P) : s.direction = vectorSpan k (s : Set P) := rfl /-- Alternative definition of the direction when the affine subspace is nonempty. This is defined so that the order on submodules (as used in the definition of `Submodule.span`) can be used in the proof of `coe_direction_eq_vsub_set`, and is not intended to be used beyond that proof. -/ def directionOfNonempty {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : Submodule k V where carrier := (s : Set P) -ᵥ s zero_mem' := by obtain ⟨p, hp⟩ := h exact vsub_self p ▸ vsub_mem_vsub hp hp add_mem' := by rintro _ _ ⟨p₁, hp₁, p₂, hp₂, rfl⟩ ⟨p₃, hp₃, p₄, hp₄, rfl⟩ rw [← vadd_vsub_assoc] refine vsub_mem_vsub ?_ hp₄ convert s.smul_vsub_vadd_mem 1 hp₁ hp₂ hp₃ rw [one_smul] smul_mem' := by rintro c _ ⟨p₁, hp₁, p₂, hp₂, rfl⟩ rw [← vadd_vsub (c • (p₁ -ᵥ p₂)) p₂] refine vsub_mem_vsub ?_ hp₂ exact s.smul_vsub_vadd_mem c hp₁ hp₂ hp₂ /-- `direction_of_nonempty` gives the same submodule as `direction`. -/ theorem directionOfNonempty_eq_direction {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : directionOfNonempty h = s.direction := by refine le_antisymm ?_ (Submodule.span_le.2 Set.Subset.rfl) rw [← SetLike.coe_subset_coe, directionOfNonempty, direction, Submodule.coe_set_mk, AddSubmonoid.coe_set_mk] exact vsub_set_subset_vectorSpan k _ /-- The set of vectors in the direction of a nonempty affine subspace is given by `vsub_set`. -/ theorem coe_direction_eq_vsub_set {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : (s.direction : Set V) = (s : Set P) -ᵥ s := directionOfNonempty_eq_direction h ▸ rfl /-- A vector is in the direction of a nonempty affine subspace if and only if it is the subtraction of two vectors in the subspace. -/ theorem mem_direction_iff_eq_vsub {s : AffineSubspace k P} (h : (s : Set P).Nonempty) (v : V) : v ∈ s.direction ↔ ∃ p₁ ∈ s, ∃ p₂ ∈ s, v = p₁ -ᵥ p₂ := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set h, Set.mem_vsub] simp only [SetLike.mem_coe, eq_comm] /-- Adding a vector in the direction to a point in the subspace produces a point in the subspace. -/ theorem vadd_mem_of_mem_direction {s : AffineSubspace k P} {v : V} (hv : v ∈ s.direction) {p : P} (hp : p ∈ s) : v +ᵥ p ∈ s := by rw [mem_direction_iff_eq_vsub ⟨p, hp⟩] at hv rcases hv with ⟨p₁, hp₁, p₂, hp₂, hv⟩ rw [hv] convert s.smul_vsub_vadd_mem 1 hp₁ hp₂ hp rw [one_smul] /-- Subtracting two points in the subspace produces a vector in the direction. -/ theorem vsub_mem_direction {s : AffineSubspace k P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) : p₁ -ᵥ p₂ ∈ s.direction := vsub_mem_vectorSpan k hp₁ hp₂ /-- Adding a vector to a point in a subspace produces a point in the subspace if and only if the vector is in the direction. -/ theorem vadd_mem_iff_mem_direction {s : AffineSubspace k P} (v : V) {p : P} (hp : p ∈ s) : v +ᵥ p ∈ s ↔ v ∈ s.direction := ⟨fun h => by simpa using vsub_mem_direction h hp, fun h => vadd_mem_of_mem_direction h hp⟩ /-- Adding a vector in the direction to a point produces a point in the subspace if and only if the original point is in the subspace. -/ theorem vadd_mem_iff_mem_of_mem_direction {s : AffineSubspace k P} {v : V} (hv : v ∈ s.direction) {p : P} : v +ᵥ p ∈ s ↔ p ∈ s := by refine ⟨fun h => ?_, fun h => vadd_mem_of_mem_direction hv h⟩ convert vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) h simp /-- Given a point in an affine subspace, the set of vectors in its direction equals the set of vectors subtracting that point on the right. -/ theorem coe_direction_eq_vsub_set_right {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : (s.direction : Set V) = (· -ᵥ p) '' s := by rw [coe_direction_eq_vsub_set ⟨p, hp⟩] refine le_antisymm ?_ ?_ · rintro v ⟨p₁, hp₁, p₂, hp₂, rfl⟩ exact ⟨(p₁ -ᵥ p₂) +ᵥ p, vadd_mem_of_mem_direction (vsub_mem_direction hp₁ hp₂) hp, vadd_vsub _ _⟩ · rintro v ⟨p₂, hp₂, rfl⟩ exact ⟨p₂, hp₂, p, hp, rfl⟩ /-- Given a point in an affine subspace, the set of vectors in its direction equals the set of vectors subtracting that point on the left. -/ theorem coe_direction_eq_vsub_set_left {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : (s.direction : Set V) = (p -ᵥ ·) '' s := by ext v rw [SetLike.mem_coe, ← Submodule.neg_mem_iff, ← SetLike.mem_coe, coe_direction_eq_vsub_set_right hp, Set.mem_image, Set.mem_image] conv_lhs => congr ext rw [← neg_vsub_eq_vsub_rev, neg_inj] /-- Given a point in an affine subspace, a vector is in its direction if and only if it results from subtracting that point on the right. -/ theorem mem_direction_iff_eq_vsub_right {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (v : V) : v ∈ s.direction ↔ ∃ p₂ ∈ s, v = p₂ -ᵥ p := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set_right hp] exact ⟨fun ⟨p₂, hp₂, hv⟩ => ⟨p₂, hp₂, hv.symm⟩, fun ⟨p₂, hp₂, hv⟩ => ⟨p₂, hp₂, hv.symm⟩⟩ /-- Given a point in an affine subspace, a vector is in its direction if and only if it results from subtracting that point on the left. -/ theorem mem_direction_iff_eq_vsub_left {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (v : V) : v ∈ s.direction ↔ ∃ p₂ ∈ s, v = p -ᵥ p₂ := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set_left hp] exact ⟨fun ⟨p₂, hp₂, hv⟩ => ⟨p₂, hp₂, hv.symm⟩, fun ⟨p₂, hp₂, hv⟩ => ⟨p₂, hp₂, hv.symm⟩⟩ /-- Two affine subspaces are equal if they have the same points. -/ theorem coe_injective : Function.Injective ((↑) : AffineSubspace k P → Set P) := SetLike.coe_injective @[ext (iff := false)] theorem ext {p q : AffineSubspace k P} (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := SetLike.ext h protected theorem ext_iff (s₁ s₂ : AffineSubspace k P) : s₁ = s₂ ↔ (s₁ : Set P) = s₂ := SetLike.ext'_iff /-- Two affine subspaces with the same direction and nonempty intersection are equal. -/ theorem ext_of_direction_eq {s₁ s₂ : AffineSubspace k P} (hd : s₁.direction = s₂.direction) (hn : ((s₁ : Set P) ∩ s₂).Nonempty) : s₁ = s₂ := by ext p have hq1 := Set.mem_of_mem_inter_left hn.some_mem have hq2 := Set.mem_of_mem_inter_right hn.some_mem constructor · intro hp rw [← vsub_vadd p hn.some] refine vadd_mem_of_mem_direction ?_ hq2 rw [← hd] exact vsub_mem_direction hp hq1 · intro hp rw [← vsub_vadd p hn.some] refine vadd_mem_of_mem_direction ?_ hq1 rw [hd] exact vsub_mem_direction hp hq2 /-- Two affine subspaces with nonempty intersection are equal if and only if their directions are equal. -/ theorem eq_iff_direction_eq_of_mem {s₁ s₂ : AffineSubspace k P} {p : P} (h₁ : p ∈ s₁) (h₂ : p ∈ s₂) : s₁ = s₂ ↔ s₁.direction = s₂.direction := ⟨fun h => h ▸ rfl, fun h => ext_of_direction_eq h ⟨p, h₁, h₂⟩⟩ /-- Construct an affine subspace from a point and a direction. -/ def mk' (p : P) (direction : Submodule k V) : AffineSubspace k P where carrier := { q | q -ᵥ p ∈ direction } smul_vsub_vadd_mem c p₁ p₂ p₃ hp₁ hp₂ hp₃ := by simpa [vadd_vsub_assoc] using direction.add_mem (direction.smul_mem c (direction.sub_mem hp₁ hp₂)) hp₃ /-- A point lies in an affine subspace constructed from another point and a direction if and only if their difference is in that direction. -/ @[simp] theorem mem_mk' {p q : P} {direction : Submodule k V} : q ∈ mk' p direction ↔ q -ᵥ p ∈ direction := Iff.rfl /-- An affine subspace constructed from a point and a direction contains that point. -/ theorem self_mem_mk' (p : P) (direction : Submodule k V) : p ∈ mk' p direction := by simp /-- An affine subspace constructed from a point and a direction contains the result of adding a vector in that direction to that point. -/ theorem vadd_mem_mk' {v : V} (p : P) {direction : Submodule k V} (hv : v ∈ direction) : v +ᵥ p ∈ mk' p direction := by simpa /-- An affine subspace constructed from a point and a direction is nonempty. -/ theorem mk'_nonempty (p : P) (direction : Submodule k V) : (mk' p direction : Set P).Nonempty := ⟨p, self_mem_mk' p direction⟩ /-- The direction of an affine subspace constructed from a point and a direction. -/ @[simp] theorem direction_mk' (p : P) (direction : Submodule k V) : (mk' p direction).direction = direction := by ext v rw [mem_direction_iff_eq_vsub (mk'_nonempty _ _)] constructor · rintro ⟨p₁, hp₁, p₂, hp₂, rfl⟩ simpa using direction.sub_mem hp₁ hp₂ · exact fun hv => ⟨v +ᵥ p, vadd_mem_mk' _ hv, p, self_mem_mk' _ _, (vadd_vsub _ _).symm⟩ @[deprecated (since := "2025-08-15")] alias mem_mk'_iff_vsub_mem := mem_mk' /-- Constructing an affine subspace from a point in a subspace and that subspace's direction yields the original subspace. -/ @[simp] theorem mk'_eq {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : mk' p s.direction = s := ext_of_direction_eq (direction_mk' p s.direction) ⟨p, Set.mem_inter (self_mem_mk' _ _) hp⟩ /-- If an affine subspace contains a set of points, it contains the `spanPoints` of that set. -/ theorem spanPoints_subset_coe_of_subset_coe {s : Set P} {s₁ : AffineSubspace k P} (h : s ⊆ s₁) : spanPoints k s ⊆ s₁ := by rintro p ⟨p₁, hp₁, v, hv, hp⟩ rw [hp] have hp₁s₁ : p₁ ∈ (s₁ : Set P) := Set.mem_of_mem_of_subset hp₁ h refine vadd_mem_of_mem_direction ?_ hp₁s₁ have hs : vectorSpan k s ≤ s₁.direction := vectorSpan_mono k h rw [SetLike.le_def] at hs rw [← SetLike.mem_coe] exact Set.mem_of_mem_of_subset hv hs end AffineSubspace namespace Submodule variable {k V : Type*} [Ring k] [AddCommGroup V] [Module k V] @[simp] theorem mem_toAffineSubspace {p : Submodule k V} {x : V} : x ∈ p.toAffineSubspace ↔ x ∈ p := Iff.rfl @[simp] theorem toAffineSubspace_direction (s : Submodule k V) : s.toAffineSubspace.direction = s := by ext x; simp [← s.toAffineSubspace.vadd_mem_iff_mem_direction _ s.zero_mem] end Submodule section affineSpan variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- The affine span of a set of points is the smallest affine subspace containing those points. (Actually defined here in terms of spans in modules.) -/ def affineSpan (s : Set P) : AffineSubspace k P where carrier := spanPoints k s smul_vsub_vadd_mem c _ _ _ hp₁ hp₂ hp₃ := vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan k hp₃ ((vectorSpan k s).smul_mem c (vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints k hp₁ hp₂)) /-- The affine span, converted to a set, is `spanPoints`. -/ @[simp] theorem coe_affineSpan (s : Set P) : (affineSpan k s : Set P) = spanPoints k s := rfl /-- The condition for a point to be in the affine span, in terms of `vectorSpan`. -/ lemma mem_affineSpan_iff_exists {p : P} {s : Set P} : p ∈ affineSpan k s ↔ ∃ p₁ ∈ s, ∃ v ∈ vectorSpan k s, p = v +ᵥ p₁ := Iff.rfl /-- A set is contained in its affine span. -/ theorem subset_affineSpan (s : Set P) : s ⊆ affineSpan k s := subset_spanPoints k s /-- The direction of the affine span is the `vectorSpan`. -/ theorem direction_affineSpan (s : Set P) : (affineSpan k s).direction = vectorSpan k s := by apply le_antisymm · refine Submodule.span_le.2 ?_ rintro v ⟨p₁, ⟨p₂, hp₂, v₁, hv₁, hp₁⟩, p₃, ⟨p₄, hp₄, v₂, hv₂, hp₃⟩, rfl⟩ simp only [SetLike.mem_coe] rw [hp₁, hp₃, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc] exact (vectorSpan k s).sub_mem ((vectorSpan k s).add_mem hv₁ (vsub_mem_vectorSpan k hp₂ hp₄)) hv₂ · exact vectorSpan_mono k (subset_spanPoints k s) /-- A point in a set is in its affine span. -/ theorem mem_affineSpan {p : P} {s : Set P} (hp : p ∈ s) : p ∈ affineSpan k s := mem_spanPoints k p s hp @[simp] lemma vectorSpan_add_self (s : Set V) : (vectorSpan k s : Set V) + s = affineSpan k s := by ext simp [mem_add, spanPoints] aesop variable {k} /-- Adding a point in the affine span and a vector in the spanning submodule produces a point in the affine span. -/ theorem vadd_mem_affineSpan_of_mem_affineSpan_of_mem_vectorSpan {s : Set P} {p : P} {v : V} (hp : p ∈ affineSpan k s) (hv : v ∈ vectorSpan k s) : v +ᵥ p ∈ affineSpan k s := vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan k hp hv /-- Subtracting two points in the affine span produces a vector in the spanning submodule. -/ theorem vsub_mem_vectorSpan_of_mem_affineSpan_of_mem_affineSpan {s : Set P} {p₁ p₂ : P} (hp₁ : p₁ ∈ affineSpan k s) (hp₂ : p₂ ∈ affineSpan k s) : p₁ -ᵥ p₂ ∈ vectorSpan k s := vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints k hp₁ hp₂ /-- If an affine subspace contains a set of points, it contains the affine span of that set. -/ theorem affineSpan_le_of_subset_coe {s : Set P} {s₁ : AffineSubspace k P} (h : s ⊆ s₁) : affineSpan k s ≤ s₁ := AffineSubspace.spanPoints_subset_coe_of_subset_coe h end affineSpan namespace AffineSubspace variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [S : AffineSpace V P] {ι : Sort*} instance : CompleteLattice (AffineSubspace k P) := { PartialOrder.lift ((↑) : AffineSubspace k P → Set P) coe_injective with sup := fun s₁ s₂ => affineSpan k (s₁ ∪ s₂) le_sup_left := fun _ _ => Set.Subset.trans Set.subset_union_left (subset_spanPoints k _) le_sup_right := fun _ _ => Set.Subset.trans Set.subset_union_right (subset_spanPoints k _) sup_le := fun _ _ _ hs₁ hs₂ => spanPoints_subset_coe_of_subset_coe (Set.union_subset hs₁ hs₂) inf := fun s₁ s₂ => mk (s₁ ∩ s₂) fun c _ _ _ hp₁ hp₂ hp₃ => ⟨s₁.smul_vsub_vadd_mem c hp₁.1 hp₂.1 hp₃.1, s₂.smul_vsub_vadd_mem c hp₁.2 hp₂.2 hp₃.2⟩ inf_le_left := fun _ _ => Set.inter_subset_left inf_le_right := fun _ _ => Set.inter_subset_right le_sInf := fun S s₁ hs₁ => by apply Set.subset_sInter rintro t ⟨s, _hs, rfl⟩ exact Set.subset_iInter (hs₁ s) top := { carrier := Set.univ smul_vsub_vadd_mem := fun _ _ _ _ _ _ _ => Set.mem_univ _ } le_top := fun _ _ _ => Set.mem_univ _ bot := { carrier := ∅ smul_vsub_vadd_mem := fun _ _ _ _ => False.elim } bot_le := fun _ _ => False.elim sSup := fun s => affineSpan k (⋃ s' ∈ s, (s' : Set P)) sInf := fun s => mk (⋂ s' ∈ s, (s' : Set P)) fun c p₁ p₂ p₃ hp₁ hp₂ hp₃ => Set.mem_iInter₂.2 fun s₂ hs₂ => by rw [Set.mem_iInter₂] at * exact s₂.smul_vsub_vadd_mem c (hp₁ s₂ hs₂) (hp₂ s₂ hs₂) (hp₃ s₂ hs₂) le_sSup := fun _ _ h => Set.Subset.trans (Set.subset_biUnion_of_mem h) (subset_spanPoints k _) sSup_le := fun _ _ h => spanPoints_subset_coe_of_subset_coe (Set.iUnion₂_subset h) sInf_le := fun _ _ => Set.biInter_subset_of_mem le_inf := fun _ _ _ => Set.subset_inter } instance : Inhabited (AffineSubspace k P) := ⟨⊤⟩ /-- The `≤` order on subspaces is the same as that on the corresponding sets. -/ theorem le_def (s₁ s₂ : AffineSubspace k P) : s₁ ≤ s₂ ↔ (s₁ : Set P) ⊆ s₂ := Iff.rfl /-- One subspace is less than or equal to another if and only if all its points are in the second subspace. -/ theorem le_def' (s₁ s₂ : AffineSubspace k P) : s₁ ≤ s₂ ↔ ∀ p ∈ s₁, p ∈ s₂ := Iff.rfl /-- The `<` order on subspaces is the same as that on the corresponding sets. -/ theorem lt_def (s₁ s₂ : AffineSubspace k P) : s₁ < s₂ ↔ (s₁ : Set P) ⊂ s₂ := Iff.rfl /-- One subspace is not less than or equal to another if and only if it has a point not in the second subspace. -/ theorem not_le_iff_exists (s₁ s₂ : AffineSubspace k P) : ¬s₁ ≤ s₂ ↔ ∃ p ∈ s₁, p ∉ s₂ := Set.not_subset /-- If a subspace is less than another, there is a point only in the second. -/ theorem exists_of_lt {s₁ s₂ : AffineSubspace k P} (h : s₁ < s₂) : ∃ p ∈ s₂, p ∉ s₁ := Set.exists_of_ssubset h /-- A subspace is less than another if and only if it is less than or equal to the second subspace and there is a point only in the second. -/ theorem lt_iff_le_and_exists (s₁ s₂ : AffineSubspace k P) : s₁ < s₂ ↔ s₁ ≤ s₂ ∧ ∃ p ∈ s₂, p ∉ s₁ := by rw [lt_iff_le_not_ge, not_le_iff_exists] /-- If an affine subspace is nonempty and contained in another with the same direction, they are equal. -/ theorem eq_of_direction_eq_of_nonempty_of_le {s₁ s₂ : AffineSubspace k P} (hd : s₁.direction = s₂.direction) (hn : (s₁ : Set P).Nonempty) (hle : s₁ ≤ s₂) : s₁ = s₂ := let ⟨p, hp⟩ := hn ext_of_direction_eq hd ⟨p, hp, hle hp⟩ instance nonempty_sup_left (s₁ s₂ : AffineSubspace k P) [Nonempty s₁] : Nonempty (s₁ ⊔ s₂ : AffineSubspace k P) := .map (Set.inclusion <| SetLike.le_def.1 le_sup_left) ‹_› instance nonempty_sup_right (s₁ s₂ : AffineSubspace k P) [Nonempty s₂] : Nonempty (s₁ ⊔ s₂ : AffineSubspace k P) := .map (Set.inclusion <| SetLike.le_def.1 le_sup_right) ‹_› variable (k V) /-- The affine span is the `sInf` of subspaces containing the given points. -/ theorem affineSpan_eq_sInf (s : Set P) : affineSpan k s = sInf { s' : AffineSubspace k P | s ⊆ s' } := le_antisymm (affineSpan_le_of_subset_coe <| Set.subset_iInter₂ fun _ => id) (sInf_le (subset_spanPoints k _)) variable (P) /-- The Galois insertion formed by `affineSpan` and coercion back to a set. -/ protected def gi : GaloisInsertion (affineSpan k) ((↑) : AffineSubspace k P → Set P) where choice s _ := affineSpan k s gc s₁ _s₂ := ⟨fun h => Set.Subset.trans (subset_spanPoints k s₁) h, affineSpan_le_of_subset_coe⟩ le_l_u _ := subset_spanPoints k _ choice_eq _ _ := rfl /-- The span of the empty set is `⊥`. -/ @[simp] theorem span_empty : affineSpan k (∅ : Set P) = ⊥ := (AffineSubspace.gi k V P).gc.l_bot /-- The span of `univ` is `⊤`. -/ @[simp] theorem span_univ : affineSpan k (Set.univ : Set P) = ⊤ := eq_top_iff.2 <| subset_affineSpan k _ variable {k V P} theorem _root_.affineSpan_le {s : Set P} {Q : AffineSubspace k P} : affineSpan k s ≤ Q ↔ s ⊆ (Q : Set P) := (AffineSubspace.gi k V P).gc _ _ variable (k V) {p₁ p₂ : P} /-- The span of a union of sets is the sup of their spans. -/ theorem span_union (s t : Set P) : affineSpan k (s ∪ t) = affineSpan k s ⊔ affineSpan k t := (AffineSubspace.gi k V P).gc.l_sup /-- The span of a union of an indexed family of sets is the sup of their spans. -/ theorem span_iUnion {ι : Type*} (s : ι → Set P) : affineSpan k (⋃ i, s i) = ⨆ i, affineSpan k (s i) := (AffineSubspace.gi k V P).gc.l_iSup variable (P) in /-- `⊤`, coerced to a set, is the whole set of points. -/ @[simp] theorem top_coe : ((⊤ : AffineSubspace k P) : Set P) = Set.univ := rfl /-- All points are in `⊤`. -/ @[simp] theorem mem_top (p : P) : p ∈ (⊤ : AffineSubspace k P) := Set.mem_univ p @[simp] lemma mk'_top (p : P) : mk' p (⊤ : Submodule k V) = ⊤ := by ext x simp [mem_mk'] variable (P) /-- The direction of `⊤` is the whole module as a submodule. -/ @[simp] theorem direction_top : (⊤ : AffineSubspace k P).direction = ⊤ := by obtain ⟨p⟩ := S.nonempty ext v refine ⟨imp_intro Submodule.mem_top, fun _hv => ?_⟩ have hpv : ((v +ᵥ p) -ᵥ p : V) ∈ (⊤ : AffineSubspace k P).direction := vsub_mem_direction (mem_top k V _) (mem_top k V _) rwa [vadd_vsub] at hpv /-- `⊥`, coerced to a set, is the empty set. -/ @[simp] theorem bot_coe : ((⊥ : AffineSubspace k P) : Set P) = ∅ := rfl theorem bot_ne_top : (⊥ : AffineSubspace k P) ≠ ⊤ := by intro contra rw [AffineSubspace.ext_iff, bot_coe, top_coe] at contra exact Set.empty_ne_univ contra instance : Nontrivial (AffineSubspace k P) := ⟨⟨⊥, ⊤, bot_ne_top k V P⟩⟩ theorem nonempty_of_affineSpan_eq_top {s : Set P} (h : affineSpan k s = ⊤) : s.Nonempty := by rw [Set.nonempty_iff_ne_empty] rintro rfl rw [AffineSubspace.span_empty] at h exact bot_ne_top k V P h /-- If the affine span of a set is `⊤`, then the vector span of the same set is the `⊤`. -/ theorem vectorSpan_eq_top_of_affineSpan_eq_top {s : Set P} (h : affineSpan k s = ⊤) : vectorSpan k s = ⊤ := by rw [← direction_affineSpan, h, direction_top] /-- For a nonempty set, the affine span is `⊤` iff its vector span is `⊤`. -/ theorem affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty {s : Set P} (hs : s.Nonempty) : affineSpan k s = ⊤ ↔ vectorSpan k s = ⊤ := by refine ⟨vectorSpan_eq_top_of_affineSpan_eq_top k V P, ?_⟩ intro h suffices Nonempty (affineSpan k s) by obtain ⟨p, hp : p ∈ affineSpan k s⟩ := this rw [eq_iff_direction_eq_of_mem hp (mem_top k V p), direction_affineSpan, h, direction_top] obtain ⟨x, hx⟩ := hs exact ⟨⟨x, mem_affineSpan k hx⟩⟩ /-- For a non-trivial space, the affine span of a set is `⊤` iff its vector span is `⊤`. -/ theorem affineSpan_eq_top_iff_vectorSpan_eq_top_of_nontrivial {s : Set P} [Nontrivial P] : affineSpan k s = ⊤ ↔ vectorSpan k s = ⊤ := by rcases s.eq_empty_or_nonempty with hs | hs · simp [hs, subsingleton_iff_bot_eq_top, AddTorsor.subsingleton_iff V P, not_subsingleton] · rw [affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty k V P hs] theorem card_pos_of_affineSpan_eq_top {ι : Type*} [Fintype ι] {p : ι → P} (h : affineSpan k (range p) = ⊤) : 0 < Fintype.card ι := by obtain ⟨-, ⟨i, -⟩⟩ := nonempty_of_affineSpan_eq_top k V P h exact Fintype.card_pos_iff.mpr ⟨i⟩ -- An instance with better keys for the context instance : Nonempty (⊤ : AffineSubspace k P) := inferInstanceAs (Nonempty (⊤ : Set P)) variable {P} /-- No points are in `⊥`. -/ theorem notMem_bot (p : P) : p ∉ (⊥ : AffineSubspace k P) := Set.notMem_empty p @[deprecated (since := "2025-05-23")] alias not_mem_bot := notMem_bot instance isEmpty_bot : IsEmpty (⊥ : AffineSubspace k P) := Subtype.isEmpty_of_false fun _ ↦ notMem_bot _ _ _ variable (P) /-- The direction of `⊥` is the submodule `⊥`. -/ @[simp] theorem direction_bot : (⊥ : AffineSubspace k P).direction = ⊥ := by rw [direction_eq_vectorSpan, bot_coe, vectorSpan_def, vsub_empty, Submodule.span_empty] variable {k V P} @[simp] theorem coe_eq_bot_iff (Q : AffineSubspace k P) : (Q : Set P) = ∅ ↔ Q = ⊥ := coe_injective.eq_iff' (bot_coe _ _ _) @[simp] theorem coe_eq_univ_iff (Q : AffineSubspace k P) : (Q : Set P) = univ ↔ Q = ⊤ := coe_injective.eq_iff' (top_coe _ _ _) theorem nonempty_iff_ne_bot (Q : AffineSubspace k P) : (Q : Set P).Nonempty ↔ Q ≠ ⊥ := by rw [nonempty_iff_ne_empty] exact not_congr Q.coe_eq_bot_iff theorem eq_bot_or_nonempty (Q : AffineSubspace k P) : Q = ⊥ ∨ (Q : Set P).Nonempty := by rw [nonempty_iff_ne_bot] apply eq_or_ne instance [Subsingleton P] : IsSimpleOrder (AffineSubspace k P) where eq_bot_or_eq_top (s : AffineSubspace k P) := by rw [← coe_eq_bot_iff, ← coe_eq_univ_iff] rcases (s : Set P).eq_empty_or_nonempty with h | h · exact .inl h · exact .inr h.eq_univ /-- A nonempty affine subspace is `⊤` if and only if its direction is `⊤`. -/ @[simp] theorem direction_eq_top_iff_of_nonempty {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : s.direction = ⊤ ↔ s = ⊤ := by constructor · intro hd rw [← direction_top k V P] at hd refine ext_of_direction_eq hd ?_ simp [h] · rintro rfl simp /-- The inf of two affine subspaces, coerced to a set, is the intersection of the two sets of points. -/ @[simp] theorem coe_inf (s₁ s₂ : AffineSubspace k P) : (s₁ ⊓ s₂ : Set P) = (s₁ : Set P) ∩ s₂ := rfl @[deprecated (since := "2025-08-31")] alias inf_coe := coe_inf /-- A point is in the inf of two affine subspaces if and only if it is in both of them. -/ theorem mem_inf_iff (p : P) (s₁ s₂ : AffineSubspace k P) : p ∈ s₁ ⊓ s₂ ↔ p ∈ s₁ ∧ p ∈ s₂ := Iff.rfl /-- The direction of the inf of two affine subspaces is less than or equal to the inf of their directions. -/ theorem direction_inf (s₁ s₂ : AffineSubspace k P) : (s₁ ⊓ s₂).direction ≤ s₁.direction ⊓ s₂.direction := by simp only [direction_eq_vectorSpan, vectorSpan_def] exact le_inf (sInf_le_sInf fun p hp => trans (vsub_self_mono inter_subset_left) hp) (sInf_le_sInf fun p hp => trans (vsub_self_mono inter_subset_right) hp) /-- If two affine subspaces have a point in common, the direction of their inf equals the inf of their directions. -/ theorem direction_inf_of_mem {s₁ s₂ : AffineSubspace k P} {p : P} (h₁ : p ∈ s₁) (h₂ : p ∈ s₂) : (s₁ ⊓ s₂).direction = s₁.direction ⊓ s₂.direction := by ext v rw [Submodule.mem_inf, ← vadd_mem_iff_mem_direction v h₁, ← vadd_mem_iff_mem_direction v h₂, ← vadd_mem_iff_mem_direction v ((mem_inf_iff p s₁ s₂).2 ⟨h₁, h₂⟩), mem_inf_iff] /-- If two affine subspaces have a point in their inf, the direction of their inf equals the inf of their directions. -/ theorem direction_inf_of_mem_inf {s₁ s₂ : AffineSubspace k P} {p : P} (h : p ∈ s₁ ⊓ s₂) : (s₁ ⊓ s₂).direction = s₁.direction ⊓ s₂.direction := direction_inf_of_mem ((mem_inf_iff p s₁ s₂).1 h).1 ((mem_inf_iff p s₁ s₂).1 h).2 @[simp, norm_cast] theorem coe_sInf (t : Set (AffineSubspace k P)) : ((sInf t : AffineSubspace k P) : Set P) = ⋂ s ∈ t, s := rfl theorem mem_sInf_iff (p : P) (t : Set (AffineSubspace k P)) : p ∈ sInf t ↔ ∀ s ∈ t, p ∈ s := Set.mem_iInter₂ theorem direction_sInf (t : Set (AffineSubspace k P)) : direction (sInf t) ≤ ⨅ s ∈ t, s.direction := by simp only [direction_eq_vectorSpan, vectorSpan_def] exact le_iInf₂ fun s hs => Submodule.span_mono <| vsub_self_mono <| biInter_subset_of_mem hs theorem direction_sInf_of_mem (t : Set (AffineSubspace k P)) (p : P) (h : ∀ s ∈ t, p ∈ s) : direction (sInf t) = ⨅ s ∈ t, s.direction := by apply (direction_sInf t).antisymm intro v hv rw [← vadd_mem_iff_mem_direction v ((mem_sInf_iff p t).mpr h), mem_sInf_iff] intro s hs rw [vadd_mem_iff_mem_direction v (h s hs)] simp only [Submodule.mem_iInf] at hv exact hv s hs theorem direction_sInf_of_mem_sInf (t : Set (AffineSubspace k P)) (p : P) (h : p ∈ sInf t) : direction (sInf t) = ⨅ s ∈ t, s.direction := direction_sInf_of_mem t p <| (mem_sInf_iff p t).mp h @[simp, norm_cast] theorem coe_iInf (s : ι → AffineSubspace k P) : ((iInf s : AffineSubspace k P) : Set P) = ⋂ i, s i := by rw [iInf, coe_sInf, Set.biInter_range] theorem mem_iInf_iff (s : ι → AffineSubspace k P) (p : P) : p ∈ iInf s ↔ ∀ i, p ∈ s i := by rw [iInf, mem_sInf_iff, Set.forall_mem_range] theorem direction_iInf (s : ι → AffineSubspace k P) : (iInf s).direction ≤ ⨅ i, (s i).direction := by apply (direction_sInf _).trans_eq rw [iInf_range] theorem direction_iInf_of_mem (s : ι → AffineSubspace k P) (p : P) (h : ∀ i, p ∈ s i) : (iInf s).direction = ⨅ i, (s i).direction := by rw [iInf, direction_sInf_of_mem _ p ?_, iInf_range] rwa [Set.forall_mem_range] theorem direction_iInf_of_mem_iInf (s : ι → AffineSubspace k P) (p : P) (h : p ∈ iInf s) : (iInf s).direction = ⨅ i, (s i).direction := by rw [iInf, direction_sInf_of_mem_sInf _ p h, iInf_range] /-- If one affine subspace is less than or equal to another, the same applies to their directions. -/ theorem direction_le {s₁ s₂ : AffineSubspace k P} (h : s₁ ≤ s₂) : s₁.direction ≤ s₂.direction := by simp only [direction_eq_vectorSpan, vectorSpan_def] exact vectorSpan_mono k h /-- The sup of the directions of two affine subspaces is less than or equal to the direction of their sup. -/ theorem sup_direction_le (s₁ s₂ : AffineSubspace k P) : s₁.direction ⊔ s₂.direction ≤ (s₁ ⊔ s₂).direction := by simp only [direction_eq_vectorSpan, vectorSpan_def] exact sup_le (sInf_le_sInf fun p hp => Set.Subset.trans (vsub_self_mono (le_sup_left : s₁ ≤ s₁ ⊔ s₂)) hp) (sInf_le_sInf fun p hp => Set.Subset.trans (vsub_self_mono (le_sup_right : s₂ ≤ s₁ ⊔ s₂)) hp) /-- The sup of the directions of two nonempty affine subspaces with empty intersection is less than the direction of their sup. -/ theorem sup_direction_lt_of_nonempty_of_inter_empty {s₁ s₂ : AffineSubspace k P} (h1 : (s₁ : Set P).Nonempty) (h2 : (s₂ : Set P).Nonempty) (he : (s₁ ∩ s₂ : Set P) = ∅) : s₁.direction ⊔ s₂.direction < (s₁ ⊔ s₂).direction := by obtain ⟨p₁, hp₁⟩ := h1 obtain ⟨p₂, hp₂⟩ := h2 rw [SetLike.lt_iff_le_and_exists] use sup_direction_le s₁ s₂, p₂ -ᵥ p₁, vsub_mem_direction ((le_sup_right : s₂ ≤ s₁ ⊔ s₂) hp₂) ((le_sup_left : s₁ ≤ s₁ ⊔ s₂) hp₁) intro h rw [Submodule.mem_sup] at h rcases h with ⟨v₁, hv₁, v₂, hv₂, hv₁v₂⟩ rw [← sub_eq_zero, sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm v₁, add_assoc, ← vadd_vsub_assoc, ← neg_neg v₂, add_comm, ← sub_eq_add_neg, ← vsub_vadd_eq_vsub_sub, vsub_eq_zero_iff_eq] at hv₁v₂ refine Set.Nonempty.ne_empty ?_ he use v₁ +ᵥ p₁, vadd_mem_of_mem_direction hv₁ hp₁ rw [hv₁v₂] exact vadd_mem_of_mem_direction (Submodule.neg_mem _ hv₂) hp₂ /-- If the directions of two nonempty affine subspaces span the whole module, they have nonempty intersection. -/ theorem inter_nonempty_of_nonempty_of_sup_direction_eq_top {s₁ s₂ : AffineSubspace k P} (h1 : (s₁ : Set P).Nonempty) (h2 : (s₂ : Set P).Nonempty) (hd : s₁.direction ⊔ s₂.direction = ⊤) : ((s₁ : Set P) ∩ s₂).Nonempty := by by_contra h rw [Set.not_nonempty_iff_eq_empty] at h have hlt := sup_direction_lt_of_nonempty_of_inter_empty h1 h2 h rw [hd] at hlt exact not_top_lt hlt /-- If the directions of two nonempty affine subspaces are complements of each other, they intersect in exactly one point. -/ theorem inter_eq_singleton_of_nonempty_of_isCompl {s₁ s₂ : AffineSubspace k P} (h1 : (s₁ : Set P).Nonempty) (h2 : (s₂ : Set P).Nonempty) (hd : IsCompl s₁.direction s₂.direction) : ∃ p, (s₁ : Set P) ∩ s₂ = {p} := by obtain ⟨p, hp⟩ := inter_nonempty_of_nonempty_of_sup_direction_eq_top h1 h2 hd.sup_eq_top use p ext q rw [Set.mem_singleton_iff] constructor · rintro ⟨hq1, hq2⟩ have hqp : q -ᵥ p ∈ s₁.direction ⊓ s₂.direction := ⟨vsub_mem_direction hq1 hp.1, vsub_mem_direction hq2 hp.2⟩ rwa [hd.inf_eq_bot, Submodule.mem_bot, vsub_eq_zero_iff_eq] at hqp · exact fun h => h.symm ▸ hp /-- Coercing a subspace to a set then taking the affine span produces the original subspace. -/ @[simp] theorem affineSpan_coe (s : AffineSubspace k P) : affineSpan k (s : Set P) = s := by refine le_antisymm ?_ (subset_affineSpan _ _) rintro p ⟨p₁, hp₁, v, hv, rfl⟩ exact vadd_mem_of_mem_direction hv hp₁ end AffineSubspace section AffineSpace' variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] variable {ι : Type*} open AffineSubspace section variable {s : Set P} /-- The affine span of a set is nonempty if and only if that set is. -/ theorem affineSpan_nonempty : (affineSpan k s : Set P).Nonempty ↔ s.Nonempty := spanPoints_nonempty k s alias ⟨_, _root_.Set.Nonempty.affineSpan⟩ := affineSpan_nonempty /-- The affine span of a nonempty set is nonempty. -/ instance [Nonempty s] : Nonempty (affineSpan k s) := ((nonempty_coe_sort.1 ‹_›).affineSpan _).to_subtype /-- The affine span of a set is `⊥` if and only if that set is empty. -/ @[simp] theorem affineSpan_eq_bot : affineSpan k s = ⊥ ↔ s = ∅ := by rw [← not_iff_not, ← Ne, ← Ne, ← nonempty_iff_ne_bot, affineSpan_nonempty, nonempty_iff_ne_empty] @[simp] theorem bot_lt_affineSpan : ⊥ < affineSpan k s ↔ s.Nonempty := by rw [bot_lt_iff_ne_bot, nonempty_iff_ne_empty] exact (affineSpan_eq_bot _).not @[simp] lemma affineSpan_eq_top_iff_nonempty_of_subsingleton [Subsingleton P] : affineSpan k s = ⊤ ↔ s.Nonempty := by rw [← bot_lt_affineSpan k, IsSimpleOrder.bot_lt_iff_eq_top] end variable {k} /-- An induction principle for span membership. If `p` holds for all elements of `s` and is preserved under certain affine combinations, then `p` holds for all elements of the span of `s`. -/ @[elab_as_elim] theorem affineSpan_induction {x : P} {s : Set P} {p : P → Prop} (h : x ∈ affineSpan k s) (mem : ∀ x : P, x ∈ s → p x) (smul_vsub_vadd : ∀ (c : k) (u v w : P), p u → p v → p w → p (c • (u -ᵥ v) +ᵥ w)) : p x := (affineSpan_le (Q := ⟨p, smul_vsub_vadd⟩)).mpr mem h /-- A dependent version of `affineSpan_induction`. -/ @[elab_as_elim] theorem affineSpan_induction' {s : Set P} {p : ∀ x, x ∈ affineSpan k s → Prop} (mem : ∀ (y) (hys : y ∈ s), p y (subset_affineSpan k _ hys)) (smul_vsub_vadd : ∀ (c : k) (u hu v hv w hw), p u hu → p v hv → p w hw → p (c • (u -ᵥ v) +ᵥ w) (AffineSubspace.smul_vsub_vadd_mem _ _ hu hv hw)) {x : P} (h : x ∈ affineSpan k s) : p x h := by suffices ∃ (hx : x ∈ affineSpan k s), p x hx from this.elim fun hx hc ↦ hc -- TODO: `induction h using affineSpan_induction` gives the error: -- extra targets for '@affineSpan_induction' -- It seems that the `induction` tactic has decided to ignore the clause -- `using affineSpan_induction` and use `Exists.rec` instead. refine affineSpan_induction h ?mem ?smul_vsub_vadd · exact fun y hy ↦ ⟨subset_affineSpan _ _ hy, mem y hy⟩ · exact fun c u v w hu hv hw ↦ hu.elim fun hu' hu ↦ hv.elim fun hv' hv ↦ hw.elim fun hw' hw ↦ ⟨AffineSubspace.smul_vsub_vadd_mem _ _ hu' hv' hw', smul_vsub_vadd _ _ _ _ _ _ _ hu hv hw⟩ variable (k) /-- The difference between two points lies in their `vectorSpan`. -/ theorem vsub_mem_vectorSpan_pair (p₁ p₂ : P) : p₁ -ᵥ p₂ ∈ vectorSpan k ({p₁, p₂} : Set P) := vsub_mem_vectorSpan _ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_singleton _)) /-- The difference between two points (reversed) lies in their `vectorSpan`. -/ theorem vsub_rev_mem_vectorSpan_pair (p₁ p₂ : P) : p₂ -ᵥ p₁ ∈ vectorSpan k ({p₁, p₂} : Set P) := vsub_mem_vectorSpan _ (Set.mem_insert_of_mem _ (Set.mem_singleton _)) (Set.mem_insert _ _) variable {k} /-- A multiple of the difference between two points lies in their `vectorSpan`. -/ theorem smul_vsub_mem_vectorSpan_pair (r : k) (p₁ p₂ : P) : r • (p₁ -ᵥ p₂) ∈ vectorSpan k ({p₁, p₂} : Set P) := Submodule.smul_mem _ _ (vsub_mem_vectorSpan_pair k p₁ p₂) /-- A multiple of the difference between two points (reversed) lies in their `vectorSpan`. -/ theorem smul_vsub_rev_mem_vectorSpan_pair (r : k) (p₁ p₂ : P) : r • (p₂ -ᵥ p₁) ∈ vectorSpan k ({p₁, p₂} : Set P) := Submodule.smul_mem _ _ (vsub_rev_mem_vectorSpan_pair k p₁ p₂) variable (k) /-- The line between two points, as an affine subspace. -/ notation "line[" k ", " p₁ ", " p₂ "]" => affineSpan k (insert p₁ (@singleton _ _ Set.instSingletonSet p₂)) /-- The first of two points lies in their affine span. -/ theorem left_mem_affineSpan_pair (p₁ p₂ : P) : p₁ ∈ line[k, p₁, p₂] := mem_affineSpan _ (Set.mem_insert _ _) /-- The second of two points lies in their affine span. -/ theorem right_mem_affineSpan_pair (p₁ p₂ : P) : p₂ ∈ line[k, p₁, p₂] := mem_affineSpan _ (Set.mem_insert_of_mem _ (Set.mem_singleton _)) variable {k} /-- The span of two points that lie in an affine subspace is contained in that subspace. -/ theorem affineSpan_pair_le_of_mem_of_mem {p₁ p₂ : P} {s : AffineSubspace k P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) : line[k, p₁, p₂] ≤ s := by rw [affineSpan_le, Set.insert_subset_iff, Set.singleton_subset_iff] exact ⟨hp₁, hp₂⟩ /-- One line is contained in another differing in the first point if the first point of the first line is contained in the second line. -/ theorem affineSpan_pair_le_of_left_mem {p₁ p₂ p₃ : P} (h : p₁ ∈ line[k, p₂, p₃]) : line[k, p₁, p₃] ≤ line[k, p₂, p₃] := affineSpan_pair_le_of_mem_of_mem h (right_mem_affineSpan_pair _ _ _) /-- One line is contained in another differing in the second point if the second point of the first line is contained in the second line. -/ theorem affineSpan_pair_le_of_right_mem {p₁ p₂ p₃ : P} (h : p₁ ∈ line[k, p₂, p₃]) : line[k, p₂, p₁] ≤ line[k, p₂, p₃] := affineSpan_pair_le_of_mem_of_mem (left_mem_affineSpan_pair _ _ _) h variable (k) /-- `affineSpan` is monotone. -/ @[gcongr, mono] theorem affineSpan_mono {s₁ s₂ : Set P} (h : s₁ ⊆ s₂) : affineSpan k s₁ ≤ affineSpan k s₂ := affineSpan_le_of_subset_coe (Set.Subset.trans h (subset_affineSpan k _)) /-- Taking the affine span of a set, adding a point and taking the span again produces the same results as adding the point to the set and taking the span. -/ theorem affineSpan_insert_affineSpan (p : P) (ps : Set P) : affineSpan k (insert p (affineSpan k ps : Set P)) = affineSpan k (insert p ps) := by rw [Set.insert_eq, Set.insert_eq, span_union, span_union, affineSpan_coe] /-- If a point is in the affine span of a set, adding it to that set does not change the affine span. -/ theorem affineSpan_insert_eq_affineSpan {p : P} {ps : Set P} (h : p ∈ affineSpan k ps) : affineSpan k (insert p ps) = affineSpan k ps := by rw [← mem_coe] at h rw [← affineSpan_insert_affineSpan, Set.insert_eq_of_mem h, affineSpan_coe] variable {k} /-- If a point is in the affine span of a set, adding it to that set does not change the vector span. -/ theorem vectorSpan_insert_eq_vectorSpan {p : P} {ps : Set P} (h : p ∈ affineSpan k ps) : vectorSpan k (insert p ps) = vectorSpan k ps := by simp_rw [← direction_affineSpan, affineSpan_insert_eq_affineSpan _ h] /-- When the affine space is also a vector space, the affine span is contained within the linear span. -/ lemma affineSpan_le_toAffineSubspace_span {s : Set V} : affineSpan k s ≤ (Submodule.span k s).toAffineSubspace := by intro x hx simp only [SetLike.mem_coe, Submodule.mem_toAffineSubspace] induction hx using affineSpan_induction' with | mem x hx => exact Submodule.subset_span hx | smul_vsub_vadd c u _ v _ w _ hu hv hw => simp only [vsub_eq_sub, vadd_eq_add] apply Submodule.add_mem _ _ hw exact Submodule.smul_mem _ _ (Submodule.sub_mem _ hu hv) lemma affineSpan_subset_span {s : Set V} : (affineSpan k s : Set V) ⊆ Submodule.span k s := affineSpan_le_toAffineSubspace_span -- TODO: We want this to be simp, but `affineSpan` gets simp-ed away to `spanPoints`! -- Let's delete `spanPoints` lemma affineSpan_insert_zero (s : Set V) : (affineSpan k (insert 0 s) : Set V) = Submodule.span k s := by rw [← Submodule.span_insert_zero] refine affineSpan_subset_span.antisymm ?_ rw [← vectorSpan_add_self, vectorSpan_def] refine Subset.trans ?_ <| subset_add_left _ <| mem_insert .. gcongr exact subset_sub_left <| mem_insert .. end AffineSpace'
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Simplex/Centroid.lean
import Mathlib.LinearAlgebra.AffineSpace.Simplex.Basic import Mathlib.LinearAlgebra.AffineSpace.Centroid /-! # Centroid of a simplex in affine space This file proves some basic properties of the centroid of a simplex in affine space. -/ noncomputable section open Finset namespace Affine namespace Simplex variable {k : Type*} {V : Type*} {P : Type*} [DivisionRing k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- The centroid of a face of a simplex as the centroid of a subset of the points. -/ @[simp] theorem face_centroid_eq_centroid {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) : Finset.univ.centroid k (s.face h).points = fs.centroid k s.points := by convert (Finset.univ.centroid_map k (fs.orderEmbOfFin h).toEmbedding s.points).symm rw [← Finset.coe_inj, Finset.coe_map, Finset.coe_univ, Set.image_univ] simp /-- Over a characteristic-zero division ring, the centroids given by two subsets of the points of a simplex are equal if and only if those faces are given by the same subset of points. -/ @[simp] theorem centroid_eq_iff [CharZero k] {n : ℕ} (s : Simplex k P n) {fs₁ fs₂ : Finset (Fin (n + 1))} {m₁ m₂ : ℕ} (h₁ : #fs₁ = m₁ + 1) (h₂ : #fs₂ = m₂ + 1) : fs₁.centroid k s.points = fs₂.centroid k s.points ↔ fs₁ = fs₂ := by refine ⟨fun h => ?_, @congrArg _ _ fs₁ fs₂ (fun z => Finset.centroid k z s.points)⟩ rw [Finset.centroid_eq_affineCombination_fintype, Finset.centroid_eq_affineCombination_fintype] at h have ha := (affineIndependent_iff_indicator_eq_of_affineCombination_eq k s.points).1 s.independent _ _ _ _ (fs₁.sum_centroidWeightsIndicator_eq_one_of_card_eq_add_one k h₁) (fs₂.sum_centroidWeightsIndicator_eq_one_of_card_eq_add_one k h₂) h simp_rw [Finset.coe_univ, Set.indicator_univ, funext_iff, Finset.centroidWeightsIndicator_def, Finset.centroidWeights, h₁, h₂] at ha ext i specialize ha i have key : ∀ n : ℕ, (n : k) + 1 ≠ 0 := fun n h => by norm_cast at h -- we should be able to golf this to -- `refine ⟨fun hi ↦ decidable.by_contradiction (fun hni ↦ ?_), ...⟩`, -- but for some unknown reason it doesn't work. constructor <;> intro hi <;> by_contra hni · simp [hni, hi, key] at ha · simpa [hni, hi, key] using ha.symm /-- Over a characteristic-zero division ring, the centroids of two faces of a simplex are equal if and only if those faces are given by the same subset of points. -/ theorem face_centroid_eq_iff [CharZero k] {n : ℕ} (s : Simplex k P n) {fs₁ fs₂ : Finset (Fin (n + 1))} {m₁ m₂ : ℕ} (h₁ : #fs₁ = m₁ + 1) (h₂ : #fs₂ = m₂ + 1) : Finset.univ.centroid k (s.face h₁).points = Finset.univ.centroid k (s.face h₂).points ↔ fs₁ = fs₂ := by rw [face_centroid_eq_centroid, face_centroid_eq_centroid] exact s.centroid_eq_iff h₁ h₂ /-- Two simplices with the same points have the same centroid. -/ theorem centroid_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex k P n} (h : Set.range s₁.points = Set.range s₂.points) : Finset.univ.centroid k s₁.points = Finset.univ.centroid k s₂.points := by rw [← Set.image_univ, ← Set.image_univ, ← Finset.coe_univ] at h exact Finset.univ.centroid_eq_of_inj_on_of_image_eq k _ (fun _ _ _ _ he => AffineIndependent.injective s₁.independent he) (fun _ _ _ _ he => AffineIndependent.injective s₂.independent he) h end Simplex end Affine
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Simplex/Basic.lean
import Mathlib.Data.Finset.Sort import Mathlib.LinearAlgebra.AffineSpace.Independent import Mathlib.LinearAlgebra.AffineSpace.Restrict /-! # Simplex in affine space This file defines n-dimensional simplices in affine space. ## Main definitions * `Simplex` is a bundled type with collection of `n + 1` points in affine space that are affinely independent, where `n` is the dimension of the simplex. * `Triangle` is a simplex with three points, defined as an abbreviation for simplex with `n = 2`. * `face` is a simplex with a subset of the points of the original simplex. ## References * https://en.wikipedia.org/wiki/Simplex -/ noncomputable section open Finset Function Module open scoped Affine namespace Affine variable (k : Type*) {V V₂ V₃ : Type*} (P P₂ P₃ : Type*) variable [Ring k] [AddCommGroup V] [AddCommGroup V₂] [AddCommGroup V₃] variable [Module k V] [Module k V₂] [Module k V₃] variable [AffineSpace V P] [AffineSpace V₂ P₂] [AffineSpace V₃ P₃] /-- A `Simplex k P n` is a collection of `n + 1` affinely independent points. -/ structure Simplex (n : ℕ) where points : Fin (n + 1) → P independent : AffineIndependent k points /-- A `Triangle k P` is a collection of three affinely independent points. -/ abbrev Triangle := Simplex k P 2 namespace Simplex variable {P P₂ P₃} /-- Construct a 0-simplex from a point. -/ def mkOfPoint (p : P) : Simplex k P 0 := have : Subsingleton (Fin (1 + 0)) := by rw [add_zero]; infer_instance ⟨fun _ => p, affineIndependent_of_subsingleton k _⟩ /-- The point in a simplex constructed with `mkOfPoint`. -/ @[simp] theorem mkOfPoint_points (p : P) (i : Fin 1) : (mkOfPoint k p).points i = p := rfl instance [Inhabited P] : Inhabited (Simplex k P 0) := ⟨mkOfPoint k default⟩ instance nonempty : Nonempty (Simplex k P 0) := ⟨mkOfPoint k <| AddTorsor.nonempty.some⟩ -- Although `simp` can prove this, it is still useful as a `simp` lemma, since the `simp`-generated -- proof uses `range_eq_singleton_iff`, which does not apply when the LHS of this lemma appears -- as part of a more complicated expression. /-- The set of points in a simplex constructed with `mkOfPoint`. -/ @[simp] lemma range_mkOfPoint_points (p : P) : Set.range (mkOfPoint k p).points = {p} := by simp variable {k} /-- Two simplices are equal if they have the same points. -/ @[ext] theorem ext {n : ℕ} {s1 s2 : Simplex k P n} (h : ∀ i, s1.points i = s2.points i) : s1 = s2 := by cases s1 cases s2 congr with i exact h i /-- Two simplices are equal if and only if they have the same points. -/ add_decl_doc Affine.Simplex.ext_iff /-- A face of a simplex is a simplex with the given subset of points. -/ def face {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) : Simplex k P m := ⟨s.points ∘ fs.orderEmbOfFin h, s.independent.comp_embedding (fs.orderEmbOfFin h).toEmbedding⟩ /-- The points of a face of a simplex are given by `mono_of_fin`. -/ theorem face_points {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) (i : Fin (m + 1)) : (s.face h).points i = s.points (fs.orderEmbOfFin h i) := rfl /-- The points of a face of a simplex are given by `mono_of_fin`. -/ theorem face_points' {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) : (s.face h).points = s.points ∘ fs.orderEmbOfFin h := rfl /-- A single-point face equals the 0-simplex constructed with `mkOfPoint`. -/ @[simp] theorem face_eq_mkOfPoint {n : ℕ} (s : Simplex k P n) (i : Fin (n + 1)) : s.face (Finset.card_singleton i) = mkOfPoint k (s.points i) := by ext simp [Affine.Simplex.mkOfPoint_points, Affine.Simplex.face_points, Finset.orderEmbOfFin_singleton] /-- The set of points of a face. -/ @[simp] theorem range_face_points {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) : Set.range (s.face h).points = s.points '' ↑fs := by rw [face_points', Set.range_comp, Finset.range_orderEmbOfFin] /-- The face of a simplex with all but one point. -/ def faceOpposite {n : ℕ} [NeZero n] (s : Simplex k P n) (i : Fin (n + 1)) : Simplex k P (n - 1) := s.face (fs := {i}ᶜ) (by simp [card_compl, NeZero.one_le]) @[simp] lemma range_faceOpposite_points {n : ℕ} [NeZero n] (s : Simplex k P n) (i : Fin (n + 1)) : Set.range (s.faceOpposite i).points = s.points '' {i}ᶜ := by simp [faceOpposite] lemma faceOpposite_point_eq_point_succAbove {n : ℕ} [NeZero n] (s : Simplex k P n) (i : Fin (n + 1)) (j : Fin (n - 1 + 1)) : (s.faceOpposite i).points j = s.points (Fin.succAbove i (Fin.cast (Nat.sub_one_add_one (NeZero.ne _)) j)) := by simp_rw [faceOpposite, face, comp_apply, Finset.orderEmbOfFin_compl_singleton_apply] lemma faceOpposite_point_eq_point_rev (s : Simplex k P 1) (i : Fin 2) (n : Fin 1) : (s.faceOpposite i).points n = s.points i.rev := by have h : i.rev = Fin.succAbove i n := by decide +revert simp [h, faceOpposite_point_eq_point_succAbove] @[simp] lemma faceOpposite_point_eq_point_one (s : Simplex k P 1) (n : Fin 1) : (s.faceOpposite 0).points n = s.points 1 := s.faceOpposite_point_eq_point_rev _ _ @[simp] lemma faceOpposite_point_eq_point_zero (s : Simplex k P 1) (n : Fin 1) : (s.faceOpposite 1).points n = s.points 0 := s.faceOpposite_point_eq_point_rev _ _ /-- Needed to make `affineSpan (s.points '' {i}ᶜ)` nonempty. -/ instance {α} [Nontrivial α] (i : α) : Nonempty ({i}ᶜ : Set _) := (Set.nonempty_compl_of_nontrivial i).to_subtype @[simp] lemma mem_affineSpan_image_iff [Nontrivial k] {n : ℕ} (s : Simplex k P n) {fs : Set (Fin (n + 1))} {i : Fin (n + 1)} : s.points i ∈ affineSpan k (s.points '' fs) ↔ i ∈ fs := s.independent.mem_affineSpan_iff _ _ @[deprecated mem_affineSpan_image_iff (since := "2025-05-18")] lemma mem_affineSpan_range_face_points_iff [Nontrivial k] {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) {i : Fin (n + 1)} : s.points i ∈ affineSpan k (Set.range (s.face h).points) ↔ i ∈ fs := by simp @[deprecated mem_affineSpan_image_iff (since := "2025-05-18")] lemma mem_affineSpan_range_faceOpposite_points_iff [Nontrivial k] {n : ℕ} [NeZero n] (s : Simplex k P n) {i j : Fin (n + 1)} : s.points i ∈ affineSpan k (Set.range (s.faceOpposite j).points) ↔ i ≠ j := by simp /-- Push forward an affine simplex under an injective affine map. -/ @[simps -fullyApplied] def map {n : ℕ} (s : Affine.Simplex k P n) (f : P →ᵃ[k] P₂) (hf : Function.Injective f) : Affine.Simplex k P₂ n where points := f ∘ s.points independent := s.independent.map' f hf @[simp] theorem map_id {n : ℕ} (s : Affine.Simplex k P n) : s.map (AffineMap.id _ _) Function.injective_id = s := ext fun _ => rfl theorem map_comp {n : ℕ} (s : Affine.Simplex k P n) (f : P →ᵃ[k] P₂) (hf : Function.Injective f) (g : P₂ →ᵃ[k] P₃) (hg : Function.Injective g) : s.map (g.comp f) (hg.comp hf) = (s.map f hf).map g hg := ext fun _ => rfl @[simp] theorem face_map {n : ℕ} (s : Simplex k P n) (f : P →ᵃ[k] P₂) (hf : Function.Injective f) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) : (s.map f hf).face h = (s.face h).map f hf := rfl @[simp] theorem faceOpposite_map {n : ℕ} [NeZero n] (s : Simplex k P n) (f : P →ᵃ[k] P₂) (hf : Function.Injective f) (i : Fin (n + 1)) : (s.map f hf).faceOpposite i = (s.faceOpposite i).map f hf := rfl @[simp] theorem map_mkOfPoint (f : P →ᵃ[k] P₂) (hf : Function.Injective f) (p : P) : (mkOfPoint k p).map f hf = mkOfPoint k (f p) := rfl /-- Remap a simplex along an `Equiv` of index types. -/ @[simps] def reindex {m n : ℕ} (s : Simplex k P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : Simplex k P n := ⟨s.points ∘ e.symm, (affineIndependent_equiv e.symm).2 s.independent⟩ /-- Reindexing by `Equiv.refl` yields the original simplex. -/ @[simp] theorem reindex_refl {n : ℕ} (s : Simplex k P n) : s.reindex (Equiv.refl (Fin (n + 1))) = s := ext fun _ => rfl /-- Reindexing by the composition of two equivalences is the same as reindexing twice. -/ @[simp] theorem reindex_trans {n₁ n₂ n₃ : ℕ} (e₁₂ : Fin (n₁ + 1) ≃ Fin (n₂ + 1)) (e₂₃ : Fin (n₂ + 1) ≃ Fin (n₃ + 1)) (s : Simplex k P n₁) : s.reindex (e₁₂.trans e₂₃) = (s.reindex e₁₂).reindex e₂₃ := rfl /-- Reindexing by an equivalence and its inverse yields the original simplex. -/ @[simp] theorem reindex_reindex_symm {m n : ℕ} (s : Simplex k P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).reindex e.symm = s := by rw [← reindex_trans, Equiv.self_trans_symm, reindex_refl] /-- Reindexing by the inverse of an equivalence and that equivalence yields the original simplex. -/ @[simp] theorem reindex_symm_reindex {m n : ℕ} (s : Simplex k P m) (e : Fin (n + 1) ≃ Fin (m + 1)) : (s.reindex e.symm).reindex e = s := by rw [← reindex_trans, Equiv.symm_trans_self, reindex_refl] /-- Reindexing a simplex produces one with the same set of points. -/ @[simp] theorem reindex_range_points {m n : ℕ} (s : Simplex k P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : Set.range (s.reindex e).points = Set.range s.points := by rw [reindex, Set.range_comp, Equiv.range_eq_univ, Set.image_univ] theorem reindex_map {m n : ℕ} (s : Simplex k P m) (e : Fin (m + 1) ≃ Fin (n + 1)) (f : P →ᵃ[k] P₂) (hf : Function.Injective f) : (s.map f hf).reindex e = (s.reindex e).map f hf := rfl section restrict /-- Restrict an affine simplex to an affine subspace that contains it. -/ @[simps] def restrict {n : ℕ} (s : Affine.Simplex k P n) (S : AffineSubspace k P) (hS : affineSpan k (Set.range s.points) ≤ S) : letI := Nonempty.map (AffineSubspace.inclusion hS) inferInstance Affine.Simplex (V := S.direction) k S n := letI := Nonempty.map (AffineSubspace.inclusion hS) inferInstance { points i := ⟨s.points i, hS <| mem_affineSpan _ <| Set.mem_range_self _⟩ independent := AffineIndependent.of_comp S.subtype s.independent } /-- Restricting to `S₁` then mapping to a larger `S₂` is the same as restricting to `S₂`. -/ @[simp] theorem restrict_map_inclusion {n : ℕ} (s : Affine.Simplex k P n) (S₁ S₂ : AffineSubspace k P) (hS₁) (hS₂ : S₁ ≤ S₂) : letI := Nonempty.map (AffineSubspace.inclusion hS₁) inferInstance letI := Nonempty.map (Set.inclusion hS₂) ‹_› (s.restrict S₁ hS₁).map (AffineSubspace.inclusion hS₂) (Set.inclusion_injective hS₂) = s.restrict S₂ (hS₁.trans hS₂) := rfl @[simp] theorem map_subtype_restrict {n : ℕ} (S : AffineSubspace k P) [Nonempty S] (s : Affine.Simplex k S n) : (s.map (AffineSubspace.subtype _) Subtype.coe_injective).restrict S (affineSpan_le.2 <| by rintro x ⟨y, rfl⟩; exact Subtype.prop _) = s := by rfl /-- Restricting to `S₁` then mapping through the restriction of `f` to `S₁ →ᵃ[k] S₂` is the same as mapping through unrestricted `f`, then restricting to `S₂`. -/ theorem restrict_map_restrict {n : ℕ} (s : Affine.Simplex k P n) (f : P →ᵃ[k] P₂) (hf : Function.Injective f) (S₁ : AffineSubspace k P) (S₂ : AffineSubspace k P₂) (hS₁ : affineSpan k (Set.range s.points) ≤ S₁) (hfS : AffineSubspace.map f S₁ ≤ S₂) : letI := Nonempty.map (AffineSubspace.inclusion hS₁) inferInstance letI := Nonempty.map (AffineSubspace.inclusion hfS) inferInstance (s.restrict S₁ hS₁).map (f.restrict hfS) (AffineMap.restrict.injective hf _) = (s.map f hf).restrict S₂ ( Eq.trans_le (by simp [AffineSubspace.map_span, Set.range_comp]) (AffineSubspace.map_mono f hS₁) |>.trans hfS) := by rfl /-- Restricting to `affineSpan k (Set.range s.points)` can be reversed by mapping through `AffineSubspace.subtype`. -/ @[simp] theorem restrict_map_subtype {n : ℕ} (s : Affine.Simplex k P n) : (s.restrict _ le_rfl).map (AffineSubspace.subtype _) Subtype.coe_injective = s := rfl lemma restrict_reindex {m n : ℕ} (s : Affine.Simplex k P n) (e : Fin (n + 1) ≃ Fin (m + 1)) {S : AffineSubspace k P} (hS : affineSpan k (Set.range s.points) ≤ S) : letI := Nonempty.map (AffineSubspace.inclusion hS) inferInstance (s.reindex e).restrict S (s.reindex_range_points e ▸ hS) = (s.restrict S hS).reindex e := rfl end restrict end Simplex end Affine namespace Affine namespace Simplex variable {k V P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- The interior of a simplex is the set of points that can be expressed as an affine combination of the vertices with weights in a set `I`. -/ protected def setInterior (I : Set k) {n : ℕ} (s : Simplex k P n) : Set P := {p | ∃ w : Fin (n + 1) → k, (∑ i, w i = 1) ∧ (∀ i, w i ∈ I) ∧ Finset.univ.affineCombination k s.points w = p} lemma affineCombination_mem_setInterior_iff {I : Set k} {n : ℕ} {s : Simplex k P n} {w : Fin (n + 1) → k} (hw : ∑ i, w i = 1) : Finset.univ.affineCombination k s.points w ∈ s.setInterior I ↔ ∀ i, w i ∈ I := by refine ⟨fun ⟨w', hw', hw'01, hww'⟩ ↦ ?_, fun h ↦ ⟨w, hw, h, rfl⟩⟩ simp_rw [← (affineIndependent_iff_eq_of_fintype_affineCombination_eq k s.points).1 s.independent w' w hw' hw hww'] exact hw'01 @[simp] lemma setInterior_reindex (I : Set k) {m n : ℕ} (s : Simplex k P n) (e : Fin (n + 1) ≃ Fin (m + 1)) : (s.reindex e).setInterior I = s.setInterior I := by ext p refine ⟨fun ⟨w, hw, hwI, h⟩ ↦ ?_, fun ⟨w, hw, hwI, h⟩ ↦ ?_⟩ · subst h simp_rw [reindex] rw [← Function.comp_id w, ← e.self_comp_symm, ← Function.comp_assoc, ← Equiv.coe_toEmbedding, ← Finset.univ.affineCombination_map e.symm.toEmbedding, map_univ_equiv] have hw' : ∑ i, (w ∘ e) i = 1 := by rwa [sum_comp_equiv, map_univ_equiv] rw [affineCombination_mem_setInterior_iff hw'] exact fun i ↦ hwI (e i) · subst h rw [← Function.comp_id w, ← Function.comp_id s.points, ← e.symm_comp_self, ← Function.comp_assoc, ← Function.comp_assoc, ← e.coe_toEmbedding, ← Finset.univ.affineCombination_map e.toEmbedding, map_univ_equiv] change Finset.univ.affineCombination k (s.reindex e).points _ ∈ _ have hw' : ∑ i, (w ∘ e.symm) i = 1 := by rwa [sum_comp_equiv, map_univ_equiv] rw [affineCombination_mem_setInterior_iff hw'] exact fun i ↦ hwI (e.symm i) lemma setInterior_mono {I J : Set k} (hij : I ⊆ J) {n : ℕ} (s : Simplex k P n) : s.setInterior I ⊆ s.setInterior J := fun _ ⟨w, hw, hw01, hww⟩ ↦ ⟨w, hw, fun i ↦ hij (hw01 i), hww⟩ lemma setInterior_subset_affineSpan {I : Set k} {n : ℕ} {s : Simplex k P n} : s.setInterior I ⊆ affineSpan k (Set.range s.points) := by rintro p ⟨w, hw, hi, rfl⟩ exact affineCombination_mem_affineSpan_of_nonempty hw _ variable [PartialOrder k] /-- The interior of a simplex is the set of points that can be expressed as an affine combination of the vertices with weights strictly between 0 and 1. This is equivalent to the intrinsic interior of the convex hull of the vertices. -/ protected def interior {n : ℕ} (s : Simplex k P n) : Set P := s.setInterior (Set.Ioo 0 1) @[simp] lemma interior_reindex {m n : ℕ} (s : Simplex k P n) (e : Fin (n + 1) ≃ Fin (m + 1)) : (s.reindex e).interior = s.interior := s.setInterior_reindex _ _ lemma affineCombination_mem_interior_iff {n : ℕ} {s : Simplex k P n} {w : Fin (n + 1) → k} (hw : ∑ i, w i = 1) : Finset.univ.affineCombination k s.points w ∈ s.interior ↔ ∀ i, w i ∈ Set.Ioo 0 1 := affineCombination_mem_setInterior_iff hw /-- `s.closedInterior` is the set of points that can be expressed as an affine combination of the vertices with weights between 0 and 1 inclusive. This is equivalent to the convex hull of the vertices or the closure of the interior. -/ protected def closedInterior {n : ℕ} (s : Simplex k P n) : Set P := s.setInterior (Set.Icc 0 1) @[simp] lemma closedInterior_reindex {m n : ℕ} (s : Simplex k P n) (e : Fin (n + 1) ≃ Fin (m + 1)) : (s.reindex e).closedInterior = s.closedInterior := s.setInterior_reindex _ _ lemma affineCombination_mem_closedInterior_iff {n : ℕ} {s : Simplex k P n} {w : Fin (n + 1) → k} (hw : ∑ i, w i = 1) : Finset.univ.affineCombination k s.points w ∈ s.closedInterior ↔ ∀ i, w i ∈ Set.Icc 0 1 := affineCombination_mem_setInterior_iff hw lemma interior_subset_closedInterior {n : ℕ} (s : Simplex k P n) : s.interior ⊆ s.closedInterior := fun _ ⟨w, hw, hw01, hww⟩ ↦ ⟨w, hw, fun i ↦ ⟨(hw01 i).1.le, (hw01 i).2.le⟩, hww⟩ lemma point_notMem_interior {n : ℕ} (s : Simplex k P n) (i : Fin (n + 1)) : s.points i ∉ s.interior := by rw [← Finset.univ.affineCombination_affineCombinationSingleWeights k s.points (Finset.mem_univ i), affineCombination_mem_interior_iff (sum_affineCombinationSingleWeights _ _ (Finset.mem_univ i)), not_forall] exact ⟨i, by simp⟩ lemma point_mem_closedInterior [ZeroLEOneClass k] {n : ℕ} (s : Simplex k P n) (i : Fin (n + 1)) : s.points i ∈ s.closedInterior := by rw [← Finset.univ.affineCombination_affineCombinationSingleWeights k s.points (Finset.mem_univ i), affineCombination_mem_closedInterior_iff (sum_affineCombinationSingleWeights _ _ (Finset.mem_univ i))] intro j by_cases hj : j = i <;> simp [hj] lemma interior_ssubset_closedInterior [ZeroLEOneClass k] {n : ℕ} (s : Simplex k P n) : s.interior ⊂ s.closedInterior := by rw [Set.ssubset_iff_exists] exact ⟨s.interior_subset_closedInterior, s.points 0, s.point_mem_closedInterior 0, s.point_notMem_interior 0⟩ lemma closedInterior_subset_affineSpan {n : ℕ} {s : Simplex k P n} : s.closedInterior ⊆ affineSpan k (Set.range s.points) := by rintro p ⟨w, hw, hi, rfl⟩ exact affineCombination_mem_affineSpan_of_nonempty hw _ @[simp] lemma interior_eq_empty (s : Simplex k P 0) : s.interior = ∅ := by ext p simp only [Simplex.interior, Simplex.setInterior, Nat.reduceAdd, univ_unique, Fin.default_eq_zero, Fin.isValue, sum_singleton, Set.mem_Ioo, Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false, not_exists, not_and] intro w h hi simpa [h] using hi 0 @[simp] lemma closedInterior_eq_singleton [ZeroLEOneClass k] (s : Simplex k P 0) : s.closedInterior = {s.points 0} := by ext p simp only [Simplex.closedInterior, Simplex.setInterior, Nat.reduceAdd, univ_unique, Fin.default_eq_zero, Fin.isValue, sum_singleton, Set.mem_Icc, Set.mem_setOf_eq, Set.mem_singleton_iff] constructor · rintro ⟨w, h0, hi, rfl⟩ simp [affineCombination_apply, h0] · rintro rfl exact ⟨1, by simp [affineCombination_apply]⟩ omit [PartialOrder k] in lemma affineCombination_mem_setInterior_face_iff_mem (I : Set k) {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) {w : Fin (n + 1) → k} (hw : ∑ i, w i = 1) : Finset.univ.affineCombination k s.points w ∈ (s.face h).setInterior I ↔ (∀ i ∈ fs, w i ∈ I) ∧ (∀ i ∉ fs, w i = 0) := by refine ⟨fun hi ↦ ?_, fun ⟨hii, hi0⟩ ↦ ?_⟩ · obtain ⟨w', hw', he⟩ := eq_affineCombination_of_mem_affineSpan_of_fintype (Set.mem_of_mem_of_subset hi setInterior_subset_affineSpan) rw [he, affineCombination_mem_setInterior_iff hw'] at hi have he' := s.independent.indicator_extend_eq_of_affineCombination_comp_embedding_eq_of_fintype hw hw' (fs.orderEmbOfFin h).toEmbedding he.symm simp_rw [he'.symm] refine ⟨fun i hi ↦ ?_, fun i hi ↦ by simp [hi]⟩ simp only [RelEmbedding.coe_toEmbedding, range_orderEmbOfFin, mem_coe, hi, Set.indicator_of_mem] rw [← mem_coe, ← fs.range_orderEmbOfFin h] at hi obtain ⟨j, rfl⟩ := hi simp [(fs.orderEmbOfFin h).injective.extend_apply, hi] · let w' : Fin (m + 1) → k := w ∘ fs.orderEmbOfFin h have hw' : ∑ i, w' i = 1 := by rw [Fintype.sum_of_injective _ (fs.orderEmbOfFin h).injective w' w (fun i hi ↦ hi0 _ (by simpa using hi)) (fun _ ↦ rfl), hw] have hw'01 (i) : w' i ∈ I := hii (fs.orderEmbOfFin h i) (by simp) rw [← (s.face h).affineCombination_mem_setInterior_iff hw'] at hw'01 convert hw'01 convert Finset.univ.affineCombination_map (fs.orderEmbOfFin h).toEmbedding w s.points using 1 simp only [map_orderEmbOfFin_univ, Finset.affineCombination_indicator_subset _ _ fs.subset_univ] congr grind [Set.indicator_eq_self, support_subset_iff] lemma affineCombination_mem_interior_face_iff_mem_Ioo {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) {w : Fin (n + 1) → k} (hw : ∑ i, w i = 1) : Finset.univ.affineCombination k s.points w ∈ (s.face h).interior ↔ (∀ i ∈ fs, w i ∈ Set.Ioo 0 1) ∧ (∀ i ∉ fs, w i = 0) := affineCombination_mem_setInterior_face_iff_mem _ _ _ hw lemma affineCombination_mem_closedInterior_face_iff_mem_Icc {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) {w : Fin (n + 1) → k} (hw : ∑ i, w i = 1) : Finset.univ.affineCombination k s.points w ∈ (s.face h).closedInterior ↔ (∀ i ∈ fs, w i ∈ Set.Icc 0 1) ∧ (∀ i ∉ fs, w i = 0) := affineCombination_mem_setInterior_face_iff_mem _ _ _ hw lemma affineCombination_mem_interior_face_iff_pos [IsOrderedAddMonoid k] {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ} [NeZero m] (h : #fs = m + 1) {w : Fin (n + 1) → k} (hw : ∑ i, w i = 1) : Finset.univ.affineCombination k s.points w ∈ (s.face h).interior ↔ (∀ i ∈ fs, 0 < w i) ∧ (∀ i ∉ fs, w i = 0) := by rw [s.affineCombination_mem_interior_face_iff_mem_Ioo h hw] refine ⟨by grind, fun ⟨hii, hi0⟩ ↦ ⟨fun i hi ↦ ⟨hii i hi, ?_⟩, hi0⟩⟩ rw [← hw, ← Finset.sum_subset (Finset.subset_univ fs) fun j _ ↦ hi0 j] obtain ⟨j, hj, hji⟩ := fs.exists_mem_ne (by grind [→ NeZero.ne]) i exact Finset.single_lt_sum hji hi hj (hii j hj) fun t ht _ ↦ (hii t ht).le lemma affineCombination_mem_closedInterior_face_iff_nonneg [IsOrderedAddMonoid k] {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : #fs = m + 1) {w : Fin (n + 1) → k} (hw : ∑ i, w i = 1) : Finset.univ.affineCombination k s.points w ∈ (s.face h).closedInterior ↔ (∀ i ∈ fs, 0 ≤ w i) ∧ (∀ i ∉ fs, w i = 0) := by rw [s.affineCombination_mem_closedInterior_face_iff_mem_Icc h hw] refine ⟨by grind, fun ⟨hii, hi0⟩ ↦ ⟨fun i hi ↦ ⟨hii i hi, ?_⟩, hi0⟩⟩ rw [← hw, ← Finset.sum_subset (Finset.subset_univ fs) fun j _ ↦ hi0 j] exact Finset.single_le_sum (fun t ht ↦ (hii t ht)) hi end Simplex end Affine
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/RootPositive.lean
import Mathlib.LinearAlgebra.RootSystem.IsValuedIn /-! # Invariant and root-positive bilinear forms on root pairings This file contains basic results on Weyl-invariant inner products for root systems and root data. Given a root pairing we define a structure which contains a bilinear form together with axioms for reflection-invariance, symmetry, and strict positivity on all roots. We show that root-positive forms display the same sign behavior as the canonical pairing between roots and coroots. Root-positive forms show up naturally as the invariant forms for symmetrizable Kac-Moody Lie algebras. In the finite case, the canonical polarization yields a root-positive form that is positive semi-definite on weight space and positive-definite on the span of roots. ## Main definitions / results: * `RootPairing.InvariantForm`: an invariant bilinear form on a root pairing. * `RootPairing.RootPositiveForm`: Given a root pairing this is a structure which contains a bilinear form together with axioms for reflection-invariance, symmetry, and strict positivity on all roots. * `RootPairing.zero_lt_pairingIn_iff`: sign relations between `RootPairing.pairingIn` and a root-positive form. * `RootPairing.pairing_eq_zero_iff`: symmetric vanishing condition for `RootPairing.pairing` * `RootPairing.coxeterWeight_nonneg`: All pairs of roots have non-negative Coxeter weight. * `RootPairing.coxeterWeight_zero_iff_isOrthogonal` : A Coxeter weight vanishes iff the roots are orthogonal. -/ noncomputable section open FaithfulSMul Function Set Submodule variable {ι R S M N : Type*} [CommRing S] [LinearOrder S] [CommRing R] [Algebra S R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] namespace RootPairing /-- Given a root pairing, this is an invariant symmetric bilinear form. -/ structure InvariantForm (P : RootPairing ι R M N) where /-- The bilinear form bundled inside an `InvariantForm`. -/ form : LinearMap.BilinForm R M symm : form.IsSymm ne_zero (i : ι) : form (P.root i) (P.root i) ≠ 0 isOrthogonal_reflection (i : ι) : form.IsOrthogonal (P.reflection i) namespace InvariantForm variable {P : RootPairing ι R M N} (B : P.InvariantForm) (i j : ι) lemma apply_root_ne_zero : B.form (P.root i) ≠ 0 := fun contra ↦ B.ne_zero i <| by simp [contra] lemma two_mul_apply_root_root : 2 * B.form (P.root i) (P.root j) = P.pairing i j * B.form (P.root j) (P.root j) := by rw [two_mul, ← eq_sub_iff_add_eq] nth_rw 1 [← B.isOrthogonal_reflection j] rw [reflection_apply, reflection_apply_self, root_coroot'_eq_pairing, LinearMap.map_sub₂, LinearMap.map_smul₂, smul_eq_mul, LinearMap.map_neg, LinearMap.map_neg, mul_neg, neg_sub_neg] lemma pairing_mul_eq_pairing_mul_swap : P.pairing j i * B.form (P.root i) (P.root i) = P.pairing i j * B.form (P.root j) (P.root j) := by rw [← B.two_mul_apply_root_root i j, ← B.two_mul_apply_root_root j i, ← B.symm.eq, RingHom.id_apply] @[simp] lemma apply_reflection_reflection (x y : M) : B.form (P.reflection i x) (P.reflection i y) = B.form x y := B.isOrthogonal_reflection i x y @[simp] lemma apply_root_root_zero_iff [IsDomain R] [NeZero (2 : R)] : B.form (P.root i) (P.root j) = 0 ↔ P.pairing i j = 0 := by calc B.form (P.root i) (P.root j) = 0 ↔ 2 * B.form (P.root i) (P.root j) = 0 := by simp [two_ne_zero] _ ↔ P.pairing i j * B.form (P.root j) (P.root j) = 0 := by rw [B.two_mul_apply_root_root i j] _ ↔ P.pairing i j = 0 := by simp [B.ne_zero j] end InvariantForm variable (S) in /-- Given a root pairing, this is an invariant symmetric bilinear form satisfying a positivity condition. -/ structure RootPositiveForm (P : RootPairing ι R M N) [P.IsValuedIn S] where /-- The bilinear form bundled inside a `RootPositiveForm`. -/ form : LinearMap.BilinForm R M symm : form.IsSymm isOrthogonal_reflection (i : ι) : form.IsOrthogonal (P.reflection i) exists_eq (i j : ι) : ∃ s, algebraMap S R s = form (P.root i) (P.root j) exists_pos_eq (i : ι) : ∃ s > 0, algebraMap S R s = form (P.root i) (P.root i) variable {P : RootPairing ι R M N} [P.IsValuedIn S] (B : P.RootPositiveForm S) (i j : ι) [FaithfulSMul S R] [Module S M] [IsScalarTower S R M] namespace RootPositiveForm omit [Module S M] [IsScalarTower S R M] in lemma form_apply_root_ne_zero (i : ι) : B.form (P.root i) (P.root i) ≠ 0 := by obtain ⟨s, hs, hs'⟩ := B.exists_pos_eq i simpa [← hs'] using hs.ne' /-- Forgetting the positivity condition, we may regard a `RootPositiveForm` as an `InvariantForm`. -/ @[simps] def toInvariantForm : InvariantForm P where form := B.form symm := B.symm ne_zero := B.form_apply_root_ne_zero isOrthogonal_reflection := B.isOrthogonal_reflection omit [Module S M] [IsScalarTower S R M] in lemma two_mul_apply_root_root : 2 * B.form (P.root i) (P.root j) = P.pairing i j * B.form (P.root j) (P.root j) := B.toInvariantForm.two_mul_apply_root_root i j /-- Given a root-positive form associated to a root pairing with coefficients in `R` but taking values in `S`, this is the associated `S`-bilinear form on the `S`-span of the roots. -/ def posForm : LinearMap.BilinForm S (span S (range P.root)) := LinearMap.restrictScalarsRange₂ (span S (range P.root)).subtype (span S (range P.root)).subtype (Algebra.linearMap S R) (FaithfulSMul.algebraMap_injective S R) B.form (fun ⟨x, hx⟩ ⟨y, hy⟩ ↦ by apply LinearMap.BilinMap.apply_apply_mem_of_mem_span (s := range P.root) (t := range P.root) (B := (LinearMap.restrictScalarsₗ S R _ _ _).comp (B.form.restrictScalars S)) · rintro - ⟨i, rfl⟩ - ⟨j, rfl⟩ simpa using B.exists_eq i j · simpa · simpa) @[simp] lemma algebraMap_posForm {x y : span S (range P.root)} : algebraMap S R (B.posForm x y) = B.form x y := by change Algebra.linearMap S R _ = _ simp [posForm] lemma algebraMap_apply_eq_form_iff {x y : span S (range P.root)} {s : S} : algebraMap S R s = B.form x y ↔ s = B.posForm x y := by simp [RootPositiveForm.posForm] lemma zero_lt_posForm_iff {x y : span S (range P.root)} : 0 < B.posForm x y ↔ ∃ s > 0, algebraMap S R s = B.form x y := by refine ⟨fun h ↦ ⟨B.posForm x y, h, by simp⟩, fun ⟨s, h, h'⟩ ↦ ?_⟩ rw [← B.algebraMap_posForm] at h' rwa [← FaithfulSMul.algebraMap_injective S R h'] lemma zero_lt_posForm_apply_root (i : ι) (hi : P.root i ∈ span S (range P.root) := subset_span (mem_range_self i)) : 0 < B.posForm ⟨P.root i, hi⟩ ⟨P.root i, hi⟩ := by simpa only [zero_lt_posForm_iff] using B.exists_pos_eq i lemma isSymm_posForm : B.posForm.IsSymm where eq x y := by apply FaithfulSMul.algebraMap_injective S R simpa using B.symm.eq x y /-- The length of the `i`-th root w.r.t. a root-positive form taking values in `S`. -/ def rootLength (i : ι) : S := B.posForm (P.rootSpanMem S i) (P.rootSpanMem S i) lemma rootLength_pos (i : ι) : 0 < B.rootLength i := by simpa using B.zero_lt_posForm_apply_root i @[simp] lemma rootLength_reflectionPerm_self (i : ι) : B.rootLength (P.reflectionPerm i i) = B.rootLength i := by simp [rootLength, rootSpanMem_reflectionPerm_self] @[deprecated (since := "2025-05-28")] alias rootLength_reflection_perm_self := rootLength_reflectionPerm_self @[simp] lemma algebraMap_rootLength (i : ι) : algebraMap S R (B.rootLength i) = B.form (P.root i) (P.root i) := by simp [rootLength] lemma pairingIn_mul_eq_pairingIn_mul_swap : P.pairingIn S j i * B.rootLength i = P.pairingIn S i j * B.rootLength j := by simpa only [← (algebraMap_injective S R).eq_iff, algebraMap_pairingIn, map_mul, B.algebraMap_rootLength] using B.toInvariantForm.pairing_mul_eq_pairing_mul_swap i j @[simp] lemma zero_lt_apply_root_root_iff [IsStrictOrderedRing S] (hi : P.root i ∈ span S (range P.root) := subset_span (mem_range_self i)) (hj : P.root j ∈ span S (range P.root) := subset_span (mem_range_self j)) : 0 < B.posForm ⟨P.root i, hi⟩ ⟨P.root j, hj⟩ ↔ 0 < P.pairingIn S i j := by let ri : span S (range P.root) := ⟨P.root i, hi⟩ let rj : span S (range P.root) := ⟨P.root j, hj⟩ have : 2 * B.posForm ri rj = P.pairingIn S i j * B.posForm rj rj := by apply FaithfulSMul.algebraMap_injective S R simpa [map_ofNat] using B.toInvariantForm.two_mul_apply_root_root i j calc 0 < B.posForm ri rj ↔ 0 < 2 * B.posForm ri rj := by rw [mul_pos_iff_of_pos_left zero_lt_two] _ ↔ 0 < P.pairingIn S i j * B.posForm rj rj := by rw [this] _ ↔ 0 < P.pairingIn S i j := by rw [mul_pos_iff_of_pos_right (B.zero_lt_posForm_apply_root j)] end RootPositiveForm include B lemma zero_lt_pairingIn_iff [IsStrictOrderedRing S] : 0 < P.pairingIn S i j ↔ 0 < P.pairingIn S j i := by rw [← B.zero_lt_apply_root_root_iff, ← B.isSymm_posForm.eq, RingHom.id_apply, B.zero_lt_apply_root_root_iff] lemma coxeterWeight_nonneg [IsStrictOrderedRing S] : 0 ≤ P.coxeterWeightIn S i j := by dsimp [coxeterWeightIn] rcases lt_or_ge 0 (P.pairingIn S i j) with h | h · exact le_of_lt <| mul_pos h ((zero_lt_pairingIn_iff B i j).mp h) · have hn : P.pairingIn S j i ≤ 0 := by rwa [← not_lt, ← zero_lt_pairingIn_iff B i j, not_lt] exact mul_nonneg_of_nonpos_of_nonpos h hn end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/Chain.lean
import Mathlib.LinearAlgebra.RootSystem.Finite.Lemmas import Mathlib.Order.Interval.Set.OrdConnectedLinear /-! # Chains of roots Given roots `α` and `β`, the `α`-chain through `β` is the set of roots of the form `α + z • β` for an integer `z`. This is known as a "root chain" and also a "root string". For linearly independent roots in finite crystallographic root pairings, these chains are always unbroken, i.e., of the form: `β - q • α, ..., β - α, β, β + α, ..., β + p • α` for natural numbers `p`, `q`, and the length, `p + q` is at most 3. ## Main definitions / results: * `RootPairing.chainTopCoeff`: the natural number `p` in the chain `β - q • α, ..., β - α, β, β + α, ..., β + p • α` * `RootPairing.chainTopCoeff`: the natural number `q` in the chain `β - q • α, ..., β - α, β, β + α, ..., β + p • α` * `RootPairing.root_add_zsmul_mem_range_iff`: every chain is an interval (aka unbroken). * `RootPairing.chainBotCoeff_add_chainTopCoeff_le`: every chain has length at most three. -/ noncomputable section open FaithfulSMul Function Set Submodule variable {ι R M N : Type*} [Finite ι] [CommRing R] [CharZero R] [IsDomain R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] namespace RootPairing variable {P : RootPairing ι R M N} [P.IsCrystallographic] {i j : ι} /-- Note that it is often more convenient to use `RootPairing.root_add_zsmul_mem_range_iff` than to invoke this lemma directly. -/ lemma setOf_root_add_zsmul_eq_Icc_of_linearIndependent (h : LinearIndependent R ![P.root i, P.root j]) : ∃ᵉ (q ≤ 0) (p ≥ 0), {z : ℤ | P.root j + z • P.root i ∈ range P.root} = Icc q p := by replace h := LinearIndependent.pair_iff.mp <| h.restrict_scalars' ℤ set S : Set ℤ := {z | P.root j + z • P.root i ∈ range P.root} with S_def have hS₀ : 0 ∈ S := by simp [S] have h_fin : S.Finite := by suffices Injective (fun z : S ↦ z.property.choose) from Finite.of_injective _ this intro ⟨z, hz⟩ ⟨z', hz'⟩ hzz have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M have : z • P.root i = z' • P.root i := by rwa [← add_right_inj (P.root j), ← hz.choose_spec, ← hz'.choose_spec, P.root.injective.eq_iff] exact Subtype.ext <| smul_left_injective ℤ (P.ne_zero i) this have h_ne : S.Nonempty := ⟨0, by simp [S_def]⟩ refine ⟨sInf S, csInf_le h_fin.bddBelow hS₀, sSup S, le_csSup h_fin.bddAbove hS₀, (h_ne.eq_Icc_iff_int h_fin.bddBelow h_fin.bddAbove).mpr fun r ⟨k, hk⟩ s ⟨l, hl⟩ hrs ↦ ?_⟩ by_contra! contra have hki_notMem : P.root k + P.root i ∉ range P.root := by replace hk : P.root k + P.root i = P.root j + (r + 1) • P.root i := by rw [hk]; module replace contra : r + 1 ∉ S := hrs.notMem_of_mem_left <| by simp [contra] simpa only [hk, S_def, mem_setOf_eq, S] using contra have hki_ne : P.root k ≠ -P.root i := by rw [hk] contrapose! h replace h : r • P.root i = - P.root j - P.root i := by rw [← sub_eq_of_eq_add h.symm]; module exact ⟨r + 1, 1, by simp [add_smul, h], by cutsat⟩ have hli_notMem : P.root l - P.root i ∉ range P.root := by replace hl : P.root l - P.root i = P.root j + (s - 1) • P.root i := by rw [hl]; module replace contra : s - 1 ∉ S := hrs.notMem_of_mem_left <| by simp [lt_sub_right_of_add_lt contra] simpa only [hl, S_def, mem_setOf_eq, S] using contra have hli_ne : P.root l ≠ P.root i := by rw [hl] contrapose! h replace h : s • P.root i = P.root i - P.root j := by rw [← sub_eq_of_eq_add h.symm]; module exact ⟨s - 1, 1, by simp [sub_smul, h], by cutsat⟩ have h₁ : 0 ≤ P.pairingIn ℤ k i := by have := P.root_add_root_mem_of_pairingIn_neg (i := k) (j := i) contrapose! this exact ⟨this, hki_ne, hki_notMem⟩ have h₂ : P.pairingIn ℤ k i = P.pairingIn ℤ j i + r * 2 := by apply algebraMap_injective ℤ R rw [algebraMap_pairingIn, map_add, map_mul, algebraMap_pairingIn, ← root_coroot'_eq_pairing, hk] simp have h₃ : P.pairingIn ℤ l i ≤ 0 := by have := P.root_sub_root_mem_of_pairingIn_pos (i := l) (j := i) contrapose! this exact ⟨this, fun x ↦ hli_ne (congrArg P.root x), hli_notMem⟩ have h₄ : P.pairingIn ℤ l i = P.pairingIn ℤ j i + s * 2 := by apply algebraMap_injective ℤ R rw [algebraMap_pairingIn, map_add, map_mul, algebraMap_pairingIn, ← root_coroot'_eq_pairing, hl] simp cutsat variable (i j) open scoped Classical in /-- If `α = P.root i` and `β = P.root j` are linearly independent, this is the value `p ≥ 0` where `β - q • α, ..., β - α, β, β + α, ..., β + p • α` is the `α`-chain through `β`. In the absence of linear independence, it takes a junk value. -/ def chainTopCoeff : ℕ := if h : LinearIndependent R ![P.root i, P.root j] then (P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose_spec.2.choose.toNat else 0 open scoped Classical in /-- If `α = P.root i` and `β = P.root j` are linearly independent, this is the value `q ≥ 0` where `β - q • α, ..., β - α, β, β + α, ..., β + p • α` is the `α`-chain through `β`. In the absence of linear independence, it takes a junk value. -/ def chainBotCoeff : ℕ := if h : LinearIndependent R ![P.root i, P.root j] then (-(P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose).toNat else 0 variable {i j} lemma chainTopCoeff_of_not_linearIndependent (h : ¬ LinearIndependent R ![P.root i, P.root j]) : P.chainTopCoeff i j = 0 := by simp only [chainTopCoeff, h, reduceDIte] lemma chainBotCoeff_of_not_linearIndependent (h : ¬ LinearIndependent R ![P.root i, P.root j]) : P.chainBotCoeff i j = 0 := by simp only [chainBotCoeff, h, reduceDIte] variable (h : LinearIndependent R ![P.root i, P.root j]) include h lemma root_add_nsmul_mem_range_iff_le_chainTopCoeff {n : ℕ} : P.root j + n • P.root i ∈ range P.root ↔ n ≤ P.chainTopCoeff i j := by set S : Set ℤ := {z | P.root j + z • P.root i ∈ range P.root} with S_def suffices (n : ℤ) ∈ S ↔ n ≤ P.chainTopCoeff i j by simpa only [S_def, mem_setOf_eq, natCast_zsmul] using this have aux : P.chainTopCoeff i j = (P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose_spec.2.choose.toNat := by simp [chainTopCoeff, h] obtain ⟨hp, h₂ : S = _⟩ := (P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose_spec.2.choose_spec rw [aux, h₂, mem_Icc] have := (P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose_spec.1 cutsat lemma root_sub_nsmul_mem_range_iff_le_chainBotCoeff {n : ℕ} : P.root j - n • P.root i ∈ range P.root ↔ n ≤ P.chainBotCoeff i j := by set S : Set ℤ := {z | P.root j + z • P.root i ∈ range P.root} with S_def suffices -(n : ℤ) ∈ S ↔ n ≤ P.chainBotCoeff i j by simpa only [S_def, mem_setOf_eq, neg_smul, natCast_zsmul, ← sub_eq_add_neg] using this have aux : P.chainBotCoeff i j = (-(P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose).toNat := by simp [chainBotCoeff, h] obtain ⟨hq, p, hp, h₂ : S = _⟩ := (P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose_spec rw [aux, h₂, mem_Icc] cutsat lemma Iic_chainTopCoeff_eq : Iic (P.chainTopCoeff i j) = {k | P.root j + k • P.root i ∈ range P.root} := by ext; simp [← P.root_add_nsmul_mem_range_iff_le_chainTopCoeff h] lemma Iic_chainBotCoeff_eq : Iic (P.chainBotCoeff i j) = {k | P.root j - k • P.root i ∈ range P.root} := by ext; simp [← P.root_sub_nsmul_mem_range_iff_le_chainBotCoeff h] omit h in lemma one_le_chainTopCoeff_of_root_add_mem [P.IsReduced] (h : P.root i + P.root j ∈ range P.root) : 1 ≤ P.chainTopCoeff i j := by have h' := P.linearIndependent_of_add_mem_range_root' h rwa [← root_add_nsmul_mem_range_iff_le_chainTopCoeff h', one_smul, add_comm] omit h in lemma one_le_chainBotCoeff_of_root_add_mem [P.IsReduced] (h : P.root i - P.root j ∈ range P.root) : 1 ≤ P.chainBotCoeff i j := by have h' := P.linearIndependent_of_sub_mem_range_root' h rwa [← root_sub_nsmul_mem_range_iff_le_chainBotCoeff h', one_smul, ← neg_mem_range_root_iff, neg_sub] lemma root_add_zsmul_mem_range_iff {z : ℤ} : P.root j + z • P.root i ∈ range P.root ↔ z ∈ Icc (-P.chainBotCoeff i j : ℤ) (P.chainTopCoeff i j) := by rcases z.eq_nat_or_neg with ⟨n, rfl | rfl⟩ · simp [P.root_add_nsmul_mem_range_iff_le_chainTopCoeff h] · simp [P.root_sub_nsmul_mem_range_iff_le_chainBotCoeff h, ← sub_eq_add_neg] lemma root_sub_zsmul_mem_range_iff {z : ℤ} : P.root j - z • P.root i ∈ range P.root ↔ z ∈ Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) := by rw [sub_eq_add_neg, ← neg_smul, P.root_add_zsmul_mem_range_iff h, mem_Icc, mem_Icc] omega lemma setOf_root_add_zsmul_mem_eq_Icc : {k : ℤ | P.root j + k • P.root i ∈ range P.root} = Icc (-P.chainBotCoeff i j : ℤ) (P.chainTopCoeff i j) := by ext; simp [← P.root_add_zsmul_mem_range_iff h] lemma setOf_root_sub_zsmul_mem_eq_Icc : {k : ℤ | P.root j - k • P.root i ∈ range P.root} = Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) := by ext; rw [← root_sub_zsmul_mem_range_iff h, mem_setOf_eq] lemma chainTopCoeff_eq_sSup : P.chainTopCoeff i j = sSup {k | P.root j + k • P.root i ∈ range P.root} := by rw [← Iic_chainTopCoeff_eq h, csSup_Iic] lemma chainBotCoeff_eq_sSup : P.chainBotCoeff i j = sSup {k | P.root j - k • P.root i ∈ range P.root} := by rw [← Iic_chainBotCoeff_eq h, csSup_Iic] lemma coe_chainTopCoeff_eq_sSup : P.chainTopCoeff i j = sSup {k : ℤ | P.root j + k • P.root i ∈ range P.root} := by rw [setOf_root_add_zsmul_mem_eq_Icc h] simp lemma coe_chainBotCoeff_eq_sSup : P.chainBotCoeff i j = sSup {k : ℤ | P.root j - k • P.root i ∈ range P.root} := by rw [setOf_root_sub_zsmul_mem_eq_Icc h] simp omit h private lemma chainCoeff_reflectionPerm_left_aux : letI := P.indexNeg Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) = Icc (-P.chainBotCoeff (-i) j : ℤ) (P.chainTopCoeff (-i) j) := by letI := P.indexNeg by_cases h : LinearIndependent R ![P.root i, P.root j] · have h' : LinearIndependent R ![P.root (-i), P.root j] := by simpa ext z rw [← P.root_add_zsmul_mem_range_iff h', indexNeg_neg, root_reflectionPerm, mem_Icc, reflection_apply_self, smul_neg, ← neg_smul, P.root_add_zsmul_mem_range_iff h, mem_Icc] omega · have h' : ¬ LinearIndependent R ![P.root (-i), P.root j] := by simpa simp only [chainTopCoeff_of_not_linearIndependent h, chainTopCoeff_of_not_linearIndependent h', chainBotCoeff_of_not_linearIndependent h, chainBotCoeff_of_not_linearIndependent h'] @[deprecated (since := "2025-05-28")] alias chainCoeff_reflection_perm_left_aux := chainCoeff_reflectionPerm_left_aux private lemma chainCoeff_reflectionPerm_right_aux : letI := P.indexNeg Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) = Icc (-P.chainBotCoeff i (-j) : ℤ) (P.chainTopCoeff i (-j)) := by letI := P.indexNeg by_cases h : LinearIndependent R ![P.root i, P.root j] · have h' : LinearIndependent R ![P.root i, P.root (-j)] := by simpa ext z rw [← P.root_add_zsmul_mem_range_iff h', indexNeg_neg, root_reflectionPerm, mem_Icc, reflection_apply_self, ← sub_neg_eq_add, ← neg_sub', neg_mem_range_root_iff, P.root_sub_zsmul_mem_range_iff h, mem_Icc] · have h' : ¬ LinearIndependent R ![P.root i, P.root (-j)] := by simpa simp only [chainTopCoeff_of_not_linearIndependent h, chainTopCoeff_of_not_linearIndependent h', chainBotCoeff_of_not_linearIndependent h, chainBotCoeff_of_not_linearIndependent h'] @[deprecated (since := "2025-05-28")] alias chainCoeff_reflection_perm_right_aux := chainCoeff_reflectionPerm_right_aux @[simp] lemma chainTopCoeff_reflectionPerm_left : P.chainTopCoeff (P.reflectionPerm i i) j = P.chainBotCoeff i j := by letI := P.indexNeg have (z : ℤ) : z ∈ Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) ↔ z ∈ Icc (-P.chainBotCoeff (-i) j : ℤ) (P.chainTopCoeff (-i) j) := by rw [P.chainCoeff_reflectionPerm_left_aux] refine le_antisymm ?_ ?_ · simpa using this (P.chainTopCoeff (-i) j) · simpa using this (P.chainBotCoeff i j) @[deprecated (since := "2025-05-28")] alias chainTopCoeff_reflection_perm_left := chainTopCoeff_reflectionPerm_left @[simp] lemma chainBotCoeff_reflectionPerm_left : P.chainBotCoeff (P.reflectionPerm i i) j = P.chainTopCoeff i j := by letI := P.indexNeg have (z : ℤ) : z ∈ Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) ↔ z ∈ Icc (-P.chainBotCoeff (-i) j : ℤ) (P.chainTopCoeff (-i) j) := by rw [P.chainCoeff_reflectionPerm_left_aux] refine le_antisymm ?_ ?_ · simpa using this (-P.chainBotCoeff (-i) j) · simpa using this (-P.chainTopCoeff i j) @[deprecated (since := "2025-05-28")] alias chainBotCoeff_reflection_perm_left := chainBotCoeff_reflectionPerm_left @[simp] lemma chainTopCoeff_reflectionPerm_right : P.chainTopCoeff i (P.reflectionPerm j j) = P.chainBotCoeff i j := by letI := P.indexNeg have (z : ℤ) : z ∈ Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) ↔ z ∈ Icc (-P.chainBotCoeff i (-j) : ℤ) (P.chainTopCoeff i (-j)) := by rw [P.chainCoeff_reflectionPerm_right_aux] refine le_antisymm ?_ ?_ · simpa using this (P.chainTopCoeff i (-j)) · simpa using this (P.chainBotCoeff i j) @[deprecated (since := "2025-05-28")] alias chainTopCoeff_reflection_perm_right := chainTopCoeff_reflectionPerm_right @[simp] lemma chainBotCoeff_reflectionPerm_right : P.chainBotCoeff i (P.reflectionPerm j j) = P.chainTopCoeff i j := by letI := P.indexNeg have (z : ℤ) : z ∈ Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) ↔ z ∈ Icc (-P.chainBotCoeff i (-j) : ℤ) (P.chainTopCoeff i (-j)) := by rw [P.chainCoeff_reflectionPerm_right_aux] refine le_antisymm ?_ ?_ · simpa using this (-P.chainBotCoeff i (-j)) · simpa using this (-P.chainTopCoeff i j) lemma chainBotCoeff_eq_zero_iff : P.chainBotCoeff i j = 0 ↔ ¬ LinearIndependent R ![P.root i, P.root j] ∨ P.root j - P.root i ∉ range P.root := by by_cases h : LinearIndependent R ![P.root i, P.root j] swap; · simp [chainBotCoeff_of_not_linearIndependent h, h] have : P.chainBotCoeff i j = 0 ↔ Iic (P.chainBotCoeff i j) = {0} := by simpa [Set.ext_iff, mem_Iic, mem_singleton_iff] using ⟨fun h ↦ by simp [h], fun h ↦ by rw [← h]⟩ simp only [h, not_true_eq_false, false_or, this, Iic_chainBotCoeff_eq h, Set.ext_iff, mem_setOf_eq, mem_singleton_iff] refine ⟨fun h' ↦ by simpa using h' 1, fun h' n ↦ ⟨fun h'' ↦ ?_, fun h'' ↦ by simp [h'']⟩⟩ replace h' : 1 ∉ {k | P.root j - k • P.root i ∈ range P.root} := by simpa using h' rw [← Iic_chainBotCoeff_eq h, mem_Iic, not_le, Nat.lt_one_iff] at h' rw [root_sub_nsmul_mem_range_iff_le_chainBotCoeff h] at h'' cutsat lemma chainTopCoeff_eq_zero_iff : P.chainTopCoeff i j = 0 ↔ ¬ LinearIndependent R ![P.root i, P.root j] ∨ P.root j + P.root i ∉ range P.root := by rw [← chainBotCoeff_reflectionPerm_left] simp [-chainBotCoeff_reflectionPerm_left, chainBotCoeff_eq_zero_iff] include h lemma chainBotCoeff_of_add {k : ι} (hk : P.root k = P.root j + P.root i) : P.chainBotCoeff i k = P.chainBotCoeff i j + 1 := by have h' : LinearIndependent R ![P.root i, P.root k] := by simpa [hk, add_comm] apply Nat.cast_injective (R := ℤ) rw [Nat.cast_add, Nat.cast_one, coe_chainBotCoeff_eq_sSup h', coe_chainBotCoeff_eq_sSup h] have (z : ℤ) : P.root k - z • P.root i = P.root j - (z - 1) • P.root i := by rw [hk]; module replace this : {z : ℤ | P.root k - z • P.root i ∈ range P.root} = OrderIso.addRight 1 '' {n | P.root j - n • P.root i ∈ range P.root} := by simp [this, sub_eq_add_neg] have bdd : BddAbove {z : ℤ | P.root j - z • P.root i ∈ range P.root} := by rw [setOf_root_sub_zsmul_mem_eq_Icc h] exact bddAbove_Icc rw [this, ← OrderIso.map_csSup' _ ⟨0, by simp⟩ bdd, OrderIso.addRight_apply] lemma chainTopCoeff_of_sub {k : ι} (hk : P.root k = P.root j - P.root i) : P.chainTopCoeff i k = P.chainTopCoeff i j + 1 := by letI := P.indexNeg replace hk : P.root k = P.root j + P.root (-i) := by simpa [sub_eq_add_neg] using hk simpa using chainBotCoeff_of_add (by simpa) hk lemma chainTopCoeff_of_add {k : ι} (hk : P.root k = P.root j + P.root i) : P.chainTopCoeff i j = P.chainTopCoeff i k + 1 := by replace h : LinearIndependent R ![P.root i, P.root k] := by rw [hk, add_comm]; simpa replace hk : P.root j = P.root k - P.root i := by rw [hk]; abel exact chainTopCoeff_of_sub h hk omit h @[deprecated (since := "2025-05-28")] alias chainBotCoeff_reflection_perm_right := chainBotCoeff_reflectionPerm_right variable (i j) open scoped Classical in /-- If `α = P.root i` and `β = P.root j` are linearly independent, this is the index of the root `β + p • α` where `β - q • α, ..., β - α, β, β + α, ..., β + p • α` is the `α`-chain through `β`. In the absence of linear independence, it takes a junk value. -/ def chainTopIdx : ι := if h : LinearIndependent R ![P.root i, P.root j] then (P.root_add_nsmul_mem_range_iff_le_chainTopCoeff h).mpr (le_refl <| P.chainTopCoeff i j) |>.choose else j open scoped Classical in /-- If `α = P.root i` and `β = P.root j` are linearly independent, this is the index of the root `β - q • α` where `β - q • α, ..., β - α, β, β + α, ..., β + p • α` is the `α`-chain through `β`. In the absence of linear independence, it takes a junk value. -/ def chainBotIdx : ι := if h : LinearIndependent R ![P.root i, P.root j] then (P.root_sub_nsmul_mem_range_iff_le_chainBotCoeff h).mpr (le_refl <| P.chainBotCoeff i j) |>.choose else j variable {i j} @[simp] lemma root_chainTopIdx : P.root (P.chainTopIdx i j) = P.root j + P.chainTopCoeff i j • P.root i := by by_cases h : LinearIndependent R ![P.root i, P.root j] · simp only [chainTopIdx, reduceDIte, h] exact (P.root_add_nsmul_mem_range_iff_le_chainTopCoeff h).mpr (le_refl <| P.chainTopCoeff i j) |>.choose_spec · simp only [chainTopIdx, chainTopCoeff, h, reduceDIte, zero_smul, add_zero] @[simp] lemma root_chainBotIdx : P.root (P.chainBotIdx i j) = P.root j - P.chainBotCoeff i j • P.root i := by by_cases h : LinearIndependent R ![P.root i, P.root j] · simp only [chainBotIdx, reduceDIte, h] exact (P.root_sub_nsmul_mem_range_iff_le_chainBotCoeff h).mpr (le_refl <| P.chainBotCoeff i j) |>.choose_spec · simp only [chainBotIdx, chainBotCoeff, h, reduceDIte, zero_smul, sub_zero] include h lemma chainBotCoeff_sub_chainTopCoeff : P.chainBotCoeff i j - P.chainTopCoeff i j = P.pairingIn ℤ j i := by suffices ∀ i j, LinearIndependent R ![P.root i, P.root j] → P.chainBotCoeff i j - P.chainTopCoeff i j ≤ P.pairingIn ℤ j i by refine le_antisymm (this i j h) ?_ specialize this (P.reflectionPerm i i) j (by simpa) simp only [chainBotCoeff_reflectionPerm_left, chainTopCoeff_reflectionPerm_left, pairingIn_reflectionPerm_self_right] at this cutsat intro i j h have h₁ : P.reflection i (P.root <| P.chainBotIdx i j) = P.root j + (P.chainBotCoeff i j - P.pairingIn ℤ j i) • P.root i := by simp [reflection_apply_root, ← P.algebraMap_pairingIn ℤ] module have h₂ : P.reflection i (P.root <| P.chainBotIdx i j) ∈ range P.root := by rw [← root_reflectionPerm] exact mem_range_self _ rw [h₁, root_add_zsmul_mem_range_iff h, mem_Icc] at h₂ omega lemma chainTopCoeff_sub_chainBotCoeff : P.chainTopCoeff i j - P.chainBotCoeff i j = -P.pairingIn ℤ j i := by rw [← chainBotCoeff_sub_chainTopCoeff h, neg_sub] omit h lemma chainCoeff_chainTopIdx_aux : P.chainBotCoeff i (P.chainTopIdx i j) = P.chainBotCoeff i j + P.chainTopCoeff i j ∧ P.chainTopCoeff i (P.chainTopIdx i j) = 0 := by have aux : LinearIndependent R ![P.root i, P.root j] ↔ LinearIndependent R ![P.root i, P.root (P.chainTopIdx i j)] := by rw [P.root_chainTopIdx, add_comm (P.root j), ← natCast_zsmul, LinearIndependent.pair_add_smul_right_iff] by_cases h : LinearIndependent R ![P.root i, P.root j] swap; · simp [chainTopCoeff_of_not_linearIndependent, chainBotCoeff_of_not_linearIndependent, h] have h' : LinearIndependent R ![P.root i, P.root (P.chainTopIdx i j)] := by rwa [← aux] set S₁ : Set ℤ := {z | P.root j + z • P.root i ∈ range P.root} with S₁_def set S₂ : Set ℤ := {z | P.root (P.chainTopIdx i j) + z • P.root i ∈ range P.root} with S₂_def have hS₁₂ : S₂ = (fun z ↦ (-P.chainTopCoeff i j : ℤ) + z) '' S₁ := by ext; simp [S₁_def, S₂_def, root_chainTopIdx, add_smul, add_assoc, natCast_zsmul] have hS₁ : S₁ = Icc (-P.chainBotCoeff i j : ℤ) (P.chainTopCoeff i j) := by ext; rw [S₁_def, mem_setOf_eq, root_add_zsmul_mem_range_iff h] have hS₂ : S₂ = Icc (-P.chainBotCoeff i (P.chainTopIdx i j) : ℤ) (P.chainTopCoeff i (P.chainTopIdx i j)) := by ext; rw [S₂_def, mem_setOf_eq, root_add_zsmul_mem_range_iff h'] rw [hS₁, hS₂, image_const_add_Icc, neg_add_cancel, Icc_eq_Icc_iff (by simp), neg_eq_iff_eq_neg, neg_add_rev, neg_neg, neg_neg] at hS₁₂ norm_cast at hS₁₂ @[simp] lemma chainBotCoeff_chainTopIdx : P.chainBotCoeff i (P.chainTopIdx i j) = P.chainBotCoeff i j + P.chainTopCoeff i j := chainCoeff_chainTopIdx_aux.1 @[simp] lemma chainTopCoeff_chainTopIdx : P.chainTopCoeff i (P.chainTopIdx i j) = 0 := chainCoeff_chainTopIdx_aux.2 include h in lemma chainBotCoeff_add_chainTopCoeff_eq_pairingIn_chainTopIdx : P.chainBotCoeff i j + P.chainTopCoeff i j = P.pairingIn ℤ (P.chainTopIdx i j) i := by replace h : LinearIndependent R ![P.root i, P.root (P.chainTopIdx i j)] := by rwa [P.root_chainTopIdx, add_comm (P.root j), ← natCast_zsmul, LinearIndependent.pair_add_smul_right_iff] calc (P.chainBotCoeff i j + P.chainTopCoeff i j : ℤ) _ = P.chainBotCoeff i (P.chainTopIdx i j) := by simp _ = P.chainBotCoeff i (P.chainTopIdx i j) - P.chainTopCoeff i (P.chainTopIdx i j) := by simp _ = P.pairingIn ℤ (P.chainTopIdx i j) i := by rw [P.chainBotCoeff_sub_chainTopCoeff h] lemma chainBotCoeff_add_chainTopCoeff_le_three [P.IsReduced] : P.chainBotCoeff i j + P.chainTopCoeff i j ≤ 3 := by by_cases h : LinearIndependent R ![P.root i, P.root j] swap; · simp [chainTopCoeff_of_not_linearIndependent, chainBotCoeff_of_not_linearIndependent, h] rw [← Int.ofNat_le, Nat.cast_add, Nat.cast_ofNat, chainBotCoeff_add_chainTopCoeff_eq_pairingIn_chainTopIdx h] have := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed i (P.chainTopIdx i j) aesop end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/Base.lean
import Mathlib.LinearAlgebra.RootSystem.Chain import Mathlib.LinearAlgebra.RootSystem.Finite.Lemmas import Mathlib.LinearAlgebra.RootSystem.IsValuedIn /-! # Bases for root pairings / systems This file contains a theory of bases for root pairings / systems. ## Implementation details For reduced root pairings `RootSystem.Base` is equivalent to the usual definition appearing in the informal literature (e.g., it follows from [serre1965](Ch. V, §8, Proposition 7) that `RootSystem.Base` is equivalent to both [serre1965](Ch. V, §8, Definition 5) and [bourbaki1968](Ch. VI, §1.5) for reduced pairings). However for non-reduced root pairings, it is more restrictive because it includes axioms on coroots as well as on roots. For example by `RootPairing.Base.eq_one_or_neg_one_of_mem_support_of_smul_mem` it is clear that the 1-dimensional root system `{-2, -1, 0, 1, 2} ⊆ ℝ` has no base in the sense of `RootSystem.Base`. It is also worth remembering that it is only for reduced root systems that one has the simply transitive action of the Weyl group on the set of bases, and that the Weyl group of a non-reduced root system is the same as that of the reduced root system obtained by passing to the indivisible roots. For infinite root systems, `RootSystem.Base` is usually not the right notion: linear independence is too strong. ## Main definitions / results: * `RootSystem.Base`: a base of a root pairing. * `RootSystem.Base.IsPos`: the predicate that a (co)root is positive relative to a base. * `RootSystem.Base.induction_add`: an induction principle for predicates on (co)roots which respect addition of a simple root. * `RootSystem.Base.induction_reflect`: an induction principle for predicates on (co)roots which respect reflection in a simple root. ## TODO * Develop a theory of base / separation / positive roots for infinite systems which specialises to the concept here for finite systems. -/ noncomputable section open Function Set Submodule open FaithfulSMul (algebraMap_injective) open Module open End (invtSubmodule mem_invtSubmodule) variable {ι R M N : Type*} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] namespace RootPairing /-- A base of a root pairing. For reduced root pairings this definition is equivalent to the usual definition appearing in the informal literature but not for non-reduced root pairings it is more restrictive. See the module doc string for further remarks. -/ structure Base (P : RootPairing ι R M N) where /-- The indices of the simple roots / coroots. -/ support : Finset ι linearIndepOn_root : LinearIndepOn R P.root support linearIndepOn_coroot : LinearIndepOn R P.coroot support root_mem_or_neg_mem (i : ι) : P.root i ∈ AddSubmonoid.closure (P.root '' support) ∨ -P.root i ∈ AddSubmonoid.closure (P.root '' support) coroot_mem_or_neg_mem (i : ι) : P.coroot i ∈ AddSubmonoid.closure (P.coroot '' support) ∨ -P.coroot i ∈ AddSubmonoid.closure (P.coroot '' support) namespace Base section RootPairing variable {P : RootPairing ι R M N} (b : P.Base) lemma support_nonempty [Nonempty ι] [NeZero (2 : R)] : b.support.Nonempty := by by_contra! contra rw [Finset.not_nonempty_iff_eq_empty] at contra inhabit ι simpa [P.ne_zero default, contra] using b.root_mem_or_neg_mem default /-- Interchanging roots and coroots, one still has a base of a root pairing. -/ @[simps] protected def flip : P.flip.Base where support := b.support linearIndepOn_root := b.linearIndepOn_coroot linearIndepOn_coroot := b.linearIndepOn_root root_mem_or_neg_mem := b.coroot_mem_or_neg_mem coroot_mem_or_neg_mem := b.root_mem_or_neg_mem include b in lemma root_ne_neg_of_ne [Nontrivial R] {i j : ι} (hi : i ∈ b.support) (hj : j ∈ b.support) (hij : i ≠ j) : P.root i ≠ -P.root j := by classical intro contra have := linearIndepOn_iff'.mp b.linearIndepOn_root ({i, j} : Finset ι) 1 (by simp [Set.insert_subset_iff, hi, hj]) (by simp [Finset.sum_pair hij, contra]) simp_all lemma linearIndependent_pair_of_ne {i j : b.support} (hij : i ≠ j) : LinearIndependent R ![P.root i, P.root j] := by have : ({(j : ι), (i : ι)} : Set ι) ⊆ b.support := by simp [pair_subset_iff] rw [← linearIndepOn_id_range_iff (by aesop)] simpa [image_pair] using LinearIndepOn.id_image <| b.linearIndepOn_root.mono this lemma root_mem_span_int (i : ι) : P.root i ∈ span ℤ (P.root '' b.support) := by have := b.root_mem_or_neg_mem i simp only [← span_nat_eq_addSubmonoidClosure, mem_toAddSubmonoid] at this rw [← span_span_of_tower (R := ℕ)] rcases this with hi | hi · exact subset_span hi · rw [← neg_mem_iff] exact subset_span hi lemma coroot_mem_span_int (i : ι) : P.coroot i ∈ span ℤ (P.coroot '' b.support) := b.flip.root_mem_span_int i @[simp] lemma span_int_root_support : span ℤ (P.root '' b.support) = span ℤ (range P.root) := by refine le_antisymm (span_mono <| image_subset_range _ _) (span_le.mpr ?_) rintro - ⟨i, rfl⟩ exact b.root_mem_span_int i @[simp] lemma span_int_coroot_support : span ℤ (P.coroot '' b.support) = span ℤ (range P.coroot) := b.flip.span_int_root_support @[simp] lemma span_root_support : span R (P.root '' b.support) = P.rootSpan R := by rw [← span_span_of_tower (R := ℤ), span_int_root_support, span_span_of_tower] @[simp] lemma span_coroot_support : span R (P.coroot '' b.support) = P.corootSpan R := b.flip.span_root_support open Finsupp in lemma eq_one_or_neg_one_of_mem_support_of_smul_mem_aux [Finite ι] [IsAddTorsionFree M] [IsAddTorsionFree N] (i : ι) (h : i ∈ b.support) (t : R) (ht : t • P.root i ∈ range P.root) : ∃ z : ℤ, z * t = 1 := by classical obtain ⟨j, hj⟩ := ht obtain ⟨f, hf⟩ : ∃ f : b.support → ℤ, P.coroot i = ∑ i, (t * f i) • P.coroot i := by have : P.coroot j ∈ span ℤ (P.coroot '' b.support) := b.coroot_mem_span_int j rw [image_eq_range, mem_span_range_iff_exists_fun] at this refine this.imp fun f hf ↦ ?_ simp only [Finset.coe_sort_coe] at hf simp_rw [mul_smul, ← Finset.smul_sum, Int.cast_smul_eq_zsmul, hf, coroot_eq_smul_coroot_iff.mpr hj] use f ⟨i, h⟩ replace hf : P.coroot i = linearCombination R (fun k : b.support ↦ P.coroot k) (t • (linearEquivFunOnFinite R _ _).symm (fun x ↦ (f x : R))) := by rw [map_smul, linearCombination_eq_fintype_linearCombination_apply, Fintype.linearCombination_apply, hf] simp_rw [mul_smul, ← Finset.smul_sum] let g : b.support →₀ R := single ⟨i, h⟩ 1 have hg : P.coroot i = linearCombination R (fun k : b.support ↦ P.coroot k) g := by simp [g] rw [hg] at hf have : Injective (linearCombination R fun k : b.support ↦ P.coroot k) := b.linearIndepOn_coroot simpa [g, linearEquivFunOnFinite, mul_comm t] using (DFunLike.congr_fun (this hf) ⟨i, h⟩).symm variable [CharZero R] lemma eq_one_or_neg_one_of_mem_support_of_smul_mem [Finite ι] [IsAddTorsionFree M] [IsAddTorsionFree N] (i : ι) (h : i ∈ b.support) (t : R) (ht : t • P.root i ∈ range P.root) : t = 1 ∨ t = -1 := by obtain ⟨z, hz⟩ := b.eq_one_or_neg_one_of_mem_support_of_smul_mem_aux i h t ht replace ht : (z : R) • P.coroot i ∈ range P.coroot := by obtain ⟨j, hj⟩ := ht simpa only [coroot_eq_smul_coroot_iff.mpr hj, smul_smul, hz, one_smul] using mem_range_self j obtain ⟨w, hw⟩ := b.flip.eq_one_or_neg_one_of_mem_support_of_smul_mem_aux i h _ ht have : (z : R) * w = 1 := by simpa [mul_mul_mul_comm _ t, mul_comm t, mul_comm _ (z : R), hz] using congr_arg₂ (· * ·) hz hw suffices z = 1 ∨ z = -1 by rcases this with rfl | rfl · left; simpa using hz · right; simpa [neg_eq_iff_eq_neg] using hz norm_cast at this rw [Int.mul_eq_one_iff_eq_one_or_neg_one] at this tauto lemma pos_or_neg_of_sum_smul_root_mem (f : ι → ℤ) (hf : ∑ j ∈ b.support, f j • P.root j ∈ range P.root) (hf₀ : f.support ⊆ b.support) : 0 < f ∨ f < 0 := by suffices ∀ (f : ι → ℤ) (hf : ∑ j ∈ b.support, f j • P.root j ∈ AddSubmonoid.closure (P.root '' b.support)) (hf₀ : f.support ⊆ b.support) (hf' : f ≠ 0), 0 < f by obtain ⟨k, hk⟩ := hf have hf' : f ≠ 0 := by rintro rfl; exact P.ne_zero k <| by simp [hk] rcases b.root_mem_or_neg_mem k with hk' | hk' <;> rw [hk] at hk' · left; exact this f hk' hf₀ hf' · right; simpa using this (-f) (by convert hk'; simp) (by simpa only [support_neg]) (by simpa) intro f hf hf₀ hf' let f' : b.support → ℤ := fun i ↦ f i replace hf : ∑ j, f' j • P.root j ∈ AddSubmonoid.closure (P.root '' b.support) := by suffices ∑ j, f' j • P.root j = ∑ j ∈ b.support, f j • P.root j by rwa [this] rw [← b.support.sum_finset_coe]; rfl rw [← span_nat_eq_addSubmonoidClosure, mem_toAddSubmonoid, Fintype.mem_span_image_iff_exists_fun] at hf obtain ⟨c, hc⟩ := hf replace hc (i : b.support) : c i = f' i := Fintype.linearIndependent_iffₛ.mp (b.linearIndepOn_root.restrict_scalars' ℤ) (Int.ofNat ∘ c) f' (by simpa) i have aux : 0 ≤ f := by intro i by_cases hi : i ∈ b.support · change 0 ≤ f' ⟨i, hi⟩ simp [← hc] · replace hi : i ∉ f.support := by contrapose! hi; exact hf₀ hi simp_all refine Pi.lt_def.mpr ⟨aux, ?_⟩ by_contra! contra replace contra : f = 0 := le_antisymm contra aux contradiction lemma not_nonpos_iff_pos_of_sum_mem_range_root (f : ι → ℤ) (hf : ∑ j ∈ b.support, f j • P.root j ∈ range P.root) (hf₀ : f.support ⊆ b.support) : (¬ f ≤ 0) ↔ 0 < f := by rw [Pi.lt_def] refine ⟨fun h ↦ ⟨?_, ?_⟩, fun ⟨h, ⟨i, hi⟩⟩ contra ↦ by simp [le_antisymm contra h] at hi⟩ · rcases b.pos_or_neg_of_sum_smul_root_mem f hf hf₀ with h' | h' · exact le_of_lt h' · exfalso exact h (le_of_lt h') · contrapose! h; exact h lemma not_nonneg_iff_neg_of_sum_mem_range_root (f : ι → ℤ) (hf : ∑ j ∈ b.support, f j • P.root j ∈ range P.root) (hf₀ : f.support ⊆ b.support) : (¬ 0 ≤ f) ↔ f < 0 := by replace hf : ∑ j ∈ b.support, (-f) j • P.root j ∈ range P.root := by rw [← neg_mem_range_root_iff]; simpa have := b.not_nonpos_iff_pos_of_sum_mem_range_root (-f) hf (by simpa) simp_all lemma sub_notMem_range_root {i j : ι} (hi : i ∈ b.support) (hj : j ∈ b.support) : P.root i - P.root j ∉ range P.root := by rcases eq_or_ne j i with rfl | hij · simpa only [sub_self, mem_range, not_exists] using fun k ↦ P.ne_zero k classical let f : ι → ℤ := fun k ↦ if k = i then 1 else if k = j then -1 else 0 have hf : ∑ k ∈ b.support, f k • P.root k = P.root i - P.root j := by have : {i, j} ⊆ b.support := by aesop (add simp Finset.insert_subset_iff) rw [← Finset.sum_subset (s₁ := {i, j}) (s₂ := b.support) (by aesop) (by aesop), Finset.sum_insert (by aesop), Finset.sum_singleton] simp [f, hij, sub_eq_add_neg] intro contra rcases b.pos_or_neg_of_sum_smul_root_mem f (by rwa [hf]) (by aesop) with pos | neg · simpa [hij, f] using le_of_lt pos j · simpa [hij, f] using le_of_lt neg i @[deprecated (since := "2025-05-24")] alias sub_nmem_range_root := sub_notMem_range_root lemma sub_notMem_range_coroot {i j : ι} (hi : i ∈ b.support) (hj : j ∈ b.support) : P.coroot i - P.coroot j ∉ range P.coroot := b.flip.sub_notMem_range_root hi hj @[deprecated (since := "2025-05-24")] alias sub_nmem_range_coroot := sub_notMem_range_coroot lemma pairingIn_le_zero_of_ne [IsDomain R] [P.IsCrystallographic] [Finite ι] {i j} (hij : i ≠ j) (hi : i ∈ b.support) (hj : j ∈ b.support) : P.pairingIn ℤ i j ≤ 0 := by by_contra! h exact b.sub_notMem_range_root hi hj <| P.root_sub_root_mem_of_pairingIn_pos h hij variable {b} variable [IsDomain R] [P.IsCrystallographic] [Finite ι] {i j : b.support} @[simp] lemma chainBotCoeff_eq_zero : P.chainBotCoeff i j = 0 := chainBotCoeff_eq_zero_iff.mpr <| Or.inr <| b.sub_notMem_range_root j.property i.property lemma chainTopCoeff_eq_of_ne (hij : i ≠ j) : P.chainTopCoeff i j = -P.pairingIn ℤ j i := by rw [← chainTopCoeff_sub_chainBotCoeff (b.linearIndependent_pair_of_ne hij)] simp end RootPairing section RootSystem variable {P : RootSystem ι R M N} (b : P.Base) /-- A base of a root system yields a basis of the root space. -/ def toWeightBasis : Basis b.support R M := Basis.mk b.linearIndepOn_root <| by change ⊤ ≤ span R (range <| P.root ∘ ((↑) : b.support → ι)) simp [range_comp] @[simp] lemma toWeightBasis_apply (i : b.support) : b.toWeightBasis i = P.root i := by simp [toWeightBasis] @[simp] lemma toWeightBasis_repr_root (i : b.support) : b.toWeightBasis.repr (P.root i) = Finsupp.single i 1 := by simp [← LinearEquiv.eq_symm_apply] /-- A base of a root system yields a basis of the coroot space. -/ def toCoweightBasis : Basis b.support R N := Base.toWeightBasis (P := P.flip) b.flip @[simp] lemma toCoweightBasis_apply (i : b.support) : b.toCoweightBasis i = P.coroot i := b.flip.toWeightBasis_apply (P := P.flip) i @[simp] lemma toCoweightBasis_repr_coroot (i : b.support) : b.toCoweightBasis.repr (P.coroot i) = Finsupp.single i 1 := by simp [← LinearEquiv.eq_symm_apply] end RootSystem section RootPairing variable {P : RootPairing ι R M N} (b : P.Base) include b lemma exists_root_eq_sum_nat_or_neg (i : ι) : ∃ f : ι → ℕ, f.support ⊆ b.support ∧ (P.root i = ∑ j ∈ b.support, f j • P.root j ∨ P.root i = - ∑ j ∈ b.support, f j • P.root j) := by classical simp_rw [← neg_eq_iff_eq_neg] suffices ∀ m ∈ AddSubmonoid.closure (P.root '' b.support), ∃ f : ι → ℕ, f.support ⊆ b.support ∧ m = ∑ j ∈ b.support, f j • P.root j by rcases b.root_mem_or_neg_mem i with hi | hi · obtain ⟨f, hf, hf'⟩ := this _ hi exact ⟨f, hf, Or.inl hf'⟩ · obtain ⟨f, hf, hf'⟩ := this _ hi exact ⟨f, hf, Or.inr hf'⟩ intro m hm refine AddSubmonoid.closure_induction ?_ ⟨0, by simp⟩ ?_ hm · rintro - ⟨j, hj, rfl⟩ exact ⟨Pi.single j 1, by simpa, by aesop (add simp Pi.single_apply)⟩ · intro _ _ _ _ ⟨f, hf, hf'⟩ ⟨g, hg, hg'⟩ refine ⟨f + g, ?_, by simp [hf', hg', add_smul, Finset.sum_add_distrib]⟩ exact (support_add f g).trans <| union_subset_iff.mpr ⟨hf, hg⟩ lemma exists_root_eq_sum_int [CharZero R] (i : ι) : ∃ f : ι → ℤ, f.support ⊆ b.support ∧ (0 < f ∨ f < 0) ∧ P.root i = ∑ j ∈ b.support, f j • P.root j := by obtain ⟨f, hf, hf' | hf'⟩ := b.exists_root_eq_sum_nat_or_neg i · refine ⟨Nat.cast ∘ f, by simpa, Or.inl <| Pi.lt_def.mpr ⟨fun _ ↦ by simp, ?_⟩, by simp [hf']⟩ by_contra! contra replace contra : f = 0 := by ext i; simpa using contra i exact P.ne_zero i <| by simp [hf', contra] · refine ⟨-Nat.cast ∘ f, by simpa, Or.inr <| Pi.lt_def.mpr ⟨fun _ ↦ by simp, ?_⟩, by simp [hf']⟩ by_contra! contra replace contra : f = 0 := by ext i; simpa using contra i exact P.ne_zero i <| by simp [hf', contra] end RootPairing section PositiveRoots variable {P : RootPairing ι R M N} (b : P.Base) [CharZero R] /-- Given a base `α₁, α₂, …`, the height of a root `∑ zᵢαᵢ` relative to this base is `∑ zᵢ`. -/ def height (i : ι) : ℤ := ∑ j ∈ b.support, (b.exists_root_eq_sum_int i).choose j variable {b} in lemma height_eq_sum {i : ι} {f : ι → ℤ} (heq : P.root i = ∑ j ∈ b.support, f j • P.root j) : b.height i = ∑ j ∈ b.support, f j := by suffices ∀ j ∈ b.support, (b.exists_root_eq_sum_int i).choose j = f j from Finset.sum_congr rfl this intro j hj obtain ⟨-, -, h⟩ := (b.exists_root_eq_sum_int i).choose_spec rw [h, b.support.sum_subtype (p := (· ∈ b.support)) (by simp) (F := inferInstance), b.support.sum_subtype (p := (· ∈ b.support)) (by simp) (F := inferInstance)] at heq have aux (j : b.support) := Fintype.linearIndependent_iffₛ.mp (b.linearIndepOn_root.restrict_scalars' ℤ) ((b.exists_root_eq_sum_int i).choose ∘ (↑)) (f ∘ (↑)) (by simpa) j simpa using aux ⟨j, hj⟩ lemma height_ne_zero (i : ι) : b.height i ≠ 0 := by obtain ⟨f, hf₀, hf₁, hf₂⟩ := b.exists_root_eq_sum_int i rw [height_eq_sum hf₂] rcases hf₁ with pos | neg · refine (Finset.sum_pos' (fun i _ ↦ pos.le i) ?_).ne' by_contra! contra replace contra (j : ι) : f j = 0 := by by_cases hj : j ∈ f.support · exact le_antisymm (contra j (hf₀ hj)) (pos.le j) · simpa using hj exact P.ne_zero i <| by simp [hf₂, contra] · refine (Finset.sum_neg' (fun i _ ↦ neg.le i) ?_).ne by_contra! contra replace contra (j : ι) : f j = 0 := by by_cases hj : j ∈ f.support · exact le_antisymm (neg.le j) (contra j (hf₀ hj)) · simpa using hj exact P.ne_zero i <| by simp [hf₂, contra] lemma height_reflectionPerm_self (i : ι) : letI := P.indexNeg b.height (-i) = -b.height i := by letI := P.indexNeg obtain ⟨f, hf₀, hf₁, hf₂⟩ := b.exists_root_eq_sum_int i have hf₃ : P.root (-i) = ∑ j ∈ b.support, (-f) j • P.root j := by simpa simp only [height_eq_sum hf₂, height_eq_sum hf₃, Pi.neg_apply, Finset.sum_neg_distrib] variable {b} in lemma height_one_of_mem_support {i : ι} (hi : i ∈ b.support) : b.height i = 1 := by classical have : P.root i = ∑ j ∈ b.support, (Pi.single i 1 : ι → ℤ) j • P.root j := by rw [Finset.sum_eq_single_of_mem i hi (by simp_all)]; simp simpa [height_eq_sum this] lemma height_add {i j k : ι} (hk : P.root k = P.root i + P.root j) : b.height k = b.height i + b.height j := by obtain ⟨f, -, -, hf⟩ := b.exists_root_eq_sum_int i obtain ⟨g, -, -, hg⟩ := b.exists_root_eq_sum_int j have hfg : P.root k = ∑ l ∈ b.support, (f + g) l • P.root l := by simp_rw [Pi.add_apply, add_smul, Finset.sum_add_distrib, ← hf, ← hg, hk] simp_rw [height_eq_sum hf, height_eq_sum hg, height_eq_sum hfg, ← Finset.sum_add_distrib, Pi.add_apply] lemma height_sub {i j k : ι} (hk : P.root k = P.root i - P.root j) : b.height k = b.height i - b.height j := by letI := P.indexNeg replace hk : P.root k = P.root i + P.root (-j) := by simpa [← sub_eq_add_neg] rw [sub_eq_add_neg, ← b.height_reflectionPerm_self, b.height_add hk] lemma height_add_zsmul {i j k : ι} {z : ℤ} (hk : P.root k = P.root i + z • P.root j) : b.height k = b.height i + z • b.height j := by obtain ⟨f, -, -, hf⟩ := b.exists_root_eq_sum_int i obtain ⟨g, -, -, hg⟩ := b.exists_root_eq_sum_int j have hfg : P.root k = ∑ l ∈ b.support, (f + z • g) l • P.root l := by simp_rw [Pi.add_apply, Pi.smul_apply, add_smul, smul_assoc, Finset.sum_add_distrib, ← Finset.smul_sum, ← hf, ← hg, hk] simp_rw [height_eq_sum hf, height_eq_sum hg, height_eq_sum hfg, Pi.add_apply, Pi.smul_apply, Finset.sum_add_distrib, Finset.smul_sum] /-- The predicate that a (co)root is positive with respect to a base. -/ def IsPos (i : ι) : Prop := 0 < b.height i lemma isPos_iff {i : ι} : b.IsPos i ↔ 0 < b.height i := Iff.rfl lemma isPos_iff' {i : ι} : b.IsPos i ↔ 0 ≤ b.height i := by rw [isPos_iff] have := b.height_ne_zero i cutsat lemma IsPos.or_neg (i : ι) : letI := P.indexNeg b.IsPos i ∨ b.IsPos (-i) := by rw [isPos_iff, isPos_iff, height_reflectionPerm_self] have := b.height_ne_zero i cutsat lemma IsPos.neg_iff_not (i : ι) : letI := P.indexNeg b.IsPos (-i) ↔ ¬ b.IsPos i := by rw [isPos_iff, isPos_iff, height_reflectionPerm_self] have := b.height_ne_zero i cutsat variable {b} lemma isPos_of_mem_support {i : ι} (h : i ∈ b.support) : b.IsPos i := by rw [isPos_iff, height_one_of_mem_support h] exact Int.one_pos lemma IsPos.add {i j k : ι} (hi : b.IsPos i) (hj : b.IsPos j) (hk : P.root k = P.root i + P.root j) : b.IsPos k := by rw [isPos_iff] at hi hj ⊢ rw [b.height_add hk] cutsat lemma IsPos.sub {i j k : ι} (hi : b.IsPos i) (hj : j ∈ b.support) (hk : P.root k = P.root i - P.root j) : b.IsPos k := by rw [isPos_iff] at hi rw [isPos_iff', b.height_sub hk, height_one_of_mem_support hj] cutsat lemma IsPos.exists_mem_support_pos_pairingIn [P.IsCrystallographic] {i : ι} (h₀ : b.IsPos i) : ∃ j ∈ b.support, 0 < P.pairingIn ℤ j i := by by_contra! contra suffices P.pairingIn ℤ i i ≤ 0 by simp_all obtain ⟨f, hf₀, hf₁, hf₂⟩ := b.exists_root_eq_sum_int i replace hf₁ : 0 < f := by refine hf₁.resolve_right ?_ rw [isPos_iff, height_eq_sum hf₂] at h₀ contrapose! h₀ exact Finset.sum_nonpos fun i _ ↦ h₀.le i have : P.pairingIn ℤ i i = ∑ j ∈ b.support, f j • P.pairingIn ℤ j i := algebraMap_injective ℤ R <| by simp_rw [algebraMap_pairingIn, map_sum, ← root_coroot_eq_pairing, hf₂, map_sum, map_zsmul, LinearMap.coeFn_sum, Finset.sum_apply, LinearMap.smul_apply, root_coroot_eq_pairing, zsmul_eq_mul, algebraMap_pairingIn] rw [this] refine Finset.sum_nonpos fun j _ ↦ ?_ by_cases hj : j ∈ Function.support f · exact smul_nonpos_of_nonneg_of_nonpos (hf₁.le j) (contra j (hf₀ hj)) · simp_all lemma exists_mem_support_pos_pairingIn_ne_zero [P.IsCrystallographic] (i : ι) : ∃ j ∈ b.support, P.pairingIn ℤ j i ≠ 0 := by rcases IsPos.or_neg b i with hi | hi · obtain ⟨j, hj, hj₀⟩ := hi.exists_mem_support_pos_pairingIn exact ⟨j, hj, hj₀.ne'⟩ · obtain ⟨j, hj, hj₀⟩ := hi.exists_mem_support_pos_pairingIn exact ⟨j, hj, by aesop⟩ variable [Finite ι] [IsDomain R] [P.IsCrystallographic] [P.IsReduced] lemma IsPos.add_zsmul {i j k : ι} {z : ℤ} (hij : i ≠ j) (hi : b.IsPos i) (hj : j ∈ b.support) (hk : P.root k = P.root i + z • P.root j) : b.IsPos k := by replace hij : LinearIndependent R ![P.root j, P.root i] := by refine IsReduced.linearIndependent P hij.symm fun contra ↦ ?_ letI := P.indexNeg replace contra : i = -j := by rw [eq_comm, neg_eq_iff_eq_neg]; simpa using contra rw [contra, isPos_iff, height_reflectionPerm_self, height_one_of_mem_support hj] at hi omega induction z generalizing i k with | zero => simp_all | succ w hw => obtain ⟨l, hl⟩ : P.root i + (w : ℤ) • P.root j ∈ range P.root := by replace hk : P.root i + (w + 1) • P.root j ∈ range P.root := ⟨k, by rw [hk]; module⟩ simp only [natCast_zsmul, root_add_nsmul_mem_range_iff_le_chainTopCoeff hij] at hk ⊢ cutsat replace hk : P.root k = P.root l + P.root j := by rw [hk, hl]; module exact (hw hi hl hij).add (b.isPos_of_mem_support hj) hk | pred w hw => obtain ⟨l, hl⟩ : P.root i + (-w : ℤ) • P.root j ∈ range P.root := by replace hk : P.root i - (w + 1) • P.root j ∈ range P.root := ⟨k, by rw [hk]; module⟩ rw [neg_smul, ← sub_eq_add_neg, natCast_zsmul] simp only [root_sub_nsmul_mem_range_iff_le_chainBotCoeff hij] at hk ⊢ cutsat replace hk : P.root k = P.root l - P.root j := by rw [hk, hl]; module exact (hw hi hl hij).sub hj hk lemma IsPos.reflectionPerm {i j : ι} (hi : b.IsPos i) (hj : j ∈ b.support) (hij : i ≠ j) : b.IsPos (P.reflectionPerm j i) := by have : P.root (P.reflectionPerm j i) = P.root i + (-P.pairingIn ℤ i j) • P.root j := by rw [root_reflectionPerm, neg_smul, reflection_apply_root' ℤ, sub_eq_add_neg] exact hi.add_zsmul hij hj this omit [P.IsReduced] in lemma IsPos.induction_on_add {i : ι} (h₀ : b.IsPos i) {p : ι → Prop} (h₁ : ∀ i ∈ b.support, p i) (h₂ : ∀ i j k, P.root k = P.root i + P.root j → p i → j ∈ b.support → p k) : p i := by generalize hN : b.height i = N induction N using Int.induction_on generalizing i with | zero => exact False.elim <| b.height_ne_zero i hN | succ n ih => obtain ⟨j, hj, hj'⟩ := h₀.exists_mem_support_pos_pairingIn rw [P.zero_lt_pairingIn_iff'] at hj' rcases eq_or_ne i j with rfl | hij; · exact h₁ i hj obtain ⟨k, hk⟩ := P.root_sub_root_mem_of_pairingIn_pos hj' hij have hkn : b.height k = n := by rw [b.height_sub hk, height_one_of_mem_support hj]; omega have hkpos : b.IsPos k := by rw [isPos_iff']; omega exact h₂ k j i (by rw [hk]; module) (ih hkpos hkn) hj | pred n ih => rw [isPos_iff] at h₀ cutsat omit [P.IsReduced] in /-- This lemma is included mostly for comparison with the informal literature. Usually `RootPairing.Base.IsPos.induction_on_add` will be more useful. -/ lemma exists_eq_sum_and_forall_sum_mem_of_isPos {i : ι} (hi : b.IsPos i) : ∃ n, ∃ f : Fin n → ι, range f ⊆ b.support ∧ P.root i = ∑ m, P.root (f m) ∧ ∀ m, ∑ m' ≤ m, P.root (f m') ∈ range P.root := by apply hi.induction_on_add (fun j hj ↦ ⟨1, ![j], by simpa⟩) intro j k l h₁ ⟨n, f, h₂, h₃, h₄⟩ h₅ refine ⟨n + 1, Fin.snoc f k, ?_, ?_, fun m ↦ ?_⟩ · simpa using insert_subset h₅ h₂ · simp [Fin.sum_univ_castSucc, h₁, h₃] · by_cases hm : m < n · have : m = (⟨m, hm⟩ : Fin n).castSucc := rfl rw [this, Fin.sum_Iic_castSucc] simp only [Fin.snoc_castSucc, h₄] · replace hm : m = n := by omega replace hm : Finset.Iic m = Finset.univ := by ext; simp [hm, Fin.le_def, Fin.is_le] simp [hm, Fin.sum_univ_castSucc, ← h₃, ← h₁] omit [P.IsReduced] in lemma induction_add (i : ι) {p : ι → Prop} (h₀ : ∀ i, p i → p (P.reflectionPerm i i)) (h₁ : ∀ i ∈ b.support, p i) (h₂ : ∀ i j k, P.root k = P.root i + P.root j → p i → j ∈ b.support → p k) : p i := by letI := P.indexNeg rcases IsPos.or_neg b i with hi | hi · exact hi.induction_on_add h₁ h₂ · suffices p (-i) by rw [← neg_neg i]; exact h₀ (-i) this exact hi.induction_on_add h₁ h₂ lemma IsPos.induction_on_reflect {i : ι} (h₀ : b.IsPos i) {p : ι → Prop} (h₁ : ∀ i ∈ b.support, p i) (h₂ : ∀ i j, p i → j ∈ b.support → p (P.reflectionPerm j i)) : p i := by generalize hN : (b.height i).natAbs = N induction N using Nat.strongRecOn generalizing i with | ind n ih => obtain ⟨j, hj, hj'⟩ := h₀.exists_mem_support_pos_pairingIn rw [P.zero_lt_pairingIn_iff'] at hj' rcases eq_or_ne i j with rfl | hij; · exact h₁ i hj have hk := h₀.reflectionPerm hj hij have : (b.height (P.reflectionPerm j i)).natAbs < n := by suffices b.height (P.reflectionPerm j i) < b.height i by have : (b.height (P.reflectionPerm j i)).natAbs = b.height (P.reflectionPerm j i) := Int.natAbs_of_nonneg <| (isPos_iff' _).mp hk cutsat have := P.reflection_apply_root' ℤ (i := j) (j := i) rw [← root_reflectionPerm, sub_eq_add_neg, ← neg_smul] at this rw [b.height_add_zsmul this] replace hj : 0 < b.height j := (isPos_iff _).mp <| isPos_of_mem_support hj aesop simpa using h₂ (P.reflectionPerm j i) j (ih (m := (b.height (P.reflectionPerm j i)).natAbs) this hk rfl) hj lemma induction_reflect (i : ι) {p : ι → Prop} (h₀ : ∀ i, p i → p (P.reflectionPerm i i)) (h₁ : ∀ i ∈ b.support, p i) (h₂ : ∀ i j, p i → j ∈ b.support → p (P.reflectionPerm j i)) : p i := by letI := P.indexNeg rcases IsPos.or_neg b i with hi | hi · exact hi.induction_on_reflect h₁ h₂ · suffices p (-i) by rw [← neg_neg i]; exact h₀ (-i) this exact hi.induction_on_reflect h₁ h₂ lemma forall_mem_support_invtSubmodule_iff (q : Submodule R M) : (∀ i ∈ b.support, q ∈ invtSubmodule (P.reflection i)) ↔ (∀ i, q ∈ invtSubmodule (P.reflection i)) := by refine ⟨fun hq i ↦ ?_, fun hq i _ ↦ hq i⟩ letI := P.indexNeg have (j : ι) : P.reflection (-j) = P.reflection j := by ext x; simp [reflection_apply, two_smul] refine b.induction_reflect i (by simp_all) hq ?_ clear i intro i j hi hj rw [reflection_reflectionPerm] exact Module.End.invtSubmodule.comp _ (Module.End.invtSubmodule.comp _ (hq j hj) hi) (hq j hj) end PositiveRoots end Base end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/Basic.lean
import Mathlib.LinearAlgebra.RootSystem.Defs import Mathlib.LinearAlgebra.RootSystem.Finite.Nondegenerate /-! # Root data and root systems This file contains basic results for root systems and root data. ## Main definitions / results: * `RootPairing.ext`: In characteristic zero if there is no torsion, the correspondence between roots and coroots is unique. * `RootSystem.ext`: In characteristic zero if there is no torsion, a root system is determined entirely by its roots. * `RootPairing.mk'`: In characteristic zero if there is no torsion, to check that two finite families of roots and coroots form a root pairing, it is sufficient to check that they are stable under reflections. * `RootSystem.mk'`: In characteristic zero if there is no torsion, to check that a finite family of roots form a root system, we do not need to check that the coroots are stable under reflections since this follows from the corresponding property for the roots. -/ open Set Function open Module hiding reflection open Submodule (span) open AddSubgroup (zmultiples) noncomputable section variable {ι R M N : Type*} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] namespace RootPairing section reflectionPerm variable (p : M →ₗ[R] N →ₗ[R] R) (root : ι ↪ M) (coroot : ι ↪ N) (i j : ι) (h : ∀ i, MapsTo (preReflection (root i) (p.flip (coroot i))) (range root) (range root)) include h private theorem exist_eq_reflection_of_mapsTo : ∃ k, root k = (preReflection (root i) (p.flip (coroot i))) (root j) := h i (mem_range_self j) variable (hp : ∀ i, p (root i) (coroot i) = 2) include hp private theorem choose_choose_eq_of_mapsTo : (exist_eq_reflection_of_mapsTo p root coroot i (exist_eq_reflection_of_mapsTo p root coroot i j h).choose h).choose = j := by refine root.injective ?_ rw [(exist_eq_reflection_of_mapsTo p root coroot i _ h).choose_spec, (exist_eq_reflection_of_mapsTo p root coroot i j h).choose_spec] apply involutive_preReflection (x := root i) (hp i) /-- The bijection on the indexing set induced by reflection. -/ @[simps] protected def equiv_of_mapsTo : ι ≃ ι where toFun j := (exist_eq_reflection_of_mapsTo p root coroot i j h).choose invFun j := (exist_eq_reflection_of_mapsTo p root coroot i j h).choose left_inv j := choose_choose_eq_of_mapsTo p root coroot i j h hp right_inv j := choose_choose_eq_of_mapsTo p root coroot i j h hp end reflectionPerm variable (P : RootPairing ι R M N) [Finite ι] /-- Even though the roots may not span, coroots are distinguished by their pairing with the roots. The proof depends crucially on the fact that there are finitely-many roots. Modulo trivial generalisations, this statement is exactly Lemma 1.1.4 on page 87 of SGA 3 XXI. -/ lemma injOn_dualMap_subtype_span_root_coroot [IsAddTorsionFree M] : InjOn ((span R (range P.root)).subtype.dualMap ∘ₗ P.toLinearMap.flip) (range P.coroot) := by have := injOn_dualMap_subtype_span_range_range (finite_range P.root) (c := P.toLinearMap.flip ∘ P.coroot) P.root_coroot_two P.mapsTo_reflection_root rintro - ⟨i, rfl⟩ - ⟨j, rfl⟩ hij exact P.flip.toPerfPair.injective <| this (mem_range_self i) (mem_range_self j) hij /-- In characteristic zero if there is no torsion, the correspondence between roots and coroots is unique. Formally, the point is that the hypothesis `hc` depends only on the range of the coroot mappings. -/ @[ext] protected lemma ext [CharZero R] [NoZeroSMulDivisors R M] {P₁ P₂ : RootPairing ι R M N} (he : P₁.toLinearMap = P₂.toLinearMap) (hr : P₁.root = P₂.root) (hc : range P₁.coroot = range P₂.coroot) : P₁ = P₂ := by have hp (hc' : P₁.coroot = P₂.coroot) : P₁.reflectionPerm = P₂.reflectionPerm := by ext i j refine P₁.root.injective ?_ conv_rhs => rw [hr] simp only [root_reflectionPerm, reflection_apply, coroot'] simp only [hr, he, hc'] suffices P₁.coroot = P₂.coroot by obtain ⟨p₁⟩ := P₁; obtain ⟨p₂⟩ := P₂; grind have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M ext i apply P₁.injOn_dualMap_subtype_span_root_coroot (mem_range_self i) (hc ▸ mem_range_self i) simp only [LinearMap.coe_comp, comp_apply] apply Dual.eq_of_preReflection_mapsTo' (finite_range P₁.root) · exact Submodule.subset_span (mem_range_self i) · exact P₁.coroot_root_two i · exact P₁.mapsTo_reflection_root i · exact hr ▸ he ▸ P₂.coroot_root_two i · exact hr ▸ he ▸ P₂.mapsTo_reflection_root i private lemma coroot_eq_coreflection_of_root_eq' [CharZero R] [NoZeroSMulDivisors R M] (p : M →ₗ[R] N →ₗ[R] R) [p.IsPerfPair] (root : ι ↪ M) (coroot : ι ↪ N) (hp : ∀ i, p (root i) (coroot i) = 2) (hr : ∀ i, MapsTo (preReflection (root i) (p.flip (coroot i))) (range root) (range root)) (hc : ∀ i, MapsTo (preReflection (coroot i) (p (root i))) (range coroot) (range coroot)) {i j k : ι} (hk : root k = preReflection (root i) (p.flip (coroot i)) (root j)) : coroot k = preReflection (coroot i) (p (root i)) (coroot j) := by set α := root i set β := root j set α' := coroot i set β' := coroot j set sα := preReflection α (p.flip α') set sβ := preReflection β (p.flip β') let sα' := preReflection α' (p α) have hij : preReflection (sα β) (p.flip (sα' β')) = sα ∘ₗ sβ ∘ₗ sα := by ext have hpi : (p.flip (coroot i)) (root i) = 2 := by simp [hp i] simp [α, β, α', β', sα, sβ, sα', ← preReflection_preReflection β (p.flip β') hpi, preReflection_apply] obtain ⟨l, hl⟩ := hc i (mem_range_self j) rw [← hl] have hkl : (p.flip (coroot l)) (root k) = 2 := by simp only [hl, preReflection_apply, map_sub, map_smul, hk, LinearMap.flip_apply, LinearMap.sub_apply, hp j, LinearMap.smul_apply, smul_eq_mul, hp i, mul_two, sub_add_cancel_right, mul_neg, sub_neg_eq_add, sα, α, α', β] rw [mul_comm (p (root i) (coroot j))] abel suffices p.flip (coroot k) = p.flip (coroot l) from p.flip.toPerfPair.injective this have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M have := injOn_dualMap_subtype_span_range_range (finite_range root) (c := p.flip ∘ coroot) hp hr apply this (mem_range_self k) (mem_range_self l) refine Dual.eq_of_preReflection_mapsTo' (finite_range root) (Submodule.subset_span <| mem_range_self k) (hp k) (hr k) hkl ?_ rw [comp_apply, hl, hk, hij] exact (hr i).comp <| (hr j).comp (hr i) /-- In characteristic zero if there is no torsion, to check that two finite families of roots and coroots form a root pairing, it is sufficient to check that they are stable under reflections. -/ def mk' [CharZero R] [NoZeroSMulDivisors R M] (p : M →ₗ[R] N →ₗ[R] R) [p.IsPerfPair] (root : ι ↪ M) (coroot : ι ↪ N) (hp : ∀ i, p (root i) (coroot i) = 2) (hr : ∀ i, MapsTo (preReflection (root i) (p.flip (coroot i))) (range root) (range root)) (hc : ∀ i, MapsTo (preReflection (coroot i) (p (root i))) (range coroot) (range coroot)) : RootPairing ι R M N where toLinearMap := p root := root coroot := coroot root_coroot_two := hp reflectionPerm i := RootPairing.equiv_of_mapsTo p root coroot i hr hp reflectionPerm_root i j := by simp [(exist_eq_reflection_of_mapsTo p root coroot i j hr).choose_spec, preReflection_apply] reflectionPerm_coroot i j := by refine (coroot_eq_coreflection_of_root_eq' p root coroot hp hr hc ?_).symm rw [equiv_of_mapsTo_apply, (exist_eq_reflection_of_mapsTo p root coroot i j hr).choose_spec] end RootPairing namespace RootSystem open RootPairing variable [Finite ι] (P : RootSystem ι R M N) /-- In characteristic zero if there is no torsion, a finite root system is determined entirely by its roots. -/ @[ext] protected lemma ext [CharZero R] [NoZeroSMulDivisors R M] {P₁ P₂ : RootSystem ι R M N} (he : P₁.toLinearMap = P₂.toLinearMap) (hr : P₁.root = P₂.root) : P₁ = P₂ := by suffices ∀ P₁ P₂ : RootSystem ι R M N, P₁.toLinearMap = P₂.toLinearMap → P₁.root = P₂.root → range P₁.coroot ⊆ range P₂.coroot by have h₁ := this P₁ P₂ he hr have h₂ := this P₂ P₁ he.symm hr.symm obtain ⟨P₁⟩ := P₁ obtain ⟨P₂⟩ := P₂ congr exact RootPairing.ext he hr (le_antisymm h₁ h₂) clear! P₁ P₂ rintro P₁ P₂ he hr - ⟨i, rfl⟩ use i apply P₁.flip.toPerfPair.injective apply Dual.eq_of_preReflection_mapsTo (finite_range P₁.root) P₁.span_root_eq_top · exact hr ▸ he ▸ P₂.coroot_root_two i · change MapsTo (preReflection _ (P₁.toLinearMap.flip.toPerfPair _)) _ _ simp_rw [hr, he] exact P₂.mapsTo_reflection_root i · exact P₁.coroot_root_two i · exact P₁.mapsTo_reflection_root i private lemma coroot_eq_coreflection_of_root_eq_of_span_eq_top [CharZero R] [NoZeroSMulDivisors R M] (p : M →ₗ[R] N →ₗ[R] R) [p.IsPerfPair] (root : ι ↪ M) (coroot : ι ↪ N) (hp : ∀ i, p (root i) (coroot i) = 2) (hs : ∀ i, MapsTo (preReflection (root i) (p.flip (coroot i))) (range root) (range root)) (hsp : span R (range root) = ⊤) {i j k : ι} (hk : root k = preReflection (root i) (p.flip (coroot i)) (root j)) : coroot k = preReflection (coroot i) (p (root i)) (coroot j) := by set α := root i set β := root j set α' := coroot i set β' := coroot j set sα := preReflection α (p.flip α') set sβ := preReflection β (p.flip β') let sα' := preReflection α' (p α) have hij : preReflection (sα β) (p.flip (sα' β')) = sα ∘ₗ sβ ∘ₗ sα := by ext have hpi : (p.flip (coroot i)) (root i) = 2 := by simp [hp i] simp [α, β, α', β', sα, sβ, sα', ← preReflection_preReflection β (p.flip β') hpi, preReflection_apply] -- v4.7.0-rc1 issues apply p.flip.toPerfPair.injective apply Dual.eq_of_preReflection_mapsTo (finite_range root) hsp (hp k) (hs k) · simp [map_sub, α, β, α', β', sα, hk, preReflection_apply, hp i, hp j, mul_comm (p α β')] ring -- v4.7.0-rc1 issues · rw [hk, LinearMap.toLinearMap_toPerfPair, hij] exact (hs i).comp <| (hs j).comp (hs i) /-- Over a field of characteristic zero, to check that a finite family of roots form a crystallographic root system, we do not need to check that the coroots are stable under reflections since this follows from the corresponding property for the roots. Likewise, we do not need to check that the coroots span. -/ def mk' {k : Type*} [Field k] [CharZero k] [Module k M] [Module k N] (p : M →ₗ[k] N →ₗ[k] k) [p.IsPerfPair] (root : ι ↪ M) (coroot : ι ↪ N) (hp : ∀ i, p (root i) (coroot i) = 2) (hs : ∀ i, MapsTo (preReflection (root i) (p.flip (coroot i))) (range root) (range root)) (hsp : span k (range root) = ⊤) (h_int : ∀ i j, ∃ z : ℤ, z = p (root i) (coroot j)) : RootSystem ι k M N := let P := RootPairing.mk' p root coroot hp hs <| by rintro i - ⟨j, rfl⟩ use RootPairing.equiv_of_mapsTo p root coroot i hs hp j refine (coroot_eq_coreflection_of_root_eq_of_span_eq_top p root coroot hp hs hsp ?_) rw [equiv_of_mapsTo_apply, (exist_eq_reflection_of_mapsTo p root coroot i j hs).choose_spec] have _i : P.IsCrystallographic := ⟨h_int⟩ have _i : Fintype ι := Fintype.ofFinite ι { toRootPairing := P, span_root_eq_top := hsp, span_coroot_eq_top := P.rootSpan_eq_top_iff.mp hsp } end RootSystem
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/WeylGroup.lean
import Mathlib.LinearAlgebra.RootSystem.Hom import Mathlib.RepresentationTheory.Basic /-! # The Weyl group of a root pairing This file defines the Weyl group of a root pairing as the subgroup of automorphisms generated by reflection automorphisms. This deviates from the existing literature, which typically defines the Weyl group as the subgroup of linear transformations of the weight space generated by linear reflections. However, the automorphism group of a root pairing comes with a permutation representation on the set indexing roots and faithful linear representations on the weight space and coweight space. Thus, our formalism gives us an isomorphism to the traditional Weyl group together with the natural dual representation generated by coreflections and the permutation representation on roots. ## Main definitions * `RootPairing.weylGroup` : The group of automorphisms generated by reflections. * `RootPairing.weylGroupToPerm` : The permutation representation of the Weyl group on roots. ## Results * `RootPairing.range_weylGroup_weightHom` : The image of the weight space representation is equal to the subgroup generated by linear reflections. * `RootPairing.range_weylGroup_coweightHom` : The image of the coweight space representation is equal to the subgroup generated by linear coreflections. * `RootPairing.range_weylGroupToPerm` : The image of the permutation representation is equal to the subgroup generated by reflection permutations. ## TODO * faithfulness of `weylGroupToPerm` when multiplication by 2 is injective on the weight space. -/ open Set Function variable {ι R M N : Type*} noncomputable section namespace RootPairing variable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] (P : RootPairing ι R M N) (i : ι) /-- The `Weyl group` of a root pairing is the group of automorphisms of the root pairing generated by reflections. -/ def weylGroup : Subgroup (Aut P) := Subgroup.closure (range (Equiv.reflection P)) lemma reflection_mem_weylGroup : Equiv.reflection P i ∈ P.weylGroup := Subgroup.subset_closure <| mem_range_self i /-- The `ith` reflection as a term of the Weyl group. -/ def weylGroup.ofIdx (i : ι) : P.weylGroup := ⟨_, P.reflection_mem_weylGroup i⟩ @[simp] lemma weylGroup.ofIdx_smul (i : ι) (m : M) : weylGroup.ofIdx P i • m = Equiv.reflection P i • m := rfl /-- Usually `RootPairing.weylGroup.induction` will be more useful than this lemma. -/ lemma weylGroup_toSubmonoid : P.weylGroup.toSubmonoid = Submonoid.closure (range (Equiv.reflection P)) := by suffices range (Equiv.reflection P) = (range (Equiv.reflection P))⁻¹ by rw [weylGroup, Subgroup.closure_toSubmonoid, ← this, union_self] ext; simp [← inv_eq_iff_eq_inv] @[elab_as_elim] lemma weylGroup.induction {pred : (g : Aut P) → g ∈ P.weylGroup → Prop} (mem : ∀ i, pred (Equiv.reflection P i) (P.reflection_mem_weylGroup i)) (one : pred 1 (one_mem _)) (mul : ∀ x y hx hy, pred x hx → pred y hy → pred (x * y) (mul_mem hx hy)) {x} (hx : x ∈ P.weylGroup) : pred x hx := by let pred' : (g : Aut P) → g ∈ Submonoid.closure (range (Equiv.reflection P)) → Prop := fun g hg ↦ pred g <| by change g ∈ P.weylGroup.toSubmonoid; rwa [weylGroup_toSubmonoid] have hx' : x ∈ Submonoid.closure (range (Equiv.reflection P)) := by rwa [← weylGroup_toSubmonoid] suffices pred' x hx' from this apply Submonoid.closure_induction · rintro - ⟨i, rfl⟩ exact mem i · exact one · intro x y hx hy hx' hy' rw [← weylGroup_toSubmonoid] at hx hy exact mul x y hx hy hx' hy' @[elab_as_elim] lemma weylGroup.induction' [Nonempty ι] {pred : (g : Aut P) → g ∈ P.weylGroup → Prop} (mem : ∀ i, pred (Equiv.reflection P i) (P.reflection_mem_weylGroup i)) (mul : ∀ x y hx hy, pred x hx → pred y hy → pred (x * y) (mul_mem hx hy)) {x} (hx : x ∈ P.weylGroup) : pred x hx := by refine weylGroup.induction P mem ?_ mul hx obtain ⟨i⟩ : Nonempty ι := inferInstance have : (Equiv.reflection P i) ^ 2 = 1 := by rw [sq, mul_eq_one_iff_inv_eq, Equiv.reflection_inv P i] simpa [sq, ← this] using mul _ _ _ _ (mem i) (mem i) lemma range_weylGroup_weightHom : MonoidHom.range ((Equiv.weightHom P).restrict P.weylGroup) = Subgroup.closure (range P.reflection) := by refine (Subgroup.closure_eq_of_le _ ?_ ?_).symm · rintro - ⟨i, rfl⟩ simp only [MonoidHom.restrict_range, Subgroup.coe_map, Equiv.weightHom_apply, mem_image, SetLike.mem_coe] use Equiv.reflection P i exact ⟨reflection_mem_weylGroup P i, Equiv.reflection_weightEquiv P i⟩ · rintro fg ⟨⟨w, hw⟩, rfl⟩ induction hw using Subgroup.closure_induction'' with | one => change ((Equiv.weightHom P).restrict P.weylGroup) 1 ∈ _ simp only [map_one, one_mem] | mem w' hw' => obtain ⟨i, rfl⟩ := hw' simp only [MonoidHom.restrict_apply, Equiv.weightHom_apply, Equiv.reflection_weightEquiv] simpa only [reflection_mem_weylGroup] using Subgroup.subset_closure (mem_range_self i) | inv_mem w' hw' => obtain ⟨i, rfl⟩ := hw' simp only [Equiv.reflection_inv, MonoidHom.restrict_apply, Equiv.weightHom_apply, Equiv.reflection_weightEquiv] simpa only [reflection_mem_weylGroup] using Subgroup.subset_closure (mem_range_self i) | mul w₁ w₂ hw₁ hw₂ h₁ h₂ => simpa only [← Submonoid.mk_mul_mk _ w₁ w₂ hw₁ hw₂, map_mul] using Subgroup.mul_mem _ h₁ h₂ lemma range_weylGroup_coweightHom : MonoidHom.range ((Equiv.coweightHom P).restrict P.weylGroup) = Subgroup.closure (range (MulOpposite.op ∘ P.coreflection)) := by refine (Subgroup.closure_eq_of_le _ ?_ ?_).symm · rintro - ⟨i, rfl⟩ simp only [MonoidHom.restrict_range, Subgroup.coe_map, mem_image, SetLike.mem_coe] use Equiv.reflection P i refine ⟨reflection_mem_weylGroup P i, by simp⟩ · rintro fg ⟨⟨w, hw⟩, rfl⟩ induction hw using Subgroup.closure_induction'' with | one => change ((Equiv.coweightHom P).restrict P.weylGroup) 1 ∈ _ simp only [map_one, one_mem] | mem w' hw' => obtain ⟨i, rfl⟩ := hw' simp only [MonoidHom.restrict_apply, Equiv.coweightHom_apply, Equiv.reflection_coweightEquiv] simpa only [reflection_mem_weylGroup] using Subgroup.subset_closure (mem_range_self i) | inv_mem w' hw' => obtain ⟨i, rfl⟩ := hw' simp only [Equiv.reflection_inv, MonoidHom.restrict_apply, Equiv.coweightHom_apply, Equiv.reflection_coweightEquiv] simpa only [reflection_mem_weylGroup] using Subgroup.subset_closure (mem_range_self i) | mul w₁ w₂ hw₁ hw₂ h₁ h₂ => simpa only [← Submonoid.mk_mul_mk _ w₁ w₂ hw₁ hw₂, map_mul] using Subgroup.mul_mem _ h₁ h₂ /-- The permutation representation of the Weyl group induced by `reflectionPerm`. -/ abbrev weylGroupToPerm := (Equiv.indexHom P).restrict P.weylGroup lemma range_weylGroupToPerm : P.weylGroupToPerm.range = Subgroup.closure (range P.reflectionPerm) := by refine (Subgroup.closure_eq_of_le _ ?_ ?_).symm · rintro - ⟨i, rfl⟩ simp only [MonoidHom.restrict_range, Subgroup.coe_map, mem_image, SetLike.mem_coe] use Equiv.reflection P i refine ⟨reflection_mem_weylGroup P i, by simp⟩ · rintro fg ⟨⟨w, hw⟩, rfl⟩ induction hw using Subgroup.closure_induction'' with | one => change ((Equiv.indexHom P).restrict P.weylGroup) 1 ∈ _ simp only [map_one, one_mem] | mem w' hw' => obtain ⟨i, rfl⟩ := hw' simp only [MonoidHom.restrict_apply, Equiv.indexHom_apply, Equiv.reflection_indexEquiv] simpa only [reflection_mem_weylGroup] using Subgroup.subset_closure (mem_range_self i) | inv_mem w' hw' => obtain ⟨i, rfl⟩ := hw' simp only [Equiv.reflection_inv, MonoidHom.restrict_apply, Equiv.indexHom_apply, Equiv.reflection_indexEquiv] simpa only [reflection_mem_weylGroup] using Subgroup.subset_closure (mem_range_self i) | mul w₁ w₂ hw₁ hw₂ h₁ h₂ => simpa only [← Submonoid.mk_mul_mk _ w₁ w₂ hw₁ hw₂, map_mul] using Subgroup.mul_mem _ h₁ h₂ /-- The natural representation of the Weyl group on the root space. -/ def weylGroupRootRep : Representation R P.weylGroup M := Representation.ofDistribMulAction R P.weylGroup M /-- The natural representation of the Weyl group on the coroot space. -/ def weylGroupCorootRep : Representation R P.weylGroup.op N := Representation.ofDistribMulAction R P.weylGroup.op N lemma weylGroup_apply_root (g : P.weylGroup) (i : ι) : g • P.root i = P.root (P.weylGroupToPerm g i) := Hom.root_weightMap_apply _ _ _ _ @[simp] lemma InvariantForm.apply_weylGroup_smul {B : P.InvariantForm} (g : P.weylGroup) (x y : M) : B.form (g • x) (g • y) = B.form x y := by revert x y obtain ⟨g, hg⟩ := g induction hg using weylGroup.induction with | mem i => simp | one => simp | mul g₁ g₂ hg₁ hg₂ hg₁' hg₂' => intro x y rw [← Submonoid.mk_mul_mk _ _ _ hg₁ hg₂, mul_smul, mul_smul, hg₁', hg₂'] end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/Defs.lean
import Mathlib.LinearAlgebra.PerfectPairing.Basic import Mathlib.LinearAlgebra.Reflection /-! # Root data and root systems This file contains basic definitions for root systems and root data. ## Main definitions: * `RootPairing`: Given two perfectly-paired `R`-modules `M` and `N` (over some commutative ring `R`) a root pairing with indexing set `ι` is the data of an `ι`-indexed subset of `M` ("the roots") an `ι`-indexed subset of `N` ("the coroots"), and an `ι`-indexed set of permutations of `ι` such that each root-coroot pair evaluates to `2`, and the permutation attached to each element of `ι` is compatible with the reflections on the corresponding roots and coroots. * `RootDatum`: A root datum is a root pairing for which the roots and coroots take values in finitely-generated free Abelian groups. * `RootSystem`: A root system is a root pairing for which the roots span their ambient module. ## Implementation details A root datum is sometimes defined as two subsets: roots and coroots, together with a bijection between them, subject to hypotheses. However the hypotheses ensure that the bijection is unique and so the question arises of whether this bijection should be part of the data of a root datum or whether one should merely assert its existence. For root systems, things are even more extreme: the coroots are uniquely determined by the roots. Furthermore a root system induces a canonical non-degenerate bilinear form on the ambient space and many informal accounts even include this form as part of the data. We have opted for a design in which some of the uniquely-determined data is included: the bijection between roots and coroots is (implicitly) included and the coroots are included for root systems. Empirically this seems to be by far the most convenient design and by providing extensionality lemmas expressing the uniqueness we expect to get the best of both worlds. Furthermore, we require roots and coroots to be injections from a base indexing type `ι` rather than subsets of their codomains. This design was chosen to avoid the bijection between roots and coroots being a dependently-typed object. A third option would be to have the roots and coroots be subsets but to avoid having a dependently-typed bijection by defining it globally with junk value `0` outside of the roots and coroots. This would work but lacks the convenient symmetry that the chosen design enjoys: by introducing the indexing type `ι`, one does not have to pick a direction (`roots → coroots` or `coroots → roots`) for the forward direction of the bijection. Besides, providing the user with the additional definitional power to specify an indexing type `ι` is a benefit and the junk-value pattern is a cost. As a final point of divergence from the classical literature, we make the reflection permutation on roots and coroots explicit, rather than specifying only that reflection preserves the sets of roots and coroots. This is necessary when working with infinite root systems, where the coroots are not uniquely determined by the roots, because without it, the reflection permutations on roots and coroots may not correspond. For this purpose, we define a map from `ι` to permutations on `ι`, and require that it is compatible with reflections and coreflections. -/ open Set Function open Module hiding reflection open Submodule (span span_image) open AddSubgroup (zmultiples) noncomputable section variable (ι R M N : Type*) [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] /-- Given two perfectly-paired `R`-modules `M` and `N`, a root pairing with indexing set `ι` is the data of an `ι`-indexed subset of `M` ("the roots"), an `ι`-indexed subset of `N` ("the coroots"), and an `ι`-indexed set of permutations of `ι`, such that each root-coroot pair evaluates to `2`, and the permutation attached to each element of `ι` is compatible with the reflections on the corresponding roots and coroots. It exists to allow for a convenient unification of the theories of root systems and root data. -/ structure RootPairing extends M →ₗ[R] N →ₗ[R] R where [isPerfPair_toLinearMap : toLinearMap.IsPerfPair] /-- A parametrized family of vectors, called roots. -/ root : ι ↪ M /-- A parametrized family of dual vectors, called coroots. -/ coroot : ι ↪ N root_coroot_two : ∀ i, toLinearMap (root i) (coroot i) = 2 /-- A parametrized family of permutations, induced by reflections. This corresponds to the classical requirement that the symmetry attached to each root (later defined in `RootPairing.reflection`) leave the whole set of roots stable: as explained above, we formalize this stability by fixing the image of the roots through each reflection (whence the permutation); and similarly for coroots. -/ reflectionPerm : ι → (ι ≃ ι) reflectionPerm_root : ∀ i j, root j - toLinearMap (root j) (coroot i) • root i = root (reflectionPerm i j) reflectionPerm_coroot : ∀ i j, coroot j - toLinearMap (root i) (coroot j) • coroot i = coroot (reflectionPerm i j) attribute [instance] RootPairing.isPerfPair_toLinearMap /-- A root datum is a root pairing with coefficients in the integers and for which the root and coroot spaces are finitely-generated free Abelian groups. Note that the latter assumptions `[Finite ℤ X₁] [Finite ℤ X₂]` should be supplied as mixins, and that freeness follows automatically since two finitely-generated Abelian groups in perfect pairing are necessarily free. Moreover Lean knows this, e.g., via `PerfectPairing.reflexive_left`, `Module.instNoZeroSMulDivisorsOfIsDomain`, `Module.free_of_finite_type_torsion_free'`. -/ abbrev RootDatum (X₁ X₂ : Type*) [AddCommGroup X₁] [AddCommGroup X₂] := RootPairing ι ℤ X₁ X₂ /-- A root system is a root pairing for which the roots and coroots span their ambient modules. Note that this is slightly more general than the usual definition in the sense that `N` is not required to be the dual of `M`. -/ structure RootSystem extends RootPairing ι R M N where span_root_eq_top : span R (range root) = ⊤ span_coroot_eq_top : span R (range coroot) = ⊤ attribute [simp] RootSystem.span_root_eq_top attribute [simp] RootSystem.span_coroot_eq_top namespace RootPairing variable {ι R M N} variable (P : RootPairing ι R M N) (i j : ι) @[deprecated "Now a syntactic equality" (since := "2025-07-05"), nolint synTaut] lemma toLinearMap_eq_toPerfectPairing (x : M) (y : N) : P.toLinearMap x y = P.toLinearMap x y := rfl /-- If we interchange the roles of `M` and `N`, we still have a root pairing. -/ @[simps!, simps toLinearMap] protected def flip : RootPairing ι R N M where toLinearMap := P.toLinearMap.flip root := P.coroot coroot := P.root root_coroot_two := P.root_coroot_two reflectionPerm := P.reflectionPerm reflectionPerm_root := P.reflectionPerm_coroot reflectionPerm_coroot := P.reflectionPerm_root @[simp] lemma flip_flip : P.flip.flip = P := rfl variable (ι R M N) in /-- `RootPairing.flip` as an equivalence. -/ @[simps] def flipEquiv : RootPairing ι R N M ≃ RootPairing ι R M N where toFun P := P.flip invFun P := P.flip /-- If we interchange the roles of `M` and `N`, we still have a root system. -/ protected def _root_.RootSystem.flip (P : RootSystem ι R M N) : RootSystem ι R N M := { toRootPairing := P.toRootPairing.flip span_root_eq_top := P.span_coroot_eq_top span_coroot_eq_top := P.span_root_eq_top } @[simp] protected lemma _root_.RootSystem.flip_flip (P : RootSystem ι R M N) : P.flip.flip = P := rfl variable (ι R M N) in /-- `RootSystem.flip` as an equivalence. -/ @[simps] def _root_.RootSystem.flipEquiv : RootSystem ι R N M ≃ RootSystem ι R M N where toFun P := P.flip invFun P := P.flip lemma ne_zero [NeZero (2 : R)] : (P.root i : M) ≠ 0 := fun h ↦ NeZero.ne' (2 : R) <| by simpa [h] using P.root_coroot_two i lemma ne_zero' [NeZero (2 : R)] : (P.coroot i : N) ≠ 0 := P.flip.ne_zero i lemma zero_notMem_range_root [NeZero (2 : R)] : 0 ∉ range P.root := by simpa only [mem_range, not_exists] using fun i ↦ P.ne_zero i @[deprecated (since := "2025-05-24")] alias zero_nmem_range_root := zero_notMem_range_root lemma zero_notMem_range_coroot [NeZero (2 : R)] : 0 ∉ range P.coroot := P.flip.zero_notMem_range_root @[deprecated (since := "2025-05-24")] alias zero_nmem_range_coroot := zero_notMem_range_coroot lemma exists_ne_zero [Nonempty ι] [NeZero (2 : R)] : ∃ i, P.root i ≠ 0 := by obtain ⟨i⟩ := inferInstanceAs (Nonempty ι) exact ⟨i, P.ne_zero i⟩ lemma exists_ne_zero' [Nonempty ι] [NeZero (2 : R)] : ∃ i, P.coroot i ≠ 0 := P.flip.exists_ne_zero include P in protected lemma nontrivial [Nonempty ι] [NeZero (2 : R)] : Nontrivial M := by obtain ⟨i, hi⟩ := P.exists_ne_zero exact ⟨P.root i, 0, hi⟩ include P in protected lemma nontrivial' [Nonempty ι] [NeZero (2 : R)] : Nontrivial N := P.flip.nontrivial /-- Roots written as functionals on the coweight space. -/ abbrev root' (i : ι) : Dual R N := P.toLinearMap (P.root i) /-- Coroots written as functionals on the weight space. -/ abbrev coroot' (i : ι) : Dual R M := P.toLinearMap.flip (P.coroot i) /-- This is the pairing between roots and coroots. -/ def pairing : R := P.root' i (P.coroot j) @[simp] lemma pairing_flip : P.flip.pairing i j = P.pairing j i := rfl @[simp] lemma root_coroot_eq_pairing : P.toLinearMap (P.root i) (P.coroot j) = P.pairing i j := rfl @[simp] lemma root'_coroot_eq_pairing : P.root' i (P.coroot j) = P.pairing i j := rfl @[simp] lemma root_coroot'_eq_pairing : P.coroot' i (P.root j) = P.pairing j i := rfl lemma coroot_root_eq_pairing : P.toLinearMap.flip (P.coroot i) (P.root j) = P.pairing j i := by simp @[simp] lemma pairing_same : P.pairing i i = 2 := P.root_coroot_two i variable {P} in lemma pairing_eq_add_of_root_eq_add {i j k l : ι} (h : P.root k = P.root i + P.root j) : P.pairing k l = P.pairing i l + P.pairing j l := by simp only [← root_coroot_eq_pairing, h, map_add, LinearMap.add_apply] variable {P} in lemma pairing_eq_add_of_root_eq_smul_add_smul {i j k l : ι} {x y : R} (h : P.root k = x • P.root i + y • P.root l) : P.pairing k j = x • P.pairing i j + y • P.pairing l j := by simp only [← root_coroot_eq_pairing, h, map_add, map_smul, LinearMap.add_apply, LinearMap.smul_apply, smul_eq_mul] lemma coroot_root_two : P.toLinearMap.flip (P.coroot i) (P.root i) = 2 := by simp /-- The reflection associated to a root. -/ def reflection : M ≃ₗ[R] M := Module.reflection (P.flip.root_coroot_two i) @[simp] lemma root_reflectionPerm (j : ι) : P.root (P.reflectionPerm i j) = (P.reflection i) (P.root j) := (P.reflectionPerm_root i j).symm @[deprecated (since := "2025-05-28")] alias root_reflection_perm := root_reflectionPerm theorem mapsTo_reflection_root : MapsTo (P.reflection i) (range P.root) (range P.root) := by rintro - ⟨j, rfl⟩ exact P.root_reflectionPerm i j ▸ mem_range_self (P.reflectionPerm i j) lemma reflection_apply (x : M) : P.reflection i x = x - (P.coroot' i x) • P.root i := rfl lemma reflection_apply_root : P.reflection i (P.root j) = P.root j - (P.pairing j i) • P.root i := rfl @[simp] lemma reflection_apply_self : P.reflection i (P.root i) = - P.root i := Module.reflection_apply_self (P.coroot_root_two i) @[simp] lemma reflection_same (x : M) : P.reflection i (P.reflection i x) = x := Module.involutive_reflection (P.coroot_root_two i) x @[simp] lemma reflection_inv : (P.reflection i)⁻¹ = P.reflection i := rfl @[simp] lemma reflection_sq : P.reflection i ^ 2 = 1 := mul_eq_one_iff_eq_inv.mpr rfl @[simp] lemma reflectionPerm_sq : P.reflectionPerm i ^ 2 = 1 := by ext j apply P.root.injective simp only [sq, Equiv.Perm.mul_apply, root_reflectionPerm, reflection_same, Equiv.Perm.one_apply] @[deprecated (since := "2025-05-28")] alias reflection_perm_sq := reflectionPerm_sq @[simp] lemma reflectionPerm_inv : (P.reflectionPerm i)⁻¹ = P.reflectionPerm i := (mul_eq_one_iff_eq_inv.mp <| P.reflectionPerm_sq i).symm @[deprecated (since := "2025-05-28")] alias reflection_perm_inv := reflectionPerm_inv @[simp] lemma reflectionPerm_self : P.reflectionPerm i (P.reflectionPerm i j) = j := by apply P.root.injective simp only [root_reflectionPerm, reflection_same] @[deprecated (since := "2025-05-28")] alias reflection_perm_self := reflectionPerm_self lemma reflectionPerm_involutive : Involutive (P.reflectionPerm i) := involutive_iff_iter_2_eq_id.mpr (by ext; simp) @[deprecated (since := "2025-05-28")] alias reflection_perm_involutive := reflectionPerm_involutive @[simp] lemma reflectionPerm_symm : (P.reflectionPerm i).symm = P.reflectionPerm i := Involutive.symm_eq_self_of_involutive (P.reflectionPerm i) <| P.reflectionPerm_involutive i @[deprecated (since := "2025-05-28")] alias reflection_perm_symm := reflectionPerm_symm lemma bijOn_reflection_root : BijOn (P.reflection i) (range P.root) (range P.root) := Module.bijOn_reflection_of_mapsTo _ <| P.mapsTo_reflection_root i @[simp] lemma reflection_image_eq : P.reflection i '' (range P.root) = range P.root := (P.bijOn_reflection_root i).image_eq /-- The reflection associated to a coroot. -/ def coreflection : N ≃ₗ[R] N := Module.reflection (P.root_coroot_two i) @[simp] lemma coroot_reflectionPerm (j : ι) : P.coroot (P.reflectionPerm i j) = (P.coreflection i) (P.coroot j) := (P.reflectionPerm_coroot i j).symm @[deprecated (since := "2025-05-28")] alias coroot_reflection_perm := coroot_reflectionPerm theorem mapsTo_coreflection_coroot : MapsTo (P.coreflection i) (range P.coroot) (range P.coroot) := by rintro - ⟨j, rfl⟩ exact P.coroot_reflectionPerm i j ▸ mem_range_self (P.reflectionPerm i j) lemma coreflection_apply (f : N) : P.coreflection i f = f - (P.root' i) f • P.coroot i := rfl lemma coreflection_apply_coroot : P.coreflection i (P.coroot j) = P.coroot j - (P.pairing i j) • P.coroot i := rfl @[simp] lemma coreflection_apply_self : P.coreflection i (P.coroot i) = - P.coroot i := Module.reflection_apply_self (P.flip.coroot_root_two i) @[simp] lemma coreflection_same (x : N) : P.coreflection i (P.coreflection i x) = x := Module.involutive_reflection (P.flip.coroot_root_two i) x @[simp] lemma coreflection_inv : (P.coreflection i)⁻¹ = P.coreflection i := rfl @[simp] lemma coreflection_sq : P.coreflection i ^ 2 = 1 := mul_eq_one_iff_eq_inv.mpr rfl lemma bijOn_coreflection_coroot : BijOn (P.coreflection i) (range P.coroot) (range P.coroot) := bijOn_reflection_root P.flip i @[simp] lemma coreflection_image_eq : P.coreflection i '' (range P.coroot) = range P.coroot := (P.bijOn_coreflection_coroot i).image_eq lemma coreflection_eq_flip_reflection : P.coreflection i = P.flip.reflection i := rfl lemma reflection_reflectionPerm {i j : ι} : P.reflection (P.reflectionPerm j i) = P.reflection j * P.reflection i * P.reflection j := by ext x; simp [reflection_apply, coreflection_apply]; module lemma reflection_dualMap_eq_coreflection : (P.reflection i).dualMap ∘ₗ P.toLinearMap.flip = P.toLinearMap.flip ∘ₗ P.coreflection i := by ext n m simp [map_sub, coreflection_apply, reflection_apply, mul_comm (P.toLinearMap m (P.coroot i))] lemma coroot_eq_coreflection_of_root_eq {i j k : ι} (hk : P.root k = P.reflection i (P.root j)) : P.coroot k = P.coreflection i (P.coroot j) := by rw [← P.root_reflectionPerm, EmbeddingLike.apply_eq_iff_eq] at hk rw [← P.coroot_reflectionPerm, hk] lemma coroot'_reflectionPerm {i j : ι} : P.coroot' (P.reflectionPerm i j) = P.coroot' j ∘ₗ P.reflection i := by ext y simp [coreflection_apply_coroot, reflection_apply, map_sub, mul_comm] @[deprecated (since := "2025-05-28")] alias coroot'_reflection_perm := coroot'_reflectionPerm lemma coroot'_reflection {i j : ι} (y : M) : P.coroot' j (P.reflection i y) = P.coroot' (P.reflectionPerm i j) y := (LinearMap.congr_fun P.coroot'_reflectionPerm y).symm lemma pairing_reflectionPerm (i j k : ι) : P.pairing j (P.reflectionPerm i k) = P.pairing (P.reflectionPerm i j) k := by simp only [pairing, root', coroot_reflectionPerm, root_reflectionPerm] simp [coreflection_apply_coroot, reflection_apply_root, mul_comm] @[deprecated (since := "2025-05-28")] alias pairing_reflection_perm := pairing_reflectionPerm @[simp] lemma toPerfPair_conj_reflection : P.toPerfPair.conj (P.reflection i) = (P.coreflection i).toLinearMap.dualMap := by ext f n simp [LinearEquiv.conj_apply, reflection_apply, coreflection_apply, mul_comm (f <| P.coroot i)] @[simp] lemma toPerfPair_flip_conj_coreflection : P.toLinearMap.flip.toPerfPair.conj (P.coreflection i) = (P.reflection i).toLinearMap.dualMap := P.flip.toPerfPair_conj_reflection i @[simp] lemma pairing_reflectionPerm_self_left (P : RootPairing ι R M N) (i j : ι) : P.pairing (P.reflectionPerm i i) j = - P.pairing i j := by rw [pairing, root', ← reflectionPerm_root, root'_coroot_eq_pairing, pairing_same, two_smul, sub_add_cancel_left, LinearMap.map_neg₂, root'_coroot_eq_pairing] @[deprecated (since := "2025-05-28")] alias pairing_reflection_perm_self_left := pairing_reflectionPerm_self_left @[simp] lemma pairing_reflectionPerm_self_right (i j : ι) : P.pairing i (P.reflectionPerm j j) = - P.pairing i j := by rw [pairing, ← reflectionPerm_coroot, root_coroot_eq_pairing, pairing_same, two_smul, sub_add_cancel_left, map_neg, root_coroot_eq_pairing] @[deprecated (since := "2025-05-28")] alias pairing_reflection_perm_self_right := pairing_reflectionPerm_self_right /-- The indexing set of a root pairing carries an involutive negation, corresponding to the negation of a root / coroot. -/ @[simps] def indexNeg : InvolutiveNeg ι where neg i := P.reflectionPerm i i neg_neg i := by apply P.root.injective simp only [root_reflectionPerm, reflection_apply, LinearMap.flip_apply, root_coroot_eq_pairing, pairing_same, map_sub, coroot_reflectionPerm, coreflection_apply_self, map_neg, neg_smul, sub_neg_eq_add, map_smul, smul_add] module lemma ne_neg [NeZero (2 : R)] [IsDomain R] : letI := P.indexNeg i ≠ -i := by have := Module.IsReflexive.of_isPerfPair P.toLinearMap intro contra replace contra : P.root i = -P.root i := by simpa using congr_arg P.root contra simp [eq_neg_iff_add_eq_zero, ← two_smul R, NeZero.out, P.ne_zero i] at contra variable {i j} in @[simp] lemma root_eq_neg_iff : P.root i = - P.root j ↔ i = P.reflectionPerm j j := by refine ⟨fun h ↦ P.root.injective ?_, fun h ↦ by simp [h]⟩ rw [root_reflectionPerm, reflection_apply_self, h] variable {i j} in @[simp] lemma coroot_eq_neg_iff : P.coroot i = - P.coroot j ↔ i = P.reflectionPerm j j := P.flip.root_eq_neg_iff lemma neg_mem_range_root_iff {x : M} : -x ∈ range P.root ↔ x ∈ range P.root := by suffices ∀ x : M, -x ∈ range P.root → x ∈ range P.root by refine ⟨this x, fun h ↦ ?_⟩ rw [← neg_neg x] at h exact this (-x) h intro y ⟨i, hi⟩ exact ⟨P.reflectionPerm i i, by simp [neg_eq_iff_eq_neg.mpr hi]⟩ lemma neg_mem_range_coroot_iff {x : N} : -x ∈ range P.coroot ↔ x ∈ range P.coroot := P.flip.neg_mem_range_root_iff lemma neg_root_mem : - P.root i ∈ range P.root := ⟨P.reflectionPerm i i, by simp⟩ lemma neg_coroot_mem : - P.coroot i ∈ range P.coroot := P.flip.neg_root_mem i variable {P} in lemma smul_coroot_eq_of_root_eq_smul [Finite ι] [IsAddTorsionFree N] (i j : ι) (t : R) (h : P.root j = t • P.root i) : t • P.coroot j = P.coroot i := by have hij : t * P.pairing i j = 2 := by simpa using ((P.coroot' j).congr_arg h).symm refine Module.eq_of_mapsTo_reflection_of_mem (f := P.root' i) (g := P.root' i) (finite_range P.coroot) (by simp [hij]) (by simp) (by simp [hij]) (by simp) ?_ (P.mapsTo_coreflection_coroot i) (mem_range_self i) convert P.mapsTo_coreflection_coroot j ext x replace h : P.root' j = t • P.root' i := by ext; simp [h, root'] simp [Module.preReflection_apply, coreflection_apply, h, smul_comm _ t, mul_smul] variable {P} in @[simp] lemma coroot_eq_smul_coroot_iff [Finite ι] [IsAddTorsionFree M] [IsAddTorsionFree N] {i j : ι} {t : R} : P.coroot i = t • P.coroot j ↔ P.root j = t • P.root i := ⟨fun h ↦ (P.flip.smul_coroot_eq_of_root_eq_smul j i t h).symm, fun h ↦ (P.smul_coroot_eq_of_root_eq_smul i j t h).symm⟩ lemma mem_range_root_of_mem_range_reflection_of_mem_range_root {r : M ≃ₗ[R] M} {α : M} (hr : r ∈ range P.reflection) (hα : α ∈ range P.root) : r • α ∈ range P.root := by obtain ⟨i, rfl⟩ := hr obtain ⟨j, rfl⟩ := hα exact ⟨P.reflectionPerm i j, P.root_reflectionPerm i j⟩ lemma mem_range_coroot_of_mem_range_coreflection_of_mem_range_coroot {r : N ≃ₗ[R] N} {α : N} (hr : r ∈ range P.coreflection) (hα : α ∈ range P.coroot) : r • α ∈ range P.coroot := by obtain ⟨i, rfl⟩ := hr obtain ⟨j, rfl⟩ := hα exact ⟨P.reflectionPerm i j, P.coroot_reflectionPerm i j⟩ lemma pairing_smul_root_eq (k : ι) (hij : P.reflectionPerm i = P.reflectionPerm j) : P.pairing k i • P.root i = P.pairing k j • P.root j := by have h : P.reflection i (P.root k) = P.reflection j (P.root k) := by simp only [← root_reflectionPerm, hij] simpa only [reflection_apply_root, sub_right_inj] using h lemma pairing_smul_coroot_eq (k : ι) (hij : P.reflectionPerm i = P.reflectionPerm j) : P.pairing i k • P.coroot i = P.pairing j k • P.coroot j := by have h : P.coreflection i (P.coroot k) = P.coreflection j (P.coroot k) := by simp only [← coroot_reflectionPerm, hij] simpa only [coreflection_apply_coroot, sub_right_inj] using h lemma two_nsmul_reflection_eq_of_perm_eq (hij : P.reflectionPerm i = P.reflectionPerm j) : 2 • ⇑(P.reflection i) = 2 • P.reflection j := by ext x suffices 2 • P.toLinearMap x (P.coroot i) • P.root i = 2 • P.toLinearMap x (P.coroot j) • P.root j by simpa [reflection_apply, smul_sub] calc 2 • P.toLinearMap x (P.coroot i) • P.root i = P.toLinearMap x (P.coroot i) • ((2 : R) • P.root i) := ?_ _ = P.toLinearMap x (P.coroot i) • (P.pairing i j • P.root j) := ?_ _ = P.toLinearMap x (P.pairing i j • P.coroot i) • (P.root j) := ?_ _ = P.toLinearMap x ((2 : R) • P.coroot j) • (P.root j) := ?_ _ = 2 • P.toLinearMap x (P.coroot j) • P.root j := ?_ · rw [smul_comm, ← Nat.cast_smul_eq_nsmul R, Nat.cast_ofNat] · rw [P.pairing_smul_root_eq j i i hij.symm, pairing_same] · rw [← smul_comm, ← smul_assoc, map_smul] · rw [← P.pairing_smul_coroot_eq j i j hij.symm, pairing_same] · rw [map_smul, smul_assoc, ← Nat.cast_smul_eq_nsmul R, Nat.cast_ofNat] lemma reflectionPerm_eq_reflectionPerm_iff_of_isSMulRegular (h2 : IsSMulRegular M 2) : P.reflectionPerm i = P.reflectionPerm j ↔ P.reflection i = P.reflection j := by refine ⟨fun h ↦ ?_, fun h ↦ Equiv.ext fun k ↦ P.root.injective <| by simp [h]⟩ suffices ⇑(P.reflection i) = ⇑(P.reflection j) from DFunLike.coe_injective this replace h2 : IsSMulRegular (M → M) 2 := IsSMulRegular.pi fun _ ↦ h2 exact h2 <| P.two_nsmul_reflection_eq_of_perm_eq i j h @[deprecated (since := "2025-05-28")] alias reflection_perm_eq_reflection_perm_iff_of_isSMulRegular := reflectionPerm_eq_reflectionPerm_iff_of_isSMulRegular lemma reflectionPerm_eq_reflectionPerm_iff_of_span : P.reflectionPerm i = P.reflectionPerm j ↔ ∀ x ∈ span R (range P.root), P.reflection i x = P.reflection j x := by refine ⟨fun h x hx ↦ ?_, fun h ↦ ?_⟩ · induction hx using Submodule.span_induction with | mem x hx => obtain ⟨k, rfl⟩ := hx simp only [← root_reflectionPerm, h] | zero => simp | add x y _ _ hx hy => simp [hx, hy] | smul t x _ hx => simp [hx] · ext k apply P.root.injective simp [h (P.root k) (Submodule.subset_span <| mem_range_self k)] @[deprecated (since := "2025-05-28")] alias reflection_perm_eq_reflection_perm_iff_of_span := reflectionPerm_eq_reflectionPerm_iff_of_span lemma _root_.RootSystem.reflectionPerm_eq_reflectionPerm_iff (P : RootSystem ι R M N) (i j : ι) : P.reflectionPerm i = P.reflectionPerm j ↔ P.reflection i = P.reflection j := by refine ⟨fun h ↦ ?_, fun h ↦ Equiv.ext fun k ↦ P.root.injective <| by simp [h]⟩ ext x exact (P.reflectionPerm_eq_reflectionPerm_iff_of_span i j).mp h x <| by simp @[deprecated (since := "2025-05-28")] alias _root_.RootSystem.reflection_perm_eq_reflection_perm_iff := _root_.RootSystem.reflectionPerm_eq_reflectionPerm_iff @[simp] lemma toPerfPair_comp_root : P.toPerfPair ∘ P.root = P.root' := rfl @[simp] lemma toPerfPair_flip_comp_coroot : P.toLinearMap.flip.toPerfPair ∘ P.coroot = P.coroot' := rfl /-- The Coxeter Weight of a pair gives the weight of an edge in a Coxeter diagram, when it is finite. It is `4 cos² θ`, where `θ` describes the dihedral angle between hyperplanes. -/ def coxeterWeight : R := pairing P i j * pairing P j i @[simp] lemma coxeterWeight_flip : P.flip.coxeterWeight i j = P.coxeterWeight i j := by simp [coxeterWeight, mul_comm (P.pairing j i)] lemma coxeterWeight_swap : coxeterWeight P i j = coxeterWeight P j i := by simp only [coxeterWeight, mul_comm] /-- Two roots are orthogonal when they are fixed by each others' reflections. -/ def IsOrthogonal : Prop := pairing P i j = 0 ∧ pairing P j i = 0 lemma isOrthogonal_symm : IsOrthogonal P i j ↔ IsOrthogonal P j i := by simp only [IsOrthogonal, and_comm] lemma isOrthogonal_comm (h : IsOrthogonal P i j) : Commute (P.reflection i) (P.reflection j) := by rw [commute_iff_eq] ext v replace h : P.pairing i j = 0 ∧ P.pairing j i = 0 := by simpa [IsOrthogonal] using h erw [Module.End.mul_apply, Module.End.mul_apply] simp only [LinearEquiv.coe_coe, reflection_apply, LinearMap.flip_apply, map_sub, map_smul, root_coroot_eq_pairing, h, zero_smul, sub_zero] abel variable {P i j} lemma IsOrthogonal.flip (h : IsOrthogonal P i j) : IsOrthogonal P.flip i j := ⟨h.2, h.1⟩ lemma IsOrthogonal.symm (h : IsOrthogonal P i j) : IsOrthogonal P j i := ⟨h.2, h.1⟩ lemma IsOrthogonal.reflection_apply_left (h : IsOrthogonal P i j) : P.reflection j (P.root i) = P.root i := by simp [reflection_apply, h.1] lemma IsOrthogonal.reflection_apply_right (h : IsOrthogonal P j i) : P.reflection j (P.root i) = P.root i := h.symm.reflection_apply_left lemma IsOrthogonal.coreflection_apply_left (h : IsOrthogonal P i j) : P.coreflection j (P.coroot i) = P.coroot i := h.flip.reflection_apply_left lemma IsOrthogonal.coreflection_apply_right (h : IsOrthogonal P j i) : P.coreflection j (P.coroot i) = P.coroot i := h.flip.reflection_apply_right lemma isFixedPt_reflection_of_isOrthogonal {s : Set ι} (hj : ∀ i ∈ s, P.IsOrthogonal j i) {x : M} (hx : x ∈ span R (P.root '' s)) : IsFixedPt (P.reflection j) x := by rw [IsFixedPt] induction hx using Submodule.span_induction with | zero => rw [map_zero] | add u v hu hv hu' hv' => rw [map_add, hu', hv'] | smul t u hu hu' => rw [map_smul, hu'] | mem u hu => obtain ⟨i, his, rfl⟩ := hu exact IsOrthogonal.reflection_apply_right <| hj i his lemma reflectionPerm_eq_of_pairing_eq_zero (h : P.pairing j i = 0) : P.reflectionPerm i j = j := P.root.injective <| by simp [reflection_apply, h] @[deprecated (since := "2025-05-28")] alias reflection_perm_eq_of_pairing_eq_zero := reflectionPerm_eq_of_pairing_eq_zero lemma reflectionPerm_eq_of_pairing_eq_zero' (h : P.pairing i j = 0) : P.reflectionPerm i j = j := P.flip.reflectionPerm_eq_of_pairing_eq_zero h @[deprecated (since := "2025-05-28")] alias reflection_perm_eq_of_pairing_eq_zero' := reflectionPerm_eq_of_pairing_eq_zero' lemma reflectionPerm_eq_iff_smul_root : P.reflectionPerm i j = j ↔ P.pairing j i • P.root i = 0 := ⟨fun h ↦ by simpa [h] using P.reflectionPerm_root i j, fun h ↦ P.root.injective <| by simp [reflection_apply, h]⟩ @[deprecated (since := "2025-05-28")] alias reflection_perm_eq_iff_smul_root := reflectionPerm_eq_iff_smul_root lemma reflectionPerm_eq_iff_smul_coroot : P.reflectionPerm i j = j ↔ P.pairing i j • P.coroot i = 0 := P.flip.reflectionPerm_eq_iff_smul_root @[deprecated (since := "2025-05-28")] alias reflection_perm_eq_iff_smul_coroot := reflectionPerm_eq_iff_smul_coroot lemma pairing_eq_zero_iff [NeZero (2 : R)] [NoZeroSMulDivisors R M] : P.pairing i j = 0 ↔ P.pairing j i = 0 := by suffices ∀ {i j : ι}, P.pairing i j = 0 → P.pairing j i = 0 from ⟨this, this⟩ intro i j h simpa [P.ne_zero i, reflectionPerm_eq_iff_smul_root] using P.reflectionPerm_eq_of_pairing_eq_zero' h lemma pairing_eq_zero_iff' [NeZero (2 : R)] [IsDomain R] : P.pairing i j = 0 ↔ P.pairing j i = 0 := by have : IsReflexive R M := .of_isPerfPair P.toLinearMap exact pairing_eq_zero_iff lemma coxeterWeight_zero_iff_isOrthogonal [NeZero (2 : R)] [IsDomain R] : P.coxeterWeight i j = 0 ↔ P.IsOrthogonal i j := by have : IsReflexive R M := .of_isPerfPair P.toLinearMap simp [coxeterWeight, IsOrthogonal, P.pairing_eq_zero_iff (i := i) (j := j)] lemma isOrthogonal_iff_pairing_eq_zero [NeZero (2 : R)] [NoZeroSMulDivisors R M] : P.IsOrthogonal i j ↔ P.pairing i j = 0 := ⟨fun h ↦ h.1, fun h ↦ ⟨h, pairing_eq_zero_iff.mp h⟩⟩ lemma isFixedPt_reflectionPerm_iff [NeZero (2 : R)] [NoZeroSMulDivisors R M] : IsFixedPt (P.reflectionPerm i) j ↔ P.pairing i j = 0 := by refine ⟨fun h ↦ ?_, P.reflectionPerm_eq_of_pairing_eq_zero'⟩ simpa [P.ne_zero i, pairing_eq_zero_iff, IsFixedPt, reflectionPerm_eq_iff_smul_root] using h @[deprecated (since := "2025-05-28")] alias isFixedPt_reflection_perm_iff := isFixedPt_reflectionPerm_iff section Map variable {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] /-- Push forward a root pairing along linear equivalences, also reindexing the (co)roots. -/ protected def map (e : ι ≃ ι₂) (f : M ≃ₗ[R] M₂) (g : N ≃ₗ[R] N₂) : RootPairing ι₂ R M₂ N₂ where __ := (f.symm.trans P.toPerfPair).trans g.symm.dualMap isPerfPair_toLinearMap := by have : IsReflexive R N := .of_isPerfPair P.flip.toLinearMap have : IsReflexive R N₂ := equiv g infer_instance root := (e.symm.toEmbedding.trans P.root).trans f.toEmbedding coroot := (e.symm.toEmbedding.trans P.coroot).trans g.toEmbedding root_coroot_two i := by simp reflectionPerm i := e.symm.trans <| (P.reflectionPerm (e.symm i)).trans e reflectionPerm_root i j := by simp [reflection_apply] reflectionPerm_coroot i j := by simp [coreflection_apply] /-- Push forward a root system along linear equivalences, also reindexing the (co)roots. -/ protected def _root_.RootSystem.map {P : RootSystem ι R M N} (e : ι ≃ ι₂) (f : M ≃ₗ[R] M₂) (g : N ≃ₗ[R] N₂) : RootSystem ι₂ R M₂ N₂ where __ := P.toRootPairing.map e f g span_root_eq_top := by simp [Embedding.coe_trans, range_comp, span_image, RootPairing.map] span_coroot_eq_top := by simp [Embedding.coe_trans, range_comp, span_image, RootPairing.map] end Map end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/IsValuedIn.lean
import Mathlib.Algebra.Module.Submodule.Invariant import Mathlib.LinearAlgebra.RootSystem.Defs /-! # Root pairings taking values in a subring This file lays out the basic theory of root pairings over a commutative ring `R`, where `R` is an `S`-algebra, and the pairing between roots and coroots takes values in `S`. The main application of this theory is the theory of crystallographic root systems, where `S = ℤ`. ## Main definitions: * `RootPairing.IsValuedIn`: Given a commutative ring `S` and an `S`-algebra `R`, a root pairing over `R` is valued in `S` if all root-coroot pairings lie in the image of `algebraMap S R`. * `RootPairing.IsCrystallographic`: A root pairing is said to be crystallographic if the pairing between a root and coroot is always an integer. * `RootPairing.pairingIn`: The `S`-valued pairing between roots and coroots. * `RootPairing.coxeterWeightIn`: The product of `pairingIn i j` and `pairingIn j i`. -/ open Set Function open Submodule (span) open Module noncomputable section namespace RootPairing variable {ι R S M N : Type*} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] (P : RootPairing ι R M N) (i j : ι) /-- If `R` is an `S`-algebra, a root pairing over `R` is said to be valued in `S` if the pairing between a root and coroot always belongs to `S`. Of particular interest is the case `S = ℤ`. See `RootPairing.IsCrystallographic`. -/ @[mk_iff] class IsValuedIn (S : Type*) [CommRing S] [Algebra S R] : Prop where exists_value : ∀ i j, ∃ s, algebraMap S R s = P.pairing i j protected alias exists_value := IsValuedIn.exists_value /-- A root pairing is said to be crystallographic if the pairing between a root and coroot is always an integer. -/ abbrev IsCrystallographic := P.IsValuedIn ℤ instance : P.IsValuedIn R where exists_value i j := by simp variable (S : Type*) [CommRing S] [Algebra S R] variable {S} in lemma isValuedIn_iff_mem_range : P.IsValuedIn S ↔ ∀ i j, P.pairing i j ∈ range (algebraMap S R) := by simp only [isValuedIn_iff, mem_range] instance [P.IsValuedIn S] : P.flip.IsValuedIn S := by rw [isValuedIn_iff, forall_comm] exact P.exists_value /-- A variant of `RootPairing.pairing` for root pairings which are valued in a smaller set of coefficients. Note that it is uniquely-defined only when the map `S → R` is injective, i.e., when we have `[FaithfulSMul S R]`. -/ def pairingIn [P.IsValuedIn S] (i j : ι) : S := (P.exists_value i j).choose @[simp] lemma algebraMap_pairingIn [P.IsValuedIn S] (i j : ι) : algebraMap S R (P.pairingIn S i j) = P.pairing i j := (P.exists_value i j).choose_spec @[simp] lemma pairingIn_same [FaithfulSMul S R] [P.IsValuedIn S] (i : ι) : P.pairingIn S i i = 2 := FaithfulSMul.algebraMap_injective S R <| by simp [map_ofNat] variable {P S} in lemma pairingIn_eq_add_of_root_eq_add [FaithfulSMul S R] [P.IsValuedIn S] {i j k l : ι} (h : P.root k = P.root i + P.root l) : P.pairingIn S k j = P.pairingIn S i j + P.pairingIn S l j := by apply FaithfulSMul.algebraMap_injective S R simpa [← P.algebraMap_pairingIn S, -algebraMap_pairingIn] using pairing_eq_add_of_root_eq_add h variable {P S} in lemma pairingIn_eq_add_of_root_eq_smul_add_smul [FaithfulSMul S R] [P.IsValuedIn S] [Module S M] [IsScalarTower S R M] {i j k l : ι} {x y : S} (h : P.root k = x • P.root i + y • P.root l) : P.pairingIn S k j = x • P.pairingIn S i j + y • P.pairingIn S l j := by apply FaithfulSMul.algebraMap_injective S R replace h : P.root k = (algebraMap S R x) • P.root i + (algebraMap S R y) • P.root l := by simpa simpa [← P.algebraMap_pairingIn S, -algebraMap_pairingIn] using pairing_eq_add_of_root_eq_smul_add_smul h lemma pairingIn_reflectionPerm [FaithfulSMul S R] [P.IsValuedIn S] (i j k : ι) : P.pairingIn S j (P.reflectionPerm i k) = P.pairingIn S (P.reflectionPerm i j) k := by simp only [← (FaithfulSMul.algebraMap_injective S R).eq_iff, algebraMap_pairingIn] exact pairing_reflectionPerm P i j k @[deprecated (since := "2025-05-28")] alias pairingIn_reflection_perm := pairingIn_reflectionPerm @[simp] lemma pairingIn_reflectionPerm_self_left [FaithfulSMul S R] [P.IsValuedIn S] (i j : ι) : P.pairingIn S (P.reflectionPerm i i) j = - P.pairingIn S i j := by simp [← (FaithfulSMul.algebraMap_injective S R).eq_iff] @[deprecated (since := "2025-05-28")] alias pairingIn_reflection_perm_self_left := pairingIn_reflectionPerm_self_left @[simp] lemma pairingIn_reflectionPerm_self_right [FaithfulSMul S R] [P.IsValuedIn S] (i j : ι) : P.pairingIn S i (P.reflectionPerm j j) = - P.pairingIn S i j := by simp [← (FaithfulSMul.algebraMap_injective S R).eq_iff] @[deprecated (since := "2025-05-28")] alias pairingIn_reflection_perm_self_right := pairingIn_reflectionPerm_self_right lemma IsValuedIn.trans (T : Type*) [CommRing T] [Algebra T S] [Algebra T R] [IsScalarTower T S R] [P.IsValuedIn T] : P.IsValuedIn S where exists_value i j := by use algebraMap T S (P.pairingIn T i j) simp [← RingHom.comp_apply, ← IsScalarTower.algebraMap_eq T S R] lemma coroot'_apply_apply_mem_of_mem_span [Module S M] [IsScalarTower S R M] [P.IsValuedIn S] {x : M} (hx : x ∈ span S (range P.root)) (i : ι) : P.coroot' i x ∈ range (algebraMap S R) := by rw [show range (algebraMap S R) = LinearMap.range (Algebra.linearMap S R) by ext; simp] induction hx using Submodule.span_induction with | mem x hx => obtain ⟨k, rfl⟩ := hx simpa using RootPairing.exists_value k i | zero => simp | add x y _ _ hx hy => simpa only [map_add] using add_mem hx hy | smul t x _ hx => simpa only [LinearMap.map_smul_of_tower] using Submodule.smul_mem _ t hx lemma root'_apply_apply_mem_of_mem_span [Module S N] [IsScalarTower S R N] [P.IsValuedIn S] {x : N} (hx : x ∈ span S (range P.coroot)) (i : ι) : P.root' i x ∈ LinearMap.range (Algebra.linearMap S R) := P.flip.coroot'_apply_apply_mem_of_mem_span S hx i /-- The `S`-span of roots. -/ abbrev rootSpan [Module S M] := span S (range P.root) /-- The `S`-span of coroots. -/ abbrev corootSpan [Module S N] := span S (range P.coroot) instance [Module S M] [Finite ι] : Module.Finite S <| P.rootSpan S := Finite.span_of_finite S <| finite_range _ instance [Module S N] [Finite ι] : Module.Finite S <| P.corootSpan S := Finite.span_of_finite S <| finite_range _ /-- A root, seen as an element of the span of roots. -/ abbrev rootSpanMem [Module S M] (i : ι) : P.rootSpan S := ⟨P.root i, Submodule.subset_span (mem_range_self i)⟩ /-- A coroot, seen as an element of the span of coroots. -/ abbrev corootSpanMem [Module S N] (i : ι) : P.corootSpan S := ⟨P.coroot i, Submodule.subset_span (mem_range_self i)⟩ omit [Algebra S R] in lemma rootSpanMem_reflectionPerm_self [Module S M] (i : ι) : P.rootSpanMem S (P.reflectionPerm i i) = - P.rootSpanMem S i := by ext; simp @[deprecated (since := "2025-05-28")] alias rootSpanMem_reflection_perm_self := rootSpanMem_reflectionPerm_self omit [Algebra S R] in lemma corootSpanMem_reflectionPerm_self [Module S N] (i : ι) : P.corootSpanMem S (P.reflectionPerm i i) = - P.corootSpanMem S i := by ext; simp @[deprecated (since := "2025-05-28")] alias corootSpanMem_reflection_perm_self := corootSpanMem_reflectionPerm_self /-- The `S`-linear map on the span of coroots given by evaluating at a root. -/ def root'In [Module S N] [IsScalarTower S R N] [FaithfulSMul S R] [P.IsValuedIn S] (i : ι) : Dual S (P.corootSpan S) := LinearMap.restrictScalarsRange (P.corootSpan S).subtype (Algebra.linearMap S R) (FaithfulSMul.algebraMap_injective S R) (P.root' i) (fun m ↦ P.root'_apply_apply_mem_of_mem_span S m.2 i) @[simp] lemma algebraMap_root'In_apply [Module S N] [IsScalarTower S R N] [FaithfulSMul S R] [P.IsValuedIn S] (i : ι) (x : P.corootSpan S) : algebraMap S R (P.root'In S i x) = P.root' i x := by rw [root'In, ← Algebra.linearMap_apply, LinearMap.restrictScalarsRange_apply, Submodule.subtype_apply] @[simp] lemma root'In_corootSpanMem_eq_pairingIn [Module S N] [IsScalarTower S R N] [FaithfulSMul S R] [P.IsValuedIn S] : P.root'In S i (P.corootSpanMem S j) = P.pairingIn S i j := rfl /-- The `S`-linear map on the span of roots given by evaluating at a coroot. -/ def coroot'In [Module S M] [IsScalarTower S R M] [FaithfulSMul S R] [P.IsValuedIn S] (i : ι) : Dual S (P.rootSpan S) := P.flip.root'In S i @[simp] lemma algebraMap_coroot'In_apply [Module S M] [IsScalarTower S R M] [FaithfulSMul S R] [P.IsValuedIn S] (i : ι) (x : P.rootSpan S) : algebraMap S R (P.coroot'In S i x) = P.coroot' i x := P.flip.algebraMap_root'In_apply S i x @[simp] lemma coroot'In_rootSpanMem_eq_pairingIn [Module S M] [IsScalarTower S R M] [FaithfulSMul S R] [P.IsValuedIn S] : P.coroot'In S i (P.rootSpanMem S j) = P.pairingIn S j i := rfl omit [Algebra S R] in lemma rootSpan_ne_bot [Module S M] [Nonempty ι] [NeZero (2 : R)] : P.rootSpan S ≠ ⊥ := by simpa [rootSpan] using P.exists_ne_zero omit [Algebra S R] in lemma corootSpan_ne_bot [Module S N] [Nonempty ι] [NeZero (2 : R)] : P.corootSpan S ≠ ⊥ := P.flip.rootSpan_ne_bot S lemma rootSpan_mem_invtSubmodule_reflection (i : ι) : P.rootSpan R ∈ Module.End.invtSubmodule (P.reflection i) := by rw [Module.End.mem_invtSubmodule, rootSpan] intro x hx induction hx using Submodule.span_induction with | mem y hy => obtain ⟨j, rfl⟩ := hy rw [Submodule.mem_comap, LinearEquiv.coe_coe, reflection_apply_root] apply Submodule.sub_mem · exact Submodule.subset_span <| mem_range_self j · exact Submodule.smul_mem _ _ <| Submodule.subset_span <| mem_range_self i | zero => simp | add y z hy hz hy' hz' => simpa using Submodule.add_mem _ hy' hz' | smul y t hy hy' => simpa using Submodule.smul_mem _ _ hy' lemma corootSpan_mem_invtSubmodule_coreflection (i : ι) : P.corootSpan R ∈ Module.End.invtSubmodule (P.coreflection i) := P.flip.rootSpan_mem_invtSubmodule_reflection i lemma rootSpan_dualAnnihilator_map_eq_iInf_ker_root' : (P.rootSpan R).dualAnnihilator.map P.flip.toPerfPair.symm = ⨅ i, LinearMap.ker (P.root' i) := SetLike.coe_injective <| by ext; simp [LinearEquiv.symm_apply_eq, subset_def] lemma corootSpan_dualAnnihilator_map_eq_iInf_ker_coroot' : (P.corootSpan R).dualAnnihilator.map P.toPerfPair.symm = ⨅ i, LinearMap.ker (P.coroot' i) := P.flip.rootSpan_dualAnnihilator_map_eq_iInf_ker_root' lemma rootSpan_dualAnnihilator_map_eq : (P.rootSpan R).dualAnnihilator.map P.flip.toPerfPair.symm = (span R (range P.root')).dualCoannihilator := SetLike.coe_injective <| by ext; simp [LinearEquiv.symm_apply_eq, subset_def] lemma corootSpan_dualAnnihilator_map_eq : (P.corootSpan R).dualAnnihilator.map P.toPerfPair.symm = (span R (range P.coroot')).dualCoannihilator := P.flip.rootSpan_dualAnnihilator_map_eq lemma iInf_ker_root'_eq : ⨅ i, LinearMap.ker (P.root' i) = (span R (range P.root')).dualCoannihilator := by rw [← rootSpan_dualAnnihilator_map_eq, rootSpan_dualAnnihilator_map_eq_iInf_ker_root'] lemma iInf_ker_coroot'_eq : ⨅ i, LinearMap.ker (P.coroot' i) = (span R (range P.coroot')).dualCoannihilator := P.flip.iInf_ker_root'_eq @[simp] lemma rootSpan_map_toPerfPair : (P.rootSpan R).map P.toPerfPair = span R (range P.root') := by rw [rootSpan, Submodule.map_span, ← image_univ, ← image_comp, image_univ, toPerfPair_comp_root] @[simp] lemma corootSpan_map_flip_toPerfPair : (P.corootSpan R).map P.toLinearMap.flip.toPerfPair = span R (range P.coroot') := P.flip.rootSpan_map_toPerfPair @[simp] lemma span_root'_eq_top (P : RootSystem ι R M N) : span R (range P.root') = ⊤ := by simp [← rootSpan_map_toPerfPair] @[simp] lemma span_coroot'_eq_top (P : RootSystem ι R M N) : span R (range P.coroot') = ⊤ := span_root'_eq_top P.flip lemma pairingIn_eq_zero_iff {S : Type*} [CommRing S] [Algebra S R] [FaithfulSMul S R] [P.IsValuedIn S] [NoZeroSMulDivisors R M] [NeZero (2 : R)] {i j : ι} : P.pairingIn S i j = 0 ↔ P.pairingIn S j i = 0 := by simpa only [← FaithfulSMul.algebraMap_eq_zero_iff S R, algebraMap_pairingIn] using P.pairing_eq_zero_iff variable {P i j} in lemma reflection_apply_root' (S : Type*) [CommRing S] [Algebra S R] [Module S M] [IsScalarTower S R M] [P.IsValuedIn S] : P.reflection i (P.root j) = P.root j - (P.pairingIn S j i) • P.root i := by rw [reflection_apply_root, ← P.algebraMap_pairingIn S, algebraMap_smul] /-- A variant of `RootPairing.coxeterWeight` for root pairings which are valued in a smaller set of coefficients. Note that it is uniquely-defined only when the map `S → R` is injective, i.e., when we have `[FaithfulSMul S R]`. -/ def coxeterWeightIn (S : Type*) [CommRing S] [Algebra S R] [P.IsValuedIn S] (i j : ι) : S := P.pairingIn S i j * P.pairingIn S j i @[simp] lemma algebraMap_coxeterWeightIn (S : Type*) [CommRing S] [Algebra S R] [P.IsValuedIn S] (i j : ι) : algebraMap S R (P.coxeterWeightIn S i j) = P.coxeterWeight i j := by simp [coxeterWeightIn, coxeterWeight] end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/OfBilinear.lean
import Mathlib.LinearAlgebra.RootSystem.Defs /-! # Root pairings made from bilinear forms A common construction of root systems is given by taking the set of all vectors in an integral lattice for which reflection yields an automorphism of the lattice. In this file, we generalize this construction, replacing the ring of integers with an arbitrary commutative ring and the integral lattice with an arbitrary reflexive module equipped with a bilinear form. ## Main definitions: * `LinearMap.IsReflective`: Length is a regular value of `R`, and reflection is definable. * `LinearMap.IsReflective.coroot`: The coroot corresponding to a reflective vector. * `RootPairing.of_Bilinear`: The root pairing whose roots are reflective vectors. ## TODO * properties -/ open Set Function Module noncomputable section variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] namespace LinearMap /-- A vector `x` is reflective with respect to a bilinear form if multiplication by its norm is injective, and for any vector `y`, the norm of `x` divides twice the inner product of `x` and `y`. These conditions are what we need when describing reflection as a map taking `y` to `y - 2 • (B x y) / (B x x) • x`. -/ structure IsReflective (B : M →ₗ[R] M →ₗ[R] R) (x : M) : Prop where regular : IsRegular (B x x) dvd_two_mul : ∀ y, B x x ∣ 2 * B x y variable (B : M →ₗ[R] M →ₗ[R] R) {x : M} namespace IsReflective lemma of_dvd_two [IsCancelMulZero R] [NeZero (2 : R)] (hx : B x x ∣ 2) : IsReflective B x where regular := isRegular_of_ne_zero <| fun contra ↦ by simp [contra, two_ne_zero (α := R)] at hx dvd_two_mul y := hx.mul_right (B x y) variable (hx : IsReflective B x) /-- The coroot attached to a reflective vector. -/ def coroot : M →ₗ[R] R where toFun y := (hx.2 y).choose map_add' a b := by refine hx.1.1 ?_ simp only rw [← (hx.2 (a + b)).choose_spec, mul_add, ← (hx.2 a).choose_spec, ← (hx.2 b).choose_spec, map_add, mul_add] map_smul' r a := by refine hx.1.1 ?_ simp only [RingHom.id_apply] rw [← (hx.2 (r • a)).choose_spec, smul_eq_mul, mul_left_comm, ← (hx.2 a).choose_spec, map_smul, two_mul, smul_eq_mul, two_mul, mul_add] @[simp] lemma apply_self_mul_coroot_apply {y : M} : B x x * coroot B hx y = 2 * B x y := (hx.dvd_two_mul y).choose_spec.symm @[simp] lemma smul_coroot : B x x • coroot B hx = 2 • B x := by ext y simp [smul_apply, smul_eq_mul, nsmul_eq_mul, Nat.cast_ofNat, apply_self_mul_coroot_apply] @[simp] lemma coroot_apply_self : coroot B hx x = 2 := hx.regular.left <| by simp [mul_comm _ (B x x)] lemma isOrthogonal_reflection (hSB : LinearMap.IsSymm B) : B.IsOrthogonal (Module.reflection (coroot_apply_self B hx)) := by intro y z simp only [reflection_apply, LinearMap.map_sub, map_smul, sub_apply, smul_apply, smul_eq_mul] refine hx.1.1 ?_ simp only [mul_sub, ← mul_assoc, apply_self_mul_coroot_apply] rw [sub_eq_iff_eq_add, ← hSB.eq x y, RingHom.id_apply, mul_assoc _ _ (B x x), mul_comm _ (B x x), apply_self_mul_coroot_apply] ring lemma reflective_reflection (hSB : LinearMap.IsSymm B) {y : M} (hx : IsReflective B x) (hy : IsReflective B y) : IsReflective B (Module.reflection (coroot_apply_self B hx) y) := by constructor · rw [isOrthogonal_reflection B hx hSB] exact hy.1 · intro z have hz : Module.reflection (coroot_apply_self B hx) (Module.reflection (coroot_apply_self B hx) z) = z := by exact (LinearEquiv.eq_symm_apply (Module.reflection (coroot_apply_self B hx))).mp rfl rw [← hz, isOrthogonal_reflection B hx hSB, isOrthogonal_reflection B hx hSB] exact hy.2 _ end IsReflective end LinearMap namespace RootPairing open LinearMap IsReflective /-- The root pairing given by all reflective vectors for a bilinear form. -/ def ofBilinear [IsReflexive R M] (B : M →ₗ[R] M →ₗ[R] R) (hNB : LinearMap.Nondegenerate B) (hSB : LinearMap.IsSymm B) (h2 : IsRegular (2 : R)) : RootPairing {x : M | IsReflective B x} R M (Dual R M) where toLinearMap := Dual.eval R M root := Embedding.subtype fun x ↦ IsReflective B x coroot := { toFun := fun x => IsReflective.coroot B x.2 inj' := by intro x y hxy simp only [mem_setOf_eq] at hxy -- x* = y* have h1 : ∀ z, IsReflective.coroot B x.2 z = IsReflective.coroot B y.2 z := fun z => congrFun (congrArg DFunLike.coe hxy) z have h2x : ∀ z, B x x * IsReflective.coroot B x.2 z = B x x * IsReflective.coroot B y.2 z := fun z => congrArg (HMul.hMul ((B x) x)) (h1 z) have h2y : ∀ z, B y y * IsReflective.coroot B x.2 z = B y y * IsReflective.coroot B y.2 z := fun z => congrArg (HMul.hMul ((B y) y)) (h1 z) simp_rw [apply_self_mul_coroot_apply B x.2] at h2x -- 2(x,z) = (x,x)y*(z) simp_rw [apply_self_mul_coroot_apply B y.2] at h2y -- (y,y)x*(z) = 2(y,z) have h2xy : B x x = B y y := by refine h2.1 ?_ dsimp only specialize h2x y rw [coroot_apply_self] at h2x specialize h2y x rw [coroot_apply_self] at h2y rw [mul_comm, ← h2x, ← hSB.eq, RingHom.id_apply, ← h2y, mul_comm] rw [Subtype.ext_iff, ← sub_eq_zero] refine hNB.1 _ (fun z => ?_) rw [map_sub, LinearMap.sub_apply, sub_eq_zero] refine h2.1 ?_ dsimp only rw [h2x z, ← h2y z, hxy, h2xy] } root_coroot_two x := coroot_apply_self B x.2 reflectionPerm x := { toFun := fun y => ⟨(Module.reflection (coroot_apply_self B x.2) y), reflective_reflection B hSB x.2 y.2⟩ invFun := fun y => ⟨(Module.reflection (coroot_apply_self B x.2) y), reflective_reflection B hSB x.2 y.2⟩ left_inv := by intro y simp [involutive_reflection (coroot_apply_self B x.2) y] right_inv := by intro y simp [involutive_reflection (coroot_apply_self B x.2) y] } reflectionPerm_root x y := by simp [Module.reflection_apply] reflectionPerm_coroot x y := by simp only [coe_setOf, mem_setOf_eq, Embedding.coeFn_mk, Embedding.subtype_apply, Dual.eval_apply, Equiv.coe_fn_mk] ext z simp only [sub_apply, smul_apply, smul_eq_mul] refine y.2.1.1 ?_ simp only [mem_setOf_eq, mul_sub, apply_self_mul_coroot_apply B y.2, ← mul_assoc] rw [← isOrthogonal_reflection B x.2 hSB y y, apply_self_mul_coroot_apply, ← hSB.eq z, ← hSB.eq z, RingHom.id_apply, RingHom.id_apply, Module.reflection_apply, map_sub, mul_sub, sub_eq_sub_iff_comm, sub_left_inj] refine x.2.1.1 ?_ simp only [mem_setOf_eq, map_smul, smul_eq_mul] rw [← mul_assoc _ _ (B z x), ← mul_assoc _ _ (B z x), mul_left_comm, apply_self_mul_coroot_apply B x.2, mul_left_comm (B x x), apply_self_mul_coroot_apply B x.2, ← hSB.eq x y, RingHom.id_apply, ← hSB.eq x z, RingHom.id_apply] ring end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/CartanMatrix.lean
import Mathlib.Algebra.CharZero.Infinite import Mathlib.Algebra.Module.Submodule.Union import Mathlib.LinearAlgebra.Matrix.BilinearForm import Mathlib.LinearAlgebra.RootSystem.Base import Mathlib.LinearAlgebra.RootSystem.Finite.Lemmas import Mathlib.LinearAlgebra.RootSystem.Finite.Nondegenerate /-! # Cartan matrices for root systems This file contains definitions and basic results about Cartan matrices of root pairings / systems. ## Main definitions: * `RootPairing.Base.cartanMatrix`: the Cartan matrix of a crystallographic root pairing, with respect to a base `b`. * `RootPairing.Base.cartanMatrix_nondegenerate`: the Cartan matrix is non-degenerate. * `RootPairing.Base.induction_on_cartanMatrix`: an induction principle expressing the connectedness of the Dynkin diagram of an irreducible root pairing. * `RootPairing.Base.equivOfCartanMatrixEq`: a root system is determined by its Cartan matrix. -/ noncomputable section open FaithfulSMul (algebraMap_injective) open Function Set open Module.End (invtSubmodule mem_invtSubmodule) open Submodule (span subset_span) variable {ι R M N : Type*} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] namespace RootPairing.Base variable (S : Type*) [CommRing S] [Algebra S R] {P : RootPairing ι R M N} [P.IsValuedIn S] (b : P.Base) /-- The Cartan matrix of a root pairing, taking values in `S`, with respect to a base `b`. See also `RootPairing.Base.cartanMatrix`. -/ def cartanMatrixIn : Matrix b.support b.support S := .of fun i j ↦ P.pairingIn S i j lemma cartanMatrixIn_def (i j : b.support) : b.cartanMatrixIn S i j = P.pairingIn S i j := rfl @[simp] lemma algebraMap_cartanMatrixIn_apply (i j : b.support) : algebraMap S R (b.cartanMatrixIn S i j) = P.pairing i j := by simp [cartanMatrixIn_def] @[simp] lemma cartanMatrixIn_apply_same [FaithfulSMul S R] (i : b.support) : b.cartanMatrixIn S i i = 2 := FaithfulSMul.algebraMap_injective S R <| by simp [cartanMatrixIn_def, map_ofNat] /- If we generalised the notion of `RootPairing.Base` to work relative to an assumption `[P.IsValuedIn S]` then such a base would provide basis of `P.rootSpan S` and we could avoid using `Matrix.map` below. -/ lemma cartanMatrixIn_mul_diagonal_eq {P : RootSystem ι R M N} [P.IsValuedIn S] (B : P.InvariantForm) (b : P.Base) [DecidableEq ι] : (b.cartanMatrixIn S).map (algebraMap S R) * (Matrix.diagonal fun i : b.support ↦ B.form (P.root i) (P.root i)) = (2 : R) • BilinForm.toMatrix b.toWeightBasis B.form := by ext simp [B.two_mul_apply_root_root] lemma cartanMatrixIn_nondegenerate [IsDomain R] [NeZero (2 : R)] [FaithfulSMul S R] [IsDomain S] {P : RootSystem ι R M N} [P.IsValuedIn S] [Fintype ι] [P.IsAnisotropic] (b : P.Base) : (b.cartanMatrixIn S).Nondegenerate := by classical obtain ⟨B, hB⟩ : ∃ B : P.InvariantForm, B.form.Nondegenerate := ⟨P.toInvariantForm, P.rootForm_nondegenerate⟩ replace hB : ((2 : R) • BilinForm.toMatrix b.toWeightBasis B.form).Nondegenerate := by rwa [Matrix.Nondegenerate.smul_iff two_ne_zero, LinearMap.BilinForm.nondegenerate_toMatrix_iff] have aux : (Matrix.diagonal fun i : b.support ↦ B.form (P.root i) (P.root i)).Nondegenerate := by rw [Matrix.nondegenerate_iff_det_ne_zero, Matrix.det_diagonal, Finset.prod_ne_zero_iff] aesop rw [← cartanMatrixIn_mul_diagonal_eq (S := S), Matrix.Nondegenerate.mul_iff_right aux, Matrix.nondegenerate_iff_det_ne_zero, ← (algebraMap S R).mapMatrix_apply, ← RingHom.map_det, ne_eq, FaithfulSMul.algebraMap_eq_zero_iff] at hB rwa [Matrix.nondegenerate_iff_det_ne_zero] section IsCrystallographic variable [P.IsCrystallographic] /-- The Cartan matrix of a crystallographic root pairing, with respect to a base `b`. -/ abbrev cartanMatrix : Matrix b.support b.support ℤ := b.cartanMatrixIn ℤ variable [CharZero R] lemma cartanMatrix_apply_same (i : b.support) : b.cartanMatrix i i = 2 := b.cartanMatrixIn_apply_same ℤ i lemma cartanMatrix_apply_eq_zero_iff_pairing {i j : b.support} : b.cartanMatrix i j = 0 ↔ P.pairing i j = 0 := by rw [cartanMatrix, cartanMatrixIn_def, ← (algebraMap_injective ℤ R).eq_iff, algebraMap_pairingIn, map_zero] variable [IsDomain R] lemma cartanMatrix_apply_eq_zero_iff_symm {i j : b.support} : b.cartanMatrix i j = 0 ↔ b.cartanMatrix j i = 0 := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap simp only [cartanMatrix_apply_eq_zero_iff_pairing, P.pairing_eq_zero_iff] variable [Finite ι] lemma cartanMatrix_le_zero_of_ne (i j : b.support) (h : i ≠ j) : b.cartanMatrix i j ≤ 0 := b.pairingIn_le_zero_of_ne (by rwa [ne_eq, ← Subtype.ext_iff]) i.property j.property lemma cartanMatrix_mem_of_ne {i j : b.support} (hij : i ≠ j) : b.cartanMatrix i j ∈ ({-3, -2, -1, 0} : Set ℤ) := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap have : Module.IsReflexive R N := .of_isPerfPair P.flip.toLinearMap simp only [cartanMatrix, cartanMatrixIn_def] have h₁ := P.pairingIn_pairingIn_mem_set_of_isCrystallographic i j have h₂ : P.pairingIn ℤ i j ≤ 0 := b.cartanMatrix_le_zero_of_ne i j hij suffices P.pairingIn ℤ i j ≠ -4 by aesop by_contra contra replace contra : P.pairingIn ℤ j i = -1 ∧ P.pairingIn ℤ i j = -4 := ⟨by simp_all, contra⟩ rw [pairingIn_neg_one_neg_four_iff] at contra refine (not_linearIndependent_iff.mpr ?_) b.linearIndepOn_root refine ⟨⟨{i, j}, by simpa⟩, Finsupp.single i (1 : R) + Finsupp.single j (2 : R), ?_⟩ simp [contra, hij, hij.symm] lemma cartanMatrix_eq_neg_chainTopCoeff {i j : b.support} (hij : i ≠ j) : b.cartanMatrix i j = - P.chainTopCoeff j i := by rw [cartanMatrix, cartanMatrixIn_def, ← neg_eq_iff_eq_neg, ← b.chainTopCoeff_eq_of_ne hij.symm] lemma cartanMatrix_apply_eq_zero_iff {i j : b.support} (hij : i ≠ j) : b.cartanMatrix i j = 0 ↔ P.root i + P.root j ∉ range P.root := by rw [b.cartanMatrix_eq_neg_chainTopCoeff hij, neg_eq_zero, Int.natCast_eq_zero, P.chainTopCoeff_eq_zero_iff] replace hij := b.linearIndependent_pair_of_ne hij.symm tauto lemma abs_cartanMatrix_apply [DecidableEq ι] {i j : b.support} : |b.cartanMatrix i j| = (if i = j then 4 else 0) - b.cartanMatrix i j := by rcases eq_or_ne i j with rfl | h · simp · simpa [h] using b.cartanMatrix_le_zero_of_ne i j h @[simp] lemma cartanMatrix_map_abs [DecidableEq ι] : b.cartanMatrix.map abs = 4 - b.cartanMatrix := by ext; simp [abs_cartanMatrix_apply, Matrix.ofNat_apply] lemma cartanMatrix_nondegenerate {P : RootSystem ι R M N} [P.IsCrystallographic] (b : P.Base) : b.cartanMatrix.Nondegenerate := let _i : Fintype ι := Fintype.ofFinite ι cartanMatrixIn_nondegenerate ℤ b /-- A characterisation of the connectedness of the Dynkin diagram for irreducible root pairings. -/ lemma induction_on_cartanMatrix [P.IsReduced] [P.IsIrreducible] (p : b.support → Prop) {i j : b.support} (hi : p i) (hp : ∀ i j, p i → b.cartanMatrix j i ≠ 0 → p j) : p j := by let q : Submodule R M := span R (P.root ∘ (↑) '' {i | p i}) have hq₀ : q ≠ ⊥ := q.ne_bot_iff.mpr ⟨P.root i, subset_span <| by simpa, P.ne_zero i⟩ have hq_mem (k : b.support) : P.root k ∈ q ↔ p k := by refine ⟨fun hk ↦ ?_, fun hk ↦ subset_span <| by simpa⟩ contrapose! hk exact b.linearIndepOn_root.linearIndependent.notMem_span_image hk have hq_notMem (k : b.support) (hk : P.root k ∉ q) : q ≤ LinearMap.ker (P.coroot' k) := by refine fun x hx ↦ LinearMap.mem_ker.mpr ?_ contrapose! hk rw [hq_mem] induction hx using Submodule.span_induction with | mem x hx => obtain ⟨l, hl, rfl⟩ : ∃ l : b.support, p l ∧ P.root l = x := by simp_all replace hk : b.cartanMatrix k l ≠ 0 := by rwa [ne_eq, cartanMatrix_apply_eq_zero_iff_symm, cartanMatrix_apply_eq_zero_iff_pairing] tauto | zero => simp_all | add x y hx hy hx' hy' => replace hk : P.coroot' k x ≠ 0 ∨ P.coroot' k y ≠ 0 := by by_contra! contra; simp_all tauto | smul a x hx hx' => simp_all have hq : ∀ k, q ∈ invtSubmodule (P.reflection k) := by rw [← b.forall_mem_support_invtSubmodule_iff] refine fun k hkb ↦ (mem_invtSubmodule _).mpr fun x hx ↦ ?_ rw [Submodule.mem_comap, LinearEquiv.coe_coe, reflection_apply] apply q.sub_mem hx by_cases hk : P.root k ∈ q · exact q.smul_mem _ hk · replace hk : P.coroot' k x = 0 := hq_notMem ⟨k, hkb⟩ hk hx simp [hk] simp [← hq_mem, IsIrreducible.eq_top_of_invtSubmodule_reflection q hq hq₀] open scoped Matrix in lemma injective_pairingIn {P : RootSystem ι R M N} [P.IsCrystallographic] (b : P.Base) : Injective (fun i (k : b.support) ↦ P.pairingIn ℤ i k) := by classical intro i j hij obtain ⟨f, -, -, hf⟩ := b.exists_root_eq_sum_int i obtain ⟨g, -, -, hg⟩ := b.exists_root_eq_sum_int j let f' : b.support → ℤ := f ∘ (↑) let g' : b.support → ℤ := g ∘ (↑) suffices f' = g' by rw [← P.root.apply_eq_iff_eq, hf, hg] refine Finset.sum_congr rfl fun k hk ↦ ?_ replace this : f k = g k := congr_fun this ⟨k, hk⟩ rw [this] replace hf : (fun k : b.support ↦ P.pairingIn ℤ i k) = f' ᵥ* b.cartanMatrix := by suffices ∀ k, P.pairingIn ℤ i k = ∑ l ∈ b.support, f l * P.pairingIn ℤ l k by ext; simp [f', this, cartanMatrixIn, Matrix.vecMul_eq_sum, b.support.sum_subtype (by tauto)] refine fun k ↦ algebraMap_injective ℤ R ?_ simp_rw [algebraMap_pairingIn, map_sum, map_mul, algebraMap_pairingIn, ← P.root_coroot'_eq_pairing] simp [hf] replace hg : (fun k : b.support ↦ P.pairingIn ℤ j k) = g' ᵥ* b.cartanMatrix := by suffices ∀ k, P.pairingIn ℤ j k = ∑ l ∈ b.support, g l * P.pairingIn ℤ l k by ext; simp [g', this, cartanMatrixIn, Matrix.vecMul_eq_sum, b.support.sum_subtype (by tauto)] refine fun k ↦ algebraMap_injective ℤ R ?_ simp_rw [algebraMap_pairingIn, map_sum, map_mul, algebraMap_pairingIn, ← P.root_coroot'_eq_pairing] simp [hg] suffices Injective fun v ↦ v ᵥ* b.cartanMatrix from this <| by simpa [← hf, ← hg] rw [Matrix.vecMul_injective_iff] apply Matrix.linearIndependent_rows_of_det_ne_zero rw [← Matrix.nondegenerate_iff_det_ne_zero] exact b.cartanMatrix_nondegenerate lemma exists_mem_span_pairingIn_ne_zero_and_pairwise_ne {K : Type*} [Field K] [CharZero K] [Module K M] [Module K N] {P : RootSystem ι K M N} [P.IsCrystallographic] (b : P.Base) : ∃ d ∈ span K (range fun (i : b.support) j ↦ (P.pairingIn ℤ j i : K)), (∀ i, d i ≠ 0) ∧ Pairwise ((· ≠ ·) on d) := by set p := span K (range fun (i : b.support) j ↦ (P.pairingIn ℤ j i : K)) let f : ι ⊕ {(i, j) : ι × ι | i ≠ j} → Module.Dual K (ι → K) := Sum.elim LinearMap.proj (fun x ↦ LinearMap.proj (R := K) (φ := fun _ ↦ K) x.1.1 - LinearMap.proj x.1.2) suffices ∃ d ∈ p, ∀ i, f i d ≠ 0 by obtain ⟨d, hp, hf⟩ := this refine ⟨d, hp, fun i ↦ hf (Sum.inl i), fun i j h ↦ ?_⟩ simpa [f, sub_eq_zero] using hf (Sum.inr ⟨⟨i, j⟩, h⟩) apply Module.Dual.exists_forall_mem_ne_zero_of_forall_exists p f rintro (i | ⟨⟨i, j⟩, h : i ≠ j⟩) · obtain ⟨j, hj, hj₀⟩ := b.exists_mem_support_pos_pairingIn_ne_zero i refine ⟨fun i ↦ P.pairingIn ℤ i j, subset_span ⟨⟨j, hj⟩, rfl⟩, ?_⟩ rw [ne_eq, P.pairingIn_eq_zero_iff] at hj₀ simpa [f, ne_eq, Int.cast_eq_zero] · obtain ⟨k, hk, hk'⟩ : ∃ k ∈ b.support, P.pairingIn ℤ i k ≠ P.pairingIn ℤ j k := by contrapose! h apply b.injective_pairingIn aesop simpa [f, sub_eq_zero] using ⟨fun i ↦ P.pairingIn ℤ i k, subset_span ⟨⟨k, hk⟩, rfl⟩, by simpa⟩ section Uniqueness variable {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] {P : RootSystem ι R M N} [P.IsCrystallographic] [P.IsReduced] (b : P.Base) {P₂ : RootSystem ι₂ R M₂ N₂} [P₂.IsCrystallographic] (b₂ : P₂.Base) (e : b.support ≃ b₂.support) lemma apply_mem_range_root_of_cartanMatrixEq (f : M ≃ₗ[R] M₂) (hf : ∀ i : b.support, f (P.root i) = P₂.root (e i)) (m : M) (hm : m ∈ range P.root) (he : ∀ i j, b₂.cartanMatrix (e i) (e j) = b.cartanMatrix i j) : f m ∈ range P₂.root := by have (k : b.support) : (P.reflection k).trans f = f.trans (P₂.reflection (e k)) := by suffices ∀ j : b.support, (P.reflection k).trans f (P.root j) = f.trans (P₂.reflection (e k)) (P.root j) by rw [← LinearEquiv.toLinearMap_inj] exact b.toWeightBasis.ext fun j ↦ by simpa using this j intro j suffices P₂.pairing (e j) (e k) = P.pairing j k by simp [reflection_apply, hf, this] simpa only [cartanMatrixIn_def, algebraMap_pairingIn] using congr_arg (algebraMap ℤ R) (he j k) obtain ⟨i, rfl⟩ := hm apply b.induction_reflect i · exact fun j ⟨k, hk⟩ ↦ ⟨P₂.reflectionPerm k k, by simpa⟩ · exact fun j hj ↦ ⟨e ⟨j, hj⟩, (hf _).symm⟩ · intro j k ⟨l, hl⟩ hk replace this : f (P.reflection k (P.root j)) = (P₂.reflection (e ⟨k, hk⟩)) (f (P.root j)) := by simpa using LinearEquiv.congr_fun (this ⟨k, hk⟩) (P.root j) rw [root_reflectionPerm, this, ← hl, ← root_reflectionPerm] exact mem_range_self _ /-- A root system is determined by its Cartan matrix. -/ def equivOfCartanMatrixEq [Finite ι₂] [P₂.IsReduced] (he : ∀ i j, b₂.cartanMatrix (e i) (e j) = b.cartanMatrix i j) : P.Equiv P₂.toRootPairing := let f : M ≃ₗ[R] M₂ := b.toWeightBasis.equiv b₂.toWeightBasis e have hf : ∀ m, f m ∈ range P₂.root ↔ m ∈ range P.root := by refine fun m ↦ ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · simpa using apply_mem_range_root_of_cartanMatrixEq _ b e.symm f.symm (by simp [f, Module.Basis.equiv]) (f m) h (by simp [(he _ _).symm]) · exact apply_mem_range_root_of_cartanMatrixEq b b₂ e f (by simp [f, Module.Basis.equiv]) m h he let : Fintype ι := Fintype.ofFinite _ let : Fintype ι₂ := Fintype.ofFinite _ have : DecidableEq M := Classical.typeDecidableEq M have : DecidableEq M₂ := Classical.typeDecidableEq M₂ let e' : ι ≃ ι₂ := P.root.toEquivRange.trans <| (f.bijOn hf).equiv.trans P₂.root.toEquivRange.symm have he' (i : ι) : f (P.root i) = P₂.root (e' i) := by simp [f, e', BijOn.equiv, Embedding.toEquivRange] have : Module.IsReflexive R M₂ := .of_isPerfPair P₂.toLinearMap Equiv.mk' P P₂ (b.toWeightBasis.equiv b₂.toWeightBasis e) e' he' end Uniqueness end IsCrystallographic end RootPairing.Base
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/Irreducible.lean
import Mathlib.LinearAlgebra.RootSystem.RootPositive import Mathlib.LinearAlgebra.RootSystem.WeylGroup import Mathlib.RepresentationTheory.Submodule /-! # Irreducible root pairings This file contains basic definitions and results about irreducible root systems. ## Main definitions / results: * `RootPairing.isSimpleModule_weylGroupRootRep_iff`: a criterion for the representation of the Weyl group on root space to be irreducible. * `RootPairing.IsIrreducible`: a typeclass encoding the fact that a root pairing is irreducible. * `RootPairing.IsIrreducible.mk'`: an alternative constructor for irreducibility when the coefficients are a field. -/ open Function Set open Submodule (span span_le) open LinearMap (ker) open MulAction (orbit mem_orbit_self mem_orbit_iff) open Module.End (invtSubmodule) variable {ι R M N : Type*} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] (P : RootPairing ι R M N) namespace RootPairing /-- The sublattice of invariant submodules of the root space. -/ def invtRootSubmodule : Sublattice (Submodule R M) := ⨅ i, invtSubmodule (P.reflection i) lemma mem_invtRootSubmodule_iff {q : Submodule R M} : q ∈ P.invtRootSubmodule ↔ ∀ i, q ∈ Module.End.invtSubmodule (P.reflection i) := by simp [invtRootSubmodule] @[simp] protected lemma invtRootSubmodule.top_mem : ⊤ ∈ P.invtRootSubmodule := by simp [invtRootSubmodule] @[simp] protected lemma invtRootSubmodule.bot_mem : ⊥ ∈ P.invtRootSubmodule := by simp [invtRootSubmodule] instance : BoundedOrder P.invtRootSubmodule where top := ⟨⊤, invtRootSubmodule.top_mem P⟩ bot := ⟨⊥, invtRootSubmodule.bot_mem P⟩ le_top := fun ⟨p, hp⟩ ↦ by simp bot_le := fun ⟨p, hp⟩ ↦ by simp instance [Nontrivial M] : Nontrivial P.invtRootSubmodule where exists_pair_ne := ⟨⊥, ⊤, by rw [ne_eq, Subtype.ext_iff]; exact bot_ne_top⟩ lemma isSimpleModule_weylGroupRootRep_iff [Nontrivial M] : IsSimpleModule (MonoidAlgebra R P.weylGroup) P.weylGroupRootRep.asModule ↔ ∀ (q : Submodule R M), (∀ i, q ∈ invtSubmodule (P.reflection i)) → q ≠ ⊥ → q = ⊤ := by rw [isSimpleModule_iff, ← P.weylGroupRootRep.mapSubmodule.isSimpleOrder_iff] refine ⟨fun h q hq₁ hq₂ ↦ ?_, fun h ↦ ⟨fun q ↦ ?_⟩⟩ · suffices ∀ g : P.weylGroup, q ∈ invtSubmodule (P.weylGroupRootRep g) by let q' : P.weylGroupRootRep.invtSubmodule := ⟨q, (Representation.mem_invtSubmodule P.weylGroupRootRep).mpr this⟩ suffices q' = ⊤ by simpa [q'] apply (IsSimpleOrder.eq_bot_or_eq_top _).resolve_left simpa [q'] rintro ⟨g, hg⟩ induction hg using weylGroup.induction with | mem i => exact hq₁ i | one => simp [← Submonoid.one_def] | mul x y hx hy hx' hy' => apply invtSubmodule.comp <;> assumption · rcases eq_or_ne q ⊥ with rfl | hq; · tauto suffices (q : Submodule R M) = ⊤ by right; simpa using this refine h q (fun i ↦ ?_) (by simpa using hq) exact P.weylGroupRootRep.mem_invtSubmodule.mp q.property ⟨_, P.reflection_mem_weylGroup i⟩ /-- A root pairing is irreducible if it is non-trivial and contains no proper invariant submodules. -/ @[mk_iff] class IsIrreducible : Prop where nontrivial : Nontrivial M nontrivial' : Nontrivial N eq_top_of_invtSubmodule_reflection (q : Submodule R M) : (∀ i, q ∈ invtSubmodule (P.reflection i)) → q ≠ ⊥ → q = ⊤ eq_top_of_invtSubmodule_coreflection (q : Submodule R N) : (∀ i, q ∈ invtSubmodule (P.coreflection i)) → q ≠ ⊥ → q = ⊤ instance [P.IsIrreducible] : P.flip.IsIrreducible where nontrivial := IsIrreducible.nontrivial' P nontrivial' := IsIrreducible.nontrivial P eq_top_of_invtSubmodule_reflection := IsIrreducible.eq_top_of_invtSubmodule_coreflection (P := P) eq_top_of_invtSubmodule_coreflection := IsIrreducible.eq_top_of_invtSubmodule_reflection (P := P) lemma isSimpleModule_weylGroupRootRep [P.IsIrreducible] : IsSimpleModule (MonoidAlgebra R P.weylGroup) P.weylGroupRootRep.asModule := have := IsIrreducible.nontrivial P P.isSimpleModule_weylGroupRootRep_iff.mpr IsIrreducible.eq_top_of_invtSubmodule_reflection /-- A nonempty irreducible root pairing is a root system. -/ def toRootSystem [Nonempty ι] [NeZero (2 : R)] [P.IsIrreducible] : RootSystem ι R M N := { toRootPairing := P span_root_eq_top := IsIrreducible.eq_top_of_invtSubmodule_reflection (P.rootSpan R) P.rootSpan_mem_invtSubmodule_reflection (P.rootSpan_ne_bot R) span_coroot_eq_top := IsIrreducible.eq_top_of_invtSubmodule_coreflection (P.corootSpan R) P.corootSpan_mem_invtSubmodule_coreflection (P.corootSpan_ne_bot R) } lemma invtSubmodule_reflection_of_invtSubmodule_coreflection (i : ι) (q : Submodule R N) (hq : q ∈ invtSubmodule (P.coreflection i)) : q.dualAnnihilator.map P.toPerfPair.symm ∈ invtSubmodule (P.reflection i) := by rw [LinearEquiv.map_mem_invtSubmodule_iff, LinearEquiv.symm_symm, toPerfPair_conj_reflection, Module.End.mem_invtSubmodule, ← Submodule.map_le_iff_le_comap] exact (Submodule.dualAnnihilator_map_dualMap_le _ _).trans <| Submodule.dualAnnihilator_anti hq /-- When the coefficients are a field, the coroot conditions for irreducibility follow from those for the roots. -/ lemma IsIrreducible.mk' {K : Type*} [Field K] [Module K M] [Module K N] [Nontrivial M] (P : RootPairing ι K M N) (h : ∀ (q : Submodule K M), (∀ i, q ∈ invtSubmodule (P.reflection i)) → q ≠ ⊥ → q = ⊤) : P.IsIrreducible where nontrivial := inferInstance nontrivial' := (Module.nontrivial_dual_iff K).mp P.toPerfPair.symm.nontrivial eq_top_of_invtSubmodule_reflection := h eq_top_of_invtSubmodule_coreflection q stab ne_bot := by specialize h (q.dualAnnihilator.map P.toPerfPair.symm) fun i ↦ invtSubmodule_reflection_of_invtSubmodule_coreflection P i q (stab i) rw [Submodule.map_eq_top_iff, not_imp_comm] at h replace ne_bot : q.dualAnnihilator ≠ ⊤ := by simpa simpa using h ne_bot lemma isIrreducible_iff_invtRootSubmodule {K : Type*} [Field K] [Module K M] [Module K N] [Nontrivial M] (P : RootPairing ι K M N) : P.IsIrreducible ↔ IsSimpleOrder P.invtRootSubmodule := by refine ⟨fun h ↦ ⟨fun ⟨q, hq⟩ ↦ ?_⟩, fun h ↦ IsIrreducible.mk' P fun q hq hq' ↦ ?_⟩ · simp only [invtRootSubmodule.bot_mem, invtRootSubmodule.top_mem, Subtype.mk_eq_bot_iff, Subtype.mk_eq_top_iff] rw [mem_invtRootSubmodule_iff] at hq have := IsIrreducible.eq_top_of_invtSubmodule_reflection q hq tauto · let q' : P.invtRootSubmodule := ⟨q, P.mem_invtRootSubmodule_iff.mpr hq⟩ replace hq' : ⊥ < q' := by simpa [q', bot_lt_iff_ne_bot, -IsSimpleOrder.bot_lt_iff_eq_top] suffices q' = ⊤ by simpa [q'] using this exact IsSimpleOrder.eq_top_of_lt hq' lemma exist_set_root_not_disjoint_and_le_ker_coroot'_of_invtSubmodule [NeZero (2 : R)] [NoZeroSMulDivisors R M] (q : Submodule R M) (hq : ∀ i, q ∈ invtSubmodule (P.reflection i)) : ∃ Φ : Set ι, (∀ i ∈ Φ, ¬ Disjoint q (R ∙ P.root i)) ∧ (∀ i ∉ Φ, q ≤ ker (P.coroot' i)) := by refine ⟨{i | ¬ Disjoint q (R ∙ P.root i)}, by simp, fun i hi ↦ ?_⟩ simp only [mem_setOf_eq, not_not] at hi rw [← Submodule.mem_invtSubmodule_reflection_iff (by simp) hi] exact hq i variable [NeZero (2 : R)] [P.IsIrreducible] lemma span_orbit_eq_top (i : ι) : span R (orbit P.weylGroup (P.root i)) = ⊤ := by refine IsIrreducible.eq_top_of_invtSubmodule_reflection (P := P) _ (fun j ↦ ?_) ?_ · let g : P.weylGroup := ⟨Equiv.reflection P j, P.reflection_mem_weylGroup j⟩ exact Module.End.span_orbit_mem_invtSubmodule R (P.root i) g · simpa using ⟨P.root i, mem_orbit_self _, P.ne_zero i⟩ lemma exists_form_eq_form_and_form_ne_zero (B : P.InvariantForm) (i j : ι) : ∃ k, B.form (P.root k) (P.root k) = B.form (P.root j) (P.root j) ∧ B.form (P.root i) (P.root k) ≠ 0 := by by_contra! contra suffices span R (orbit P.weylGroup (P.root j)) ≤ ker (B.form (P.root i)) from B.apply_root_ne_zero i <| by simpa [span_orbit_eq_top] using this refine span_le.mpr fun v hv ↦ ?_ obtain ⟨g, rfl⟩ := mem_orbit_iff.mp hv simp only [P.weylGroup_apply_root, SetLike.mem_coe, LinearMap.mem_ker] apply contra simp [← Subgroup.smul_def g] lemma span_root_image_eq_top_of_forall_orthogonal (s : Set ι) (hne : s.Nonempty) (h : ∀ j, P.root j ∉ span R (P.root '' s) → ∀ i ∈ s, P.IsOrthogonal j i) : span R (P.root '' s) = ⊤ := by have hq (j : ι) : span R (P.root '' s) ∈ Module.End.invtSubmodule (P.reflection j) := by by_cases hj : P.root j ∈ span R (P.root '' s) · exact Submodule.mem_invtSubmodule_reflection_of_mem _ _ hj · refine (Module.End.mem_invtSubmodule _).mpr fun x hx ↦ ?_ rwa [Submodule.mem_comap, LinearEquiv.coe_coe, (isFixedPt_reflection_of_isOrthogonal (h _ hj) hx).eq] apply IsIrreducible.eq_top_of_invtSubmodule_reflection _ hq simpa using ⟨hne.choose, hne.choose_spec, P.ne_zero _⟩ end RootPairing namespace RootSystem /- Note that this actually holds for `RootPairing` provided we: * assume `RootPairing.IsBalanced`, * replace the assumption `q ≠ ⊥` with `¬ Disjoint P.rootSpan q`, * replace the conclusion `q = ⊤` with `P.rootSpan ≤ q`. -/ lemma eq_top_of_mem_invtSubmodule_of_forall_eq_univ {K : Type*} [Field K] [NeZero (2 : K)] [Module K M] [Module K N] (P : RootSystem ι K M N) (q : Submodule K M) (h₀ : q ≠ ⊥) (h₁ : ∀ i, q ∈ invtSubmodule (P.reflection i)) (h₂ : ∀ Φ, Φ.Nonempty → P.root '' Φ ⊆ q → (∀ i ∉ Φ, q ≤ ker (P.coroot' i)) → Φ = univ) : q = ⊤ := by obtain ⟨Φ, b, c⟩ := P.exist_set_root_not_disjoint_and_le_ker_coroot'_of_invtSubmodule q h₁ rcases Φ.eq_empty_or_nonempty with rfl | hΦ · replace c : q ≤ ⨅ i, LinearMap.ker (P.coroot' i) := by simpa using c simp [h₀, ← P.corootSpan_dualAnnihilator_map_eq_iInf_ker_coroot'] at c · replace b : P.root '' Φ ⊆ q := by simpa [Submodule.disjoint_span_singleton' (P.ne_zero _)] using b simpa [h₂ Φ hΦ b c, ← span_le] using b end RootSystem
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/BaseChange.lean
import Mathlib.Algebra.Algebra.Rat import Mathlib.LinearAlgebra.PerfectPairing.Restrict import Mathlib.LinearAlgebra.RootSystem.IsValuedIn /-! # Base change for root pairings When the coefficients are a field, root pairings behave well with respect to restriction and extension of scalars. ## Main results: * `RootPairing.restrict`: if `RootPairing.pairing` takes values in a subfield, we may restrict to get a root _system_ with coefficients in the subfield. Of particular interest is the case when the pairing takes values in its prime subfield (which happens for crystallographic pairings). ## TODO * Extension of scalars * Crystallographic root systems are isomorphic to base changes of root systems over `ℤ`: Take `M₀` and `N₀` to be the `ℤ`-span of roots and coroots. -/ noncomputable section open Set Function open Submodule (span injective_subtype span subset_span span_setOf_mem_eq_top) namespace RootPairing /-- We say a root pairing is balanced if the root span and coroot span are perfectly complementary. All root systems are balanced and all finite root pairings over a field are balanced. -/ class IsBalanced {ι R M N : Type*} [AddCommGroup M] [AddCommGroup N] [CommRing R] [Module R M] [Module R N] (P : RootPairing ι R M N) : Prop where isPerfectCompl : P.toLinearMap.IsPerfectCompl (P.rootSpan R) (P.corootSpan R) instance {ι R M N : Type*} [AddCommGroup M] [AddCommGroup N] [CommRing R] [Module R M] [Module R N] (P : RootSystem ι R M N) : P.IsBalanced where isPerfectCompl := by simp variable {ι L M N : Type*} [Field L] [AddCommGroup M] [AddCommGroup N] [Module L M] [Module L N] (P : RootPairing ι L M N) section restrictScalars variable (K : Type*) [Field K] [Algebra K L] [Module K M] [Module K N] [IsScalarTower K L M] [IsScalarTower K L N] [P.IsBalanced] section SubfieldValued variable (hP : ∀ i j, P.pairing i j ∈ (algebraMap K L).range) /-- Restriction of scalars for a root pairing taking values in a subfield. Note that we obtain a root system (not just a root pairing). See also `RootPairing.restrictScalars`. -/ def restrictScalars' : RootSystem ι K (span K (range P.root)) (span K (range P.coroot)) where toLinearMap := .restrictScalarsRange₂ (R := L) (span K (range P.root)).subtype (span K (range P.coroot)).subtype (Algebra.linearMap K L) (FaithfulSMul.algebraMap_injective K L) P.toLinearMap fun x y ↦ LinearMap.BilinMap.apply_apply_mem_of_mem_span (LinearMap.range (Algebra.linearMap K L)) (range P.root) (range P.coroot) (LinearMap.restrictScalarsₗ K L _ _ _ ∘ₗ P.toLinearMap.restrictScalars K) (by rintro - ⟨i, rfl⟩ - ⟨j, rfl⟩; exact hP i j) _ _ x.property y.property isPerfPair_toLinearMap := .restrictScalars_of_field P.toLinearMap _ _ (injective_subtype _) (injective_subtype _) (by simpa using IsBalanced.isPerfectCompl) _ root := ⟨fun i ↦ ⟨_, subset_span (mem_range_self i)⟩, fun i j h ↦ by simpa using h⟩ coroot := ⟨fun i ↦ ⟨_, subset_span (mem_range_self i)⟩, fun i j h ↦ by simpa using h⟩ root_coroot_two i := by have : algebraMap K L 2 = 2 := by rw [← Int.cast_two (R := K), ← Int.cast_two (R := L), map_intCast] exact FaithfulSMul.algebraMap_injective K L <| by simp [this] reflectionPerm := P.reflectionPerm reflectionPerm_root i j := by ext; simpa [algebra_compatible_smul L] using P.reflectionPerm_root i j reflectionPerm_coroot i j := by ext; simpa [algebra_compatible_smul L] using P.reflectionPerm_coroot i j span_root_eq_top := by rw [← span_setOf_mem_eq_top] congr ext ⟨x, hx⟩ simp span_coroot_eq_top := by rw [← span_setOf_mem_eq_top] congr ext ⟨x, hx⟩ simp @[simp] lemma restrictScalars_toLinearMap_apply_apply (x : span K (range P.root)) (y : span K (range P.coroot)) : algebraMap K L ((P.restrictScalars' K hP).toLinearMap x y) = P.toLinearMap x y := by simp [restrictScalars'] @[simp] lemma restrictScalars_coe_root (i : ι) : (P.restrictScalars' K hP).root i = P.root i := rfl @[simp] lemma restrictScalars_coe_coroot (i : ι) : (P.restrictScalars' K hP).coroot i = P.coroot i := rfl @[simp] lemma restrictScalars_pairing (i j : ι) : algebraMap K L ((P.restrictScalars' K hP).pairing i j) = P.pairing i j := by simp only [pairing, restrictScalars_toLinearMap_apply_apply, restrictScalars_coe_root, restrictScalars_coe_coroot] end SubfieldValued /-- Restriction of scalars for a crystallographic root pairing. -/ abbrev restrictScalars [P.IsCrystallographic] : RootSystem ι K (span K (range P.root)) (span K (range P.coroot)) := P.restrictScalars' K (IsValuedIn.trans P K ℤ).exists_value /-- Restriction of scalars to `ℚ` for a crystallographic root pairing in characteristic zero. -/ abbrev restrictScalarsRat [CharZero L] [P.IsCrystallographic] := let _i : Module ℚ M := Module.compHom M (algebraMap ℚ L) let _i : Module ℚ N := Module.compHom N (algebraMap ℚ L) P.restrictScalars ℚ end restrictScalars end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/RootPairingCat.lean
import Mathlib.LinearAlgebra.RootSystem.Hom import Mathlib.CategoryTheory.Category.Basic /-! # The category of root pairings This file defines the category of root pairings, following the definition of category of root data given in SGA III Exp. 21 Section 6. ## Main definitions: * `RootPairingCat`: Objects are root pairings. ## TODO * Forgetful functors * Functions passing between module maps and root pairing homs ## Implementation details This is mostly copied from `ModuleCat`. -/ open Set Function CategoryTheory noncomputable section universe v u variable {R : Type u} [CommRing R] /-- Objects in the category of root pairings. -/ structure RootPairingCat (R : Type u) [CommRing R] where /-- The weight space of a root pairing. -/ weight : Type v [weightIsAddCommGroup : AddCommGroup weight] [weightIsModule : Module R weight] /-- The coweight space of a root pairing. -/ coweight : Type v [coweightIsAddCommGroup : AddCommGroup coweight] [coweightIsModule : Module R coweight] /-- The set that indexes roots and coroots. -/ index : Type v /-- The root pairing structure. -/ pairing : RootPairing index R weight coweight attribute [instance] RootPairingCat.weightIsAddCommGroup RootPairingCat.weightIsModule attribute [instance] RootPairingCat.coweightIsAddCommGroup RootPairingCat.coweightIsModule namespace RootPairingCat instance category : Category.{v, max (v + 1) u} (RootPairingCat.{v} R) where Hom P Q := RootPairing.Hom P.pairing Q.pairing id P := RootPairing.Hom.id P.pairing comp f g := RootPairing.Hom.comp g f end RootPairingCat
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/Hom.lean
import Mathlib.LinearAlgebra.RootSystem.Basic import Mathlib.LinearAlgebra.RootSystem.Defs /-! # Morphisms of root pairings This file defines morphisms of root pairings, following the definition of morphisms of root data given in SGA III Exp. 21 Section 6. ## Main definitions: * `Hom`: A morphism of root pairings is a linear map of weight spaces, its transverse on coweight spaces, and a bijection on the set that indexes roots and coroots. * `Hom.id`: The identity morphism. * `Hom.comp`: The composite of two morphisms. * `End`: The endomorphism monoid of a root pairing. * `Hom.weightHom`: The homomorphism from the endomorphism monoid to linear endomorphisms on the weight space. * `Hom.coweightHom`: The homomorphism from the endomorphism monoid to the opposite monoid of linear endomorphisms on the coweight space. * `Equiv`: An equivalence of root pairings is a morphism for which the maps on weight spaces and coweight spaces are bijective. * `Equiv.toHom`: The morphism underlying an equivalence. * `Equiv.weightEquiv`: The linear isomorphism on weight spaces given by an equivalence. * `Equiv.coweightEquiv`: The linear isomorphism on coweight spaces given by an equivalence. * `Equiv.id`: The identity equivalence. * `Equiv.comp`: The composite of two equivalences. * `Equiv.symm`: The inverse of an equivalence. * `Aut`: The automorphism group of a root pairing. * `Equiv.toEndUnit`: The group isomorphism between the automorphism group of a root pairing and the group of invertible endomorphisms. * `Equiv.weightHom`: The homomorphism from the automorphism group to linear automorphisms on the weight space. * `Equiv.coweightHom`: The homomorphism from the automorphism group to the opposite group of linear automorphisms on the coweight space. * `Equiv.reflection`: The automorphism of a root pairing given by reflection in a root and coreflection in the corresponding coroot. ## TODO * Special types of morphisms: Isogenies, weight/coweight space embeddings * Weyl group reimplementation? -/ open Set Function noncomputable section variable {ι R M N : Type*} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] namespace RootPairing /-- A morphism of root pairings is a pair of mutually transposed maps of weight and coweight spaces that preserves roots and coroots. We make the map of indexing sets explicit. -/ @[ext] structure Hom {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) where /-- A linear map on weight space. -/ weightMap : M →ₗ[R] M₂ /-- A contravariant linear map on coweight space. -/ coweightMap : N₂ →ₗ[R] N /-- A bijection on index sets. -/ indexEquiv : ι ≃ ι₂ weight_coweight_transpose : weightMap.dualMap ∘ₗ Q.flip.toPerfPair = P.flip.toPerfPair ∘ₗ coweightMap root_weightMap : weightMap ∘ P.root = Q.root ∘ indexEquiv coroot_coweightMap : coweightMap ∘ Q.coroot = P.coroot ∘ indexEquiv.symm namespace Hom lemma weight_coweight_transpose_apply {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) (x : N₂) (f : Hom P Q) : f.weightMap.dualMap (Q.flip.toPerfPair x) = P.flip.toPerfPair (f.coweightMap x) := Eq.mp (propext LinearMap.ext_iff) f.weight_coweight_transpose x lemma root_weightMap_apply {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) (i : ι) (f : Hom P Q) : f.weightMap (P.root i) = Q.root (f.indexEquiv i) := Eq.mp (propext funext_iff) f.root_weightMap i lemma coroot_coweightMap_apply {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) (i : ι₂) (f : Hom P Q) : f.coweightMap (Q.coroot i) = P.coroot (f.indexEquiv.symm i) := Eq.mp (propext funext_iff) f.coroot_coweightMap i /-- The identity morphism of a root pairing. -/ @[simps!] def id (P : RootPairing ι R M N) : Hom P P where weightMap := LinearMap.id coweightMap := LinearMap.id indexEquiv := Equiv.refl ι weight_coweight_transpose := by simp root_weightMap := by simp coroot_coweightMap := by simp /-- Composition of morphisms -/ @[simps!] def comp {ι₁ M₁ N₁ ι₂ M₂ N₂ : Type*} [AddCommGroup M₁] [Module R M₁] [AddCommGroup N₁] [Module R N₁] [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] {P : RootPairing ι R M N} {P₁ : RootPairing ι₁ R M₁ N₁} {P₂ : RootPairing ι₂ R M₂ N₂} (g : Hom P₁ P₂) (f : Hom P P₁) : Hom P P₂ where weightMap := g.weightMap ∘ₗ f.weightMap coweightMap := f.coweightMap ∘ₗ g.coweightMap indexEquiv := f.indexEquiv.trans g.indexEquiv weight_coweight_transpose := by ext φ x rw [← LinearMap.dualMap_comp_dualMap, ← LinearMap.comp_assoc _ f.coweightMap, ← f.weight_coweight_transpose, LinearMap.comp_assoc g.coweightMap, ← g.weight_coweight_transpose, ← LinearMap.comp_assoc] root_weightMap := by ext i simp only [LinearMap.coe_comp, Equiv.coe_trans] rw [comp_assoc, f.root_weightMap, ← comp_assoc, g.root_weightMap, comp_assoc] coroot_coweightMap := by ext i simp only [LinearMap.coe_comp] rw [comp_assoc, g.coroot_coweightMap, ← comp_assoc, f.coroot_coweightMap, comp_assoc] simp @[simp] lemma id_comp {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) (f : Hom P Q) : comp f (id P) = f := by ext x <;> simp @[simp] lemma comp_id {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) (f : Hom P Q) : comp (id Q) f = f := by ext x <;> simp @[simp] lemma comp_assoc {ι₁ M₁ N₁ ι₂ M₂ N₂ ι₃ M₃ N₃ : Type*} [AddCommGroup M₁] [Module R M₁] [AddCommGroup N₁] [Module R N₁] [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] [AddCommGroup M₃] [Module R M₃] [AddCommGroup N₃] [Module R N₃] {P : RootPairing ι R M N} {P₁ : RootPairing ι₁ R M₁ N₁} {P₂ : RootPairing ι₂ R M₂ N₂} {P₃ : RootPairing ι₃ R M₃ N₃} (h : Hom P₂ P₃) (g : Hom P₁ P₂) (f : Hom P P₁) : comp (comp h g) f = comp h (comp g f) := by ext <;> simp /-- The endomorphism monoid of a root pairing. -/ instance (P : RootPairing ι R M N) : Monoid (Hom P P) where mul := comp mul_assoc := comp_assoc one := id P one_mul := id_comp P P mul_one := comp_id P P @[simp] lemma weightMap_one (P : RootPairing ι R M N) : weightMap (P := P) (Q := P) 1 = LinearMap.id (R := R) (M := M) := rfl @[simp] lemma coweightMap_one (P : RootPairing ι R M N) : coweightMap (P := P) (Q := P) 1 = LinearMap.id (R := R) (M := N) := rfl @[simp] lemma indexEquiv_one (P : RootPairing ι R M N) : indexEquiv (P := P) (Q := P) 1 = Equiv.refl ι := rfl @[simp] lemma weightMap_mul (P : RootPairing ι R M N) (x y : Hom P P) : weightMap (x * y) = weightMap x ∘ₗ weightMap y := rfl @[simp] lemma coweightMap_mul (P : RootPairing ι R M N) (x y : Hom P P) : coweightMap (x * y) = coweightMap y ∘ₗ coweightMap x := rfl @[simp] lemma indexEquiv_mul (P : RootPairing ι R M N) (x y : Hom P P) : indexEquiv (x * y) = indexEquiv x ∘ indexEquiv y := rfl /-- The endomorphism monoid of a root pairing. -/ abbrev _root_.RootPairing.End (P : RootPairing ι R M N) := Hom P P /-- The weight space representation of endomorphisms -/ def weightHom (P : RootPairing ι R M N) : End P →* (Module.End R M) where toFun g := Hom.weightMap (P := P) (Q := P) g map_mul' g h := by ext; simp map_one' := by ext; simp lemma weightHom_injective (P : RootPairing ι R M N) : Injective (weightHom P) := by intro f g hfg ext x · exact LinearMap.congr_fun hfg x · refine LinearEquiv.injective P.flip.toPerfPair ?_ simp_rw [← weight_coweight_transpose_apply] exact congrFun (congrArg DFunLike.coe (congrArg LinearMap.dualMap hfg)) (P.flip.toPerfPair x) · refine Embedding.injective P.root ?_ simp_rw [← root_weightMap_apply] exact congrFun (congrArg DFunLike.coe hfg) (P.root x) /-- The coweight space representation of endomorphisms -/ def coweightHom (P : RootPairing ι R M N) : End P →* (N →ₗ[R] N)ᵐᵒᵖ where toFun g := MulOpposite.op (Hom.coweightMap (P := P) (Q := P) g) map_mul' g h := by simp only [← MulOpposite.op_mul, coweightMap_mul, Module.End.mul_eq_comp] map_one' := by simp only [MulOpposite.op_eq_one_iff, coweightMap_one, Module.End.one_eq_id] lemma coweightHom_injective (P : RootPairing ι R M N) : Injective (coweightHom P) := by intro f g hfg ext x · dsimp [coweightHom] at hfg rw [MulOpposite.op_inj] at hfg have h := congrArg (LinearMap.comp (M₃ := Module.Dual R M) (σ₂₃ := .id R) P.flip.toPerfPair) hfg rw [← f.weight_coweight_transpose, ← g.weight_coweight_transpose] at h have : f.weightMap = g.weightMap := by haveI : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap refine (Module.dualMap_dualMap_eq_iff R M).mp (congrArg LinearMap.dualMap ((LinearEquiv.eq_comp_toLinearMap_iff f.weightMap.dualMap g.weightMap.dualMap).mp h)) exact congrFun (congrArg DFunLike.coe this) x · dsimp [coweightHom] at hfg simp_all only [MulOpposite.op_inj] · dsimp [coweightHom] at hfg rw [MulOpposite.op_inj] at hfg set y := f.indexEquiv x with hy have : f.coweightMap (P.coroot y) = g.coweightMap (P.coroot y) := by exact congrFun (congrArg DFunLike.coe hfg) (P.coroot y) rw [coroot_coweightMap_apply, coroot_coweightMap_apply, Embedding.apply_eq_iff_eq, hy] at this rw [Equiv.symm_apply_apply] at this rw [this, Equiv.apply_symm_apply] /-- The permutation representation of the endomorphism monoid on the root index set -/ def indexHom (P : RootPairing ι R M N) : End P →* (ι ≃ ι) where toFun f := Hom.indexEquiv f map_one' := by ext; simp map_mul' x y := by ext; simp end Hom variable {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) /-- An equivalence of root pairings is a morphism where the maps of weight and coweight spaces are bijective. See also `RootPairing.Equiv.toEndUnit`. -/ @[ext] protected structure Equiv extends Hom P Q where bijective_weightMap : Bijective weightMap bijective_coweightMap : Bijective coweightMap attribute [coe] Equiv.toHom /-- The root pairing homomorphism underlying an equivalence. -/ add_decl_doc Equiv.toHom namespace Equiv /-- The linear equivalence of weight spaces given by an equivalence of root pairings. -/ def weightEquiv (e : RootPairing.Equiv P Q) : M ≃ₗ[R] M₂ := LinearEquiv.ofBijective _ e.bijective_weightMap @[simp] lemma weightEquiv_apply (e : RootPairing.Equiv P Q) (m : M) : weightEquiv P Q e m = e.toHom.weightMap m := rfl @[simp] lemma weightEquiv_symm_weightMap (e : RootPairing.Equiv P Q) (m : M) : (weightEquiv P Q e).symm (e.toHom.weightMap m) = m := (LinearEquiv.symm_apply_eq (weightEquiv P Q e)).mpr rfl @[simp] lemma weightMap_weightEquiv_symm (e : RootPairing.Equiv P Q) (m : M₂) : e.toHom.weightMap ((weightEquiv P Q e).symm m) = m := by rw [← weightEquiv_apply] exact LinearEquiv.apply_symm_apply (weightEquiv P Q e) m /-- The contravariant equivalence of coweight spaces given by an equivalence of root pairings. -/ def coweightEquiv (e : RootPairing.Equiv P Q) : N₂ ≃ₗ[R] N := LinearEquiv.ofBijective _ e.bijective_coweightMap @[simp] lemma coweightEquiv_apply (e : RootPairing.Equiv P Q) (n : N₂) : coweightEquiv P Q e n = e.toHom.coweightMap n := rfl @[simp] lemma coweightEquiv_symm_coweightMap (e : RootPairing.Equiv P Q) (n : N₂) : (coweightEquiv P Q e).symm (e.toHom.coweightMap n) = n := (LinearEquiv.symm_apply_eq (coweightEquiv P Q e)).mpr rfl @[simp] lemma coweightMap_coweightEquiv_symm (e : RootPairing.Equiv P Q) (n : N) : e.toHom.coweightMap ((coweightEquiv P Q e).symm n) = n := by rw [← coweightEquiv_apply] exact LinearEquiv.apply_symm_apply (coweightEquiv P Q e) n /-- The identity equivalence of a root pairing. -/ @[simps!] def id (P : RootPairing ι R M N) : RootPairing.Equiv P P := { Hom.id P with bijective_weightMap := _root_.id bijective_id bijective_coweightMap := _root_.id bijective_id } /-- Composition of equivalences -/ @[simps!] def comp {ι₁ M₁ N₁ ι₂ M₂ N₂ : Type*} [AddCommGroup M₁] [Module R M₁] [AddCommGroup N₁] [Module R N₁] [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] {P : RootPairing ι R M N} {P₁ : RootPairing ι₁ R M₁ N₁} {P₂ : RootPairing ι₂ R M₂ N₂} (g : RootPairing.Equiv P₁ P₂) (f : RootPairing.Equiv P P₁) : RootPairing.Equiv P P₂ := { Hom.comp g.toHom f.toHom with bijective_weightMap := by simp only [Hom.comp, LinearMap.coe_comp] exact Bijective.comp g.bijective_weightMap f.bijective_weightMap bijective_coweightMap := by simp only [Hom.comp, LinearMap.coe_comp] exact Bijective.comp f.bijective_coweightMap g.bijective_coweightMap } @[simp] lemma toHom_comp {ι₁ M₁ N₁ ι₂ M₂ N₂ : Type*} [AddCommGroup M₁] [Module R M₁] [AddCommGroup N₁] [Module R N₁] [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] {P : RootPairing ι R M N} {P₁ : RootPairing ι₁ R M₁ N₁} {P₂ : RootPairing ι₂ R M₂ N₂} (g : RootPairing.Equiv P₁ P₂) (f : RootPairing.Equiv P P₁) : (Equiv.comp g f).toHom = Hom.comp g.toHom f.toHom := by rfl @[simp] lemma id_comp {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) (f : RootPairing.Equiv P Q) : comp f (id P) = f := by ext x <;> simp @[simp] lemma comp_id {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) (f : RootPairing.Equiv P Q) : comp (id Q) f = f := by ext x <;> simp @[simp] lemma comp_assoc {ι₁ M₁ N₁ ι₂ M₂ N₂ ι₃ M₃ N₃ : Type*} [AddCommGroup M₁] [Module R M₁] [AddCommGroup N₁] [Module R N₁] [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] [AddCommGroup M₃] [Module R M₃] [AddCommGroup N₃] [Module R N₃] {P : RootPairing ι R M N} {P₁ : RootPairing ι₁ R M₁ N₁} {P₂ : RootPairing ι₂ R M₂ N₂} {P₃ : RootPairing ι₃ R M₃ N₃} (h : RootPairing.Equiv P₂ P₃) (g : RootPairing.Equiv P₁ P₂) (f : RootPairing.Equiv P P₁) : comp (comp h g) f = comp h (comp g f) := by ext <;> simp /-- Equivalences form a monoid. -/ instance (P : RootPairing ι R M N) : Monoid (RootPairing.Equiv P P) where mul := comp mul_assoc := comp_assoc one := id P one_mul := id_comp P P mul_one := comp_id P P @[simp] lemma weightEquiv_one (P : RootPairing ι R M N) : weightEquiv (P := P) (Q := P) 1 = LinearMap.id (R := R) (M := M) := rfl @[simp] lemma coweightEquiv_one (P : RootPairing ι R M N) : coweightEquiv (P := P) (Q := P) 1 = LinearMap.id (R := R) (M := N) := rfl @[simp] lemma toHom_one (P : RootPairing ι R M N) : (1 : RootPairing.Equiv P P).toHom = (1 : RootPairing.Hom P P) := rfl @[simp] lemma mul_eq_comp {P : RootPairing ι R M N} (x y : RootPairing.Equiv P P) : x * y = Equiv.comp x y := rfl @[simp] lemma weightEquiv_comp_toLin {P : RootPairing ι R M N} (x y : RootPairing.Equiv P P) : weightEquiv P P (Equiv.comp x y) = weightEquiv P P y ≪≫ₗ weightEquiv P P x := by ext; simp @[simp] lemma weightEquiv_mul {P : RootPairing ι R M N} (x y : RootPairing.Equiv P P) : weightEquiv P P x * weightEquiv P P y = weightEquiv P P y ≪≫ₗ weightEquiv P P x := by rfl @[simp] lemma coweightEquiv_comp_toLin {P : RootPairing ι R M N} (x y : RootPairing.Equiv P P) : coweightEquiv P P (Equiv.comp x y) = coweightEquiv P P x ≪≫ₗ coweightEquiv P P y := by ext; simp @[simp] lemma coweightEquiv_mul {P : RootPairing ι R M N} (x y : RootPairing.Equiv P P) : coweightEquiv P P x * coweightEquiv P P y = coweightEquiv P P y ≪≫ₗ coweightEquiv P P x := by rfl /-- The inverse of a root pairing equivalence. -/ def symm {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) (f : RootPairing.Equiv P Q) : RootPairing.Equiv Q P where weightMap := (weightEquiv P Q f).symm coweightMap := (coweightEquiv P Q f).symm indexEquiv := f.indexEquiv.symm weight_coweight_transpose := by ext n m nth_rw 2 [show m = (weightEquiv P Q f) ((weightEquiv P Q f).symm m) by exact (LinearEquiv.symm_apply_eq (weightEquiv P Q f)).mp rfl] nth_rw 1 [show n = (coweightEquiv P Q f) ((coweightEquiv P Q f).symm n) by exact (LinearEquiv.symm_apply_eq (coweightEquiv P Q f)).mp rfl] have := f.weight_coweight_transpose rw [LinearMap.ext_iff₂] at this exact Eq.symm (this ((coweightEquiv P Q f).symm n) ((weightEquiv P Q f).symm m)) root_weightMap := by ext i simp only [LinearEquiv.coe_coe, comp_apply] have := f.root_weightMap rw [funext_iff] at this specialize this (f.indexEquiv.symm i) simp only [comp_apply, Equiv.apply_symm_apply] at this simp [← this] coroot_coweightMap := by ext i simp only [LinearEquiv.coe_coe, comp_apply, Equiv.symm_symm] have := f.coroot_coweightMap rw [funext_iff] at this specialize this (f.indexEquiv i) simp only [comp_apply, Equiv.symm_apply_apply] at this simp [← this] bijective_weightMap := by simp only [LinearEquiv.coe_coe] exact LinearEquiv.bijective (weightEquiv P Q f).symm bijective_coweightMap := by simp only [LinearEquiv.coe_coe] exact LinearEquiv.bijective (coweightEquiv P Q f).symm @[simp] lemma inv_weightMap {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) (f : RootPairing.Equiv P Q) : (symm P Q f).weightMap = (weightEquiv P Q f).symm := rfl @[simp] lemma inv_coweightMap {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) (f : RootPairing.Equiv P Q) : (symm P Q f).coweightMap = (coweightEquiv P Q f).symm := rfl @[simp] lemma inv_indexEquiv {ι₂ M₂ N₂ : Type*} [AddCommGroup M₂] [Module R M₂] [AddCommGroup N₂] [Module R N₂] (P : RootPairing ι R M N) (Q : RootPairing ι₂ R M₂ N₂) (f : RootPairing.Equiv P Q) : (symm P Q f).indexEquiv = (Hom.indexEquiv f.toHom).symm := rfl /-- Equivalences form a group. -/ instance (P : RootPairing ι R M N) : Group (RootPairing.Equiv P P) where mul := comp mul_assoc := comp_assoc one := id P one_mul := id_comp P P mul_one := comp_id P P inv := symm P P inv_mul_cancel e := by ext m · rw [← weightEquiv_apply] simp · rw [← coweightEquiv_apply] simp · simp /-- For finite roots systems in characteristic zero, a linear equivalence preserving roots, also preserves coroots, and is thus an equivalence of root systems. -/ def mk' [CharZero R] [NoZeroSMulDivisors R M₂] [Finite ι₂] (P : RootSystem ι R M N) (Q : RootSystem ι₂ R M₂ N₂) (f : M ≃ₗ[R] M₂) (e : ι ≃ ι₂) (hf : ∀ i, f (P.root i) = Q.root (e i)) : P.Equiv Q.toRootPairing where weightMap := f coweightMap := Q.flip.toPerfPair.trans (f.dualMap.trans P.flip.toPerfPair.symm) indexEquiv := e weight_coweight_transpose := by ext; simp [RootSystem.flip] root_weightMap := by ext; simp [hf] coroot_coweightMap := by let g : N ≃ₗ[R] N₂ := P.flip.toPerfPair.trans <| f.symm.dualMap.trans Q.flip.toPerfPair.symm suffices Q = P.map e f g by ext i rw [LinearEquiv.coe_coe, comp_apply, ← LinearEquiv.eq_symm_apply] conv_lhs => rw [this] rfl ext m n · simp [RootSystem.map, RootPairing.map, RootSystem.flip, g] · simp [hf, RootSystem.map, RootPairing.map] bijective_weightMap := LinearEquiv.bijective _ bijective_coweightMap := LinearEquiv.bijective _ end Equiv /-- The automorphism group of a root pairing. -/ abbrev Aut (P : RootPairing ι R M N) := (RootPairing.Equiv P P) namespace Equiv /-- The isomorphism between the automorphism group of a root pairing and the group of invertible endomorphisms. -/ def toEndUnit (P : RootPairing ι R M N) : Aut P ≃* (End P)ˣ where toFun f := { val := f.toHom inv := (Equiv.symm P P f).toHom val_inv := by ext <;> simp inv_val := by ext <;> simp } invFun f := { f.val with bijective_weightMap := by refine bijective_iff_has_inverse.mpr ?_ use f.inv.weightMap constructor · refine leftInverse_iff_comp.mpr ?_ simp only [← @LinearMap.coe_comp] rw [← Hom.weightMap_mul, f.inv_val, Hom.weightMap_one, LinearMap.id_coe] · refine rightInverse_iff_comp.mpr ?_ simp only [← @LinearMap.coe_comp] rw [← Hom.weightMap_mul, f.val_inv, Hom.weightMap_one, LinearMap.id_coe] bijective_coweightMap := by refine bijective_iff_has_inverse.mpr ?_ use f.inv.coweightMap constructor · refine leftInverse_iff_comp.mpr ?_ simp only [← @LinearMap.coe_comp] rw [← Hom.coweightMap_mul, f.val_inv, Hom.coweightMap_one, LinearMap.id_coe] · refine rightInverse_iff_comp.mpr ?_ simp only [← @LinearMap.coe_comp] rw [← Hom.coweightMap_mul, f.inv_val, Hom.coweightMap_one, LinearMap.id_coe] } left_inv f := by simp right_inv f := by simp map_mul' f g := by simp only [Equiv.mul_eq_comp, Equiv.toHom_comp] ext <;> simp lemma toEndUnit_val (P : RootPairing ι R M N) (g : Aut P) : (toEndUnit P g).val = g.toHom := rfl lemma toEndUnit_inv (P : RootPairing ι R M N) (g : Aut P) : (toEndUnit P g).inv = (symm P P g).toHom := rfl /-- The weight space representation of automorphisms -/ @[simps] def weightHom (P : RootPairing ι R M N) : Aut P →* (M ≃ₗ[R] M) where toFun := weightEquiv P P map_one' := by ext; simp map_mul' x y := by ext; simp lemma weightHom_toLinearMap {P : RootPairing ι R M N} (g : Aut P) : (weightHom P g).toLinearMap = Hom.weightHom P g.toHom := rfl lemma weightHom_injective (P : RootPairing ι R M N) : Injective (Equiv.weightHom P) := by refine Injective.of_comp (f := LinearEquiv.toLinearMap) fun g g' hgg' => ?_ let h : (weightHom P g).toLinearMap = (weightHom P g').toLinearMap := hgg' --`have` gets lint rw [weightHom_toLinearMap, weightHom_toLinearMap] at h suffices h' : g.toHom = g'.toHom by exact Equiv.ext hgg' (congrArg Hom.coweightMap h') (congrArg Hom.indexEquiv h') exact Hom.weightHom_injective P hgg' @[simp] lemma weightEquiv_inv {P : RootPairing ι R M N} (g : Aut P) : weightEquiv P P g⁻¹ = (weightEquiv P P g)⁻¹ := LinearEquiv.toLinearMap_inj.mp rfl /-- The coweight space representation of automorphisms -/ @[simps] def coweightHom (P : RootPairing ι R M N) : Aut P →* (N ≃ₗ[R] N)ᵐᵒᵖ where toFun g := MulOpposite.op (coweightEquiv P P g) map_one' := by simp only [MulOpposite.op_eq_one_iff] exact LinearEquiv.toLinearMap_inj.mp rfl map_mul' := by simp only [mul_eq_comp, coweightEquiv_comp_toLin] exact fun x y ↦ rfl lemma coweightHom_toLinearMap {P : RootPairing ι R M N} (g : Aut P) : (MulOpposite.unop (coweightHom P g)).toLinearMap = MulOpposite.unop (Hom.coweightHom P g.toHom) := rfl lemma coweightHom_injective (P : RootPairing ι R M N) : Injective (Equiv.coweightHom P) := by refine Injective.of_comp (f := fun a => MulOpposite.op a) fun g g' hgg' => ?_ have h : (MulOpposite.unop (coweightHom P g)).toLinearMap = (MulOpposite.unop (coweightHom P g')).toLinearMap := by simp_all rw [coweightHom_toLinearMap, coweightHom_toLinearMap] at h suffices h' : g.toHom = g'.toHom by exact Equiv.ext (congrArg Hom.weightMap h') h (congrArg Hom.indexEquiv h') apply Hom.coweightHom_injective P exact MulOpposite.unop_inj.mp h lemma coweightHom_op {P : RootPairing ι R M N} (g : Aut P) : MulOpposite.unop (coweightHom P g) = coweightEquiv P P g := rfl @[simp] lemma coweightEquiv_inv {P : RootPairing ι R M N} (g : Aut P) : coweightEquiv P P g⁻¹ = (coweightEquiv P P g)⁻¹ := LinearEquiv.toLinearMap_inj.mp rfl /-- The permutation representation of the automorphism group on the root index set -/ @[simps] def indexHom (P : RootPairing ι R M N) : Aut P →* (ι ≃ ι) where toFun g := g.toHom.indexEquiv map_one' := by ext; simp map_mul' x y := by ext; simp @[simp] lemma indexEquiv_inv {P : RootPairing ι R M N} (g : Aut P) : (g⁻¹).toHom.indexEquiv = (indexHom P g)⁻¹ := rfl /-- The automorphism of a root pairing given by a reflection. -/ def reflection (P : RootPairing ι R M N) (i : ι) : Aut P where weightMap := P.reflection i coweightMap := P.coreflection i indexEquiv := P.reflectionPerm i weight_coweight_transpose := by ext f x; simpa [reflection_apply, coreflection_apply] using mul_comm .. root_weightMap := by ext; simp coroot_coweightMap := by ext; simp bijective_weightMap := by simp only [LinearEquiv.coe_coe] exact LinearEquiv.bijective (P.reflection i) bijective_coweightMap := by simp only [LinearEquiv.coe_coe] exact LinearEquiv.bijective (P.coreflection i) @[simp] lemma reflection_weightEquiv (P : RootPairing ι R M N) (i : ι) : (reflection P i).weightEquiv = P.reflection i := LinearEquiv.toLinearMap_inj.mp rfl @[simp] lemma reflection_coweightEquiv (P : RootPairing ι R M N) (i : ι) : (reflection P i).coweightEquiv = P.coreflection i := LinearEquiv.toLinearMap_inj.mp rfl @[simp] lemma reflection_indexEquiv (P : RootPairing ι R M N) (i : ι) : (reflection P i).indexEquiv = P.reflectionPerm i := rfl @[simp] lemma reflection_inv (P : RootPairing ι R M N) (i : ι) : (reflection P i)⁻¹ = (reflection P i) := by refine Equiv.ext ?_ ?_ ?_ · exact LinearMap.ext_iff.mpr (fun x => by simp [← weightEquiv_apply]) · exact LinearMap.ext_iff.mpr (fun x => by simp [← coweightEquiv_apply]) · exact _root_.Equiv.ext (fun j => by simp) instance : DistribMulAction P.Aut M where smul w x := weightHom P w x one_smul _ := rfl mul_smul _ _ _ := rfl smul_zero w := show weightHom P w 0 = 0 by simp smul_add w x y := show weightHom P w (x + y) = weightHom P w x + weightHom P w y by simp @[simp] lemma reflection_smul (i : ι) (x : M) : Equiv.reflection P i • x = P.reflection i x := rfl @[simp] lemma root_indexEquiv_eq_smul (i : ι) (g : P.Aut) : P.root (g.indexEquiv i) = g • P.root i := by simpa using (congr_fun g.root_weightMap i).symm open MulOpposite in instance : DistribMulAction P.Autᵐᵒᵖ N where smul w x := unop (coweightHom P (unop w)) x one_smul _ := rfl mul_smul _ _ _ := rfl smul_zero w := show unop (coweightHom P (unop w)) 0 = 0 by simp smul_add w x y := by change unop (coweightHom P _) (x + y) = unop (coweightHom P _) x + unop (coweightHom P _) y simp instance : SMulCommClass P.Aut R M where smul_comm w t x := show weightHom P w (t • x) = t • weightHom P w x by simp open MulOpposite in instance : SMulCommClass P.Autᵐᵒᵖ R N where smul_comm w t x := by change unop (coweightHom P (unop w)) (t • x) = t • unop (coweightHom P (unop w)) x simp instance : MulAction P.Aut ι where smul w i := Equiv.indexHom P w i one_smul _ := rfl mul_smul _ _ _ := rfl end Equiv end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/Reduced.lean
import Mathlib.LinearAlgebra.RootSystem.IsValuedIn /-! # Reduced root pairings This file contains basic definitions and results related to reduced root pairings. ## Main definitions: * `RootPairing.IsReduced`: A root pairing is said to be reduced if two linearly dependent roots are always related by a sign. * `RootPairing.linearIndependent_iff_coxeterWeight_ne_four`: for a finite root pairing, two roots are linearly independent iff their Coxeter weight is not four. ## Implementation details: For convenience we provide two versions of many lemmas, according to whether we know that the root pairing is valued in a smaller ring (in the sense of `RootPairing.IsValuedIn`). For example we provide both `RootPairing.linearIndependent_iff_coxeterWeight_ne_four` and `RootPairing.linearIndependent_iff_coxeterWeightIn_ne_four`. Several ways to avoid this duplication exist. We leave explorations of this for future work. One possible solution is to drop `RootPairing.pairing` and `RootPairing.coxeterWeight` entirely and rely solely on `RootPairing.pairingIn` and `RootPairing.coxeterWeightIn`. -/ open Module Set Function variable {ι R M N : Type*} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] (P : RootPairing ι R M N) (S : Type*) {i j : ι} namespace RootPairing /-- A root pairing is said to be reduced if any linearly dependent pair of roots is related by a sign. TODO Consider redefining this to make it perfectly symemtric between roots and coroots (i.e., so that the same demand is made of coroots) and turning `RootPairing.instFlipIsReduced` into a convenience constructor. -/ @[mk_iff] class IsReduced : Prop where eq_or_eq_neg (i j : ι) (h : ¬ LinearIndependent R ![P.root i, P.root j]) : P.root i = P.root j ∨ P.root i = - P.root j lemma isReduced_iff' : P.IsReduced ↔ ∀ i j : ι, i ≠ j → ¬ LinearIndependent R ![P.root i, P.root j] → P.root i = - P.root j := by rw [isReduced_iff] refine ⟨fun h i j hij hLin ↦ ?_, fun h i j hLin ↦ ?_⟩ · specialize h i j hLin simp_all only [ne_eq, EmbeddingLike.apply_eq_iff_eq, false_or] · rcases eq_or_ne i j with rfl | h' · tauto · exact Or.inr (h i j h' hLin) lemma IsReduced.linearIndependent [P.IsReduced] (h : i ≠ j) (h' : P.root i ≠ -P.root j) : LinearIndependent R ![P.root i, P.root j] := by have := IsReduced.eq_or_eq_neg (P := P) i j simp_all lemma IsReduced.linearIndependent_iff [Nontrivial R] [P.IsReduced] : LinearIndependent R ![P.root i, P.root j] ↔ i ≠ j ∧ P.root i ≠ - P.root j := by refine ⟨fun h ↦ ?_, fun ⟨h, h'⟩ ↦ linearIndependent P h h'⟩ rw [LinearIndependent.pair_iff] at h contrapose! h rcases eq_or_ne i j with rfl | h' · exact ⟨1, -1, by simp⟩ · rw [h h'] exact ⟨1, 1, by simp⟩ lemma nsmul_notMem_range_root [CharZero R] [IsAddTorsionFree M] [P.IsReduced] {n : ℕ} [n.AtLeastTwo] {i : ι} : n • P.root i ∉ range P.root := by have : ¬ LinearIndependent R ![n • P.root i, P.root i] := by simpa only [LinearIndependent.pair_iff, not_forall] using ⟨1, -(n : R), by simp [Nat.cast_smul_eq_nsmul], by simp⟩ rintro ⟨j, hj⟩ replace this : j = i ∨ P.root j = -P.root i := by simpa only [← hj, IsReduced.linearIndependent_iff, not_and_or, not_not] using this rcases this with rfl | this · replace hj : (1 : ℤ) • P.root j = (n : ℤ) • P.root j := by simpa rw [(smul_left_injective ℤ <| P.ne_zero j).eq_iff, eq_comm] at hj have : 2 ≤ n := Nat.AtLeastTwo.prop cutsat · rw [← one_smul ℤ (P.root i), ← neg_smul, hj] at this replace this : (n : ℤ) • P.root i = -1 • P.root i := by simpa rw [(smul_left_injective ℤ <| P.ne_zero i).eq_iff] at this cutsat @[deprecated (since := "2025-07-06")] alias two_smul_notMem_range_root := nsmul_notMem_range_root @[deprecated (since := "2025-05-24")] alias two_smul_nmem_range_root := two_smul_notMem_range_root lemma linearIndependent_of_add_mem_range_root [CharZero R] [IsAddTorsionFree M] [P.IsReduced] {i j : ι} (h : P.root i + P.root j ∈ range P.root) : LinearIndependent R ![P.root i, P.root j] := by refine IsReduced.linearIndependent P (fun hij ↦ ?_) (fun hij ↦ P.zero_notMem_range_root ?_) · rw [hij, ← two_smul (R := ℕ)] at h exact P.nsmul_notMem_range_root h · rwa [hij, neg_add_cancel] at h lemma linearIndependent_of_sub_mem_range_root [CharZero R] [IsAddTorsionFree M] [P.IsReduced] {i j : ι} (h : P.root i - P.root j ∈ range P.root) : LinearIndependent R ![P.root i, P.root j] := by suffices LinearIndependent R ![P.root i, P.root (P.reflectionPerm j j)] by simpa using this apply P.linearIndependent_of_add_mem_range_root simpa [sub_eq_add_neg] using h lemma linearIndependent_of_add_mem_range_root' [CharZero R] [IsDomain R] [P.IsReduced] {i j : ι} (h : P.root i + P.root j ∈ range P.root) : LinearIndependent R ![P.root i, P.root j] := have : IsReflexive R M := .of_isPerfPair P.toLinearMap have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M P.linearIndependent_of_add_mem_range_root h lemma linearIndependent_of_sub_mem_range_root' [CharZero R] [IsDomain R] [P.IsReduced] {i j : ι} (h : P.root i - P.root j ∈ range P.root) : LinearIndependent R ![P.root i, P.root j] := have : IsReflexive R M := .of_isPerfPair P.toLinearMap have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M P.linearIndependent_of_sub_mem_range_root h lemma infinite_of_linearIndependent_coxeterWeight_four [NeZero (2 : R)] [IsAddTorsionFree M] (hl : LinearIndependent R ![P.root i, P.root j]) (hc : P.coxeterWeight i j = 4) : Infinite ι := by refine (infinite_range_iff (Embedding.injective P.root)).mp (Infinite.mono ?_ ((infinite_range_reflection_reflection_iterate_iff (P.coroot_root_two i) (P.coroot_root_two j) ?_).mpr ?_)) · rw [range_subset_iff] intro n rw [← IsFixedPt.image_iterate ((bijOn_reflection_of_mapsTo (P.coroot_root_two i) (P.mapsTo_reflection_root i)).comp (bijOn_reflection_of_mapsTo (P.coroot_root_two j) (P.mapsTo_reflection_root j))).image_eq n] exact mem_image_of_mem _ (mem_range_self j) · rw [coroot_root_eq_pairing, coroot_root_eq_pairing, ← hc, mul_comm, coxeterWeight] · rw [LinearIndependent.pair_iff] at hl specialize hl (P.pairing j i) (-2) simp only [neg_smul, neg_eq_zero, two_ne_zero (α := R), and_false, imp_false] at hl rw [ne_eq, coroot_root_eq_pairing, ← sub_eq_zero, sub_eq_add_neg] exact hl lemma pairing_smul_root_eq_of_not_linearIndependent [NeZero (2 : R)] [NoZeroSMulDivisors R M] (h : ¬ LinearIndependent R ![P.root i, P.root j]) : P.pairing j i • P.root i = (2 : R) • P.root j := by rw [LinearIndependent.pair_iff] at h push_neg at h obtain ⟨s, t, h₁, h₂⟩ := h replace h₂ : s ≠ 0 := by rcases eq_or_ne s 0 with rfl | hs · exact False.elim <| h₂ rfl <| (smul_eq_zero_iff_left <| P.ne_zero j).mp <| by simpa using h₁ · assumption have h₃ : t ≠ 0 := by rcases eq_or_ne t 0 with rfl | ht · exact False.elim <| h₂ <| (smul_eq_zero_iff_left <| P.ne_zero i).mp <| by simpa using h₁ · assumption replace h₁ : s • P.root i = -t • P.root j := by rwa [← eq_neg_iff_add_eq_zero, ← neg_smul] at h₁ have h₄ : s * 2 = - (t * P.pairing j i) := by simpa using congr_arg (P.coroot' i) h₁ replace h₁ : (2 : R) • (s • P.root i) = (2 : R) • (-t • P.root j) := by rw [h₁] rw [smul_smul, mul_comm, h₄, smul_comm, ← neg_mul, ← smul_smul] at h₁ exact smul_right_injective M (neg_ne_zero.mpr h₃) h₁ section Finite variable [Finite ι] lemma coxeterWeight_ne_four_of_linearIndependent [NeZero (2 : R)] [IsAddTorsionFree M] (hl : LinearIndependent R ![P.root i, P.root j]) : P.coxeterWeight i j ≠ 4 := by intro contra have := P.infinite_of_linearIndependent_coxeterWeight_four hl contra exact not_finite ι variable [CharZero R] [NoZeroSMulDivisors R M] /-- See also `RootPairing.linearIndependent_iff_coxeterWeightIn_ne_four`. -/ lemma linearIndependent_iff_coxeterWeight_ne_four : LinearIndependent R ![P.root i, P.root j] ↔ P.coxeterWeight i j ≠ 4 := by have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M refine ⟨coxeterWeight_ne_four_of_linearIndependent P, fun h ↦ ?_⟩ contrapose! h have h₁ := P.pairing_smul_root_eq_of_not_linearIndependent h rw [LinearIndependent.pair_symm_iff] at h have h₂ := P.pairing_smul_root_eq_of_not_linearIndependent h suffices P.coxeterWeight i j • P.root i = (4 : R) • P.root i from smul_left_injective R (P.ne_zero i) this calc P.coxeterWeight i j • P.root i = (P.pairing i j * P.pairing j i) • P.root i := by rfl _ = P.pairing i j • (2 : R) • P.root j := by rw [mul_smul, h₁] _ = (4 : R) • P.root i := by rw [smul_comm, h₂, ← mul_smul]; norm_num /-- See also `RootPairing.coxeterWeightIn_eq_four_iff_not_linearIndependent`. -/ lemma coxeterWeight_eq_four_iff_not_linearIndependent : P.coxeterWeight i j = 4 ↔ ¬ LinearIndependent R ![P.root i, P.root j] := by rw [P.linearIndependent_iff_coxeterWeight_ne_four, not_not] instance instFlipIsReduced [P.IsReduced] [NoZeroSMulDivisors R N] : P.flip.IsReduced := by refine ⟨fun i j h ↦ ?_⟩ rcases eq_or_ne i j with rfl | hij; · tauto right rw [← coxeterWeight_eq_four_iff_not_linearIndependent, coxeterWeight_flip, coxeterWeight_eq_four_iff_not_linearIndependent, IsReduced.linearIndependent_iff] at h push_neg at h simp [P.root_eq_neg_iff.mp (h hij)] variable (i j) /-- See also `RootPairing.pairingIn_two_two_iff`. -/ @[simp] lemma pairing_two_two_iff : P.pairing i j = 2 ∧ P.pairing j i = 2 ↔ i = j := by refine ⟨fun ⟨h₁, h₂⟩ ↦ ?_, fun h ↦ by simp [h]⟩ have : ¬ LinearIndependent R ![P.root i, P.root j] := by rw [← coxeterWeight_eq_four_iff_not_linearIndependent, coxeterWeight, h₁, h₂]; norm_num replace this := P.pairing_smul_root_eq_of_not_linearIndependent this exact P.root.injective <| smul_right_injective M two_ne_zero (h₂ ▸ this) /-- See also `RootPairing.pairingIn_neg_two_neg_two_iff`. -/ @[simp] lemma pairing_neg_two_neg_two_iff : P.pairing i j = -2 ∧ P.pairing j i = -2 ↔ P.root i = -P.root j := by simp only [← neg_eq_iff_eq_neg] simpa [eq_comm (a := -P.root i), eq_comm (b := j)] using P.pairing_two_two_iff (P.reflectionPerm i i) j variable [NoZeroSMulDivisors R N] lemma pairing_one_four_iff' (h2 : IsSMulRegular R (2 : R)) : P.pairing i j = 1 ∧ P.pairing j i = 4 ↔ P.root j = (2 : R) • P.root i := by have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M have : IsAddTorsionFree N := .of_noZeroSMulDivisors R N refine ⟨fun ⟨h₁, h₂⟩ ↦ ?_, fun h ↦ ?_⟩ · have : ¬ LinearIndependent R ![P.root i, P.root j] := by rw [← coxeterWeight_eq_four_iff_not_linearIndependent, coxeterWeight, h₁, h₂]; simp replace this := P.pairing_smul_root_eq_of_not_linearIndependent this rw [h₂, show (4 : R) = 2 * 2 by norm_num, mul_smul] at this exact smul_right_injective M two_ne_zero this.symm · rw [← coroot_eq_smul_coroot_iff] at h rw [pairing, pairing, h] norm_num suffices (2 : R) • P.pairing i j = (2 : R) • 1 from h2 this rw [pairing, ← map_smul, ← h] simp lemma pairing_neg_one_neg_four_iff' (h2 : IsSMulRegular R (2 : R)) : P.pairing i j = -1 ∧ P.pairing j i = -4 ↔ P.root j = (-2 : R) • P.root i := by simpa [neg_smul, ← neg_eq_iff_eq_neg] using P.pairing_one_four_iff' i (P.reflectionPerm j j) h2 /-- See also `RootPairing.pairingIn_one_four_iff`. -/ @[simp] lemma pairing_one_four_iff [IsDomain R] : P.pairing i j = 1 ∧ P.pairing j i = 4 ↔ P.root j = (2 : R) • P.root i := P.pairing_one_four_iff' i j <| smul_right_injective R two_ne_zero /-- See also `RootPairing.pairingIn_neg_one_neg_four_iff`. -/ @[simp] lemma pairing_neg_one_neg_four_iff [IsDomain R] : P.pairing i j = -1 ∧ P.pairing j i = -4 ↔ P.root j = (-2 : R) • P.root i := P.pairing_neg_one_neg_four_iff' i j <| smul_right_injective R two_ne_zero section IsValuedIn open FaithfulSMul variable [CommRing S] [Algebra S R] [FaithfulSMul S R] [P.IsValuedIn S] omit [NoZeroSMulDivisors R N] variable {i j} lemma linearIndependent_iff_coxeterWeightIn_ne_four : LinearIndependent R ![P.root i, P.root j] ↔ P.coxeterWeightIn S i j ≠ 4 := by rw [linearIndependent_iff_coxeterWeight_ne_four, ← P.algebraMap_coxeterWeightIn S, ← map_ofNat (algebraMap S R), (algebraMap_injective S R).ne_iff] lemma coxeterWeightIn_eq_four_iff_not_linearIndependent : P.coxeterWeightIn S i j = 4 ↔ ¬ LinearIndependent R ![P.root i, P.root j] := by rw [P.linearIndependent_iff_coxeterWeightIn_ne_four S, not_not] lemma coxeterWeightIn_ne_four [P.IsReduced] (h : i ≠ j) (h' : P.root i ≠ -P.root j) : P.coxeterWeightIn S i j ≠ 4 := by rw [ne_eq, coxeterWeightIn_eq_four_iff_not_linearIndependent, not_not] exact IsReduced.linearIndependent P h h' variable (i j) @[simp] lemma pairingIn_two_two_iff : P.pairingIn S i j = 2 ∧ P.pairingIn S j i = 2 ↔ i = j := by simp only [← P.pairing_two_two_iff, ← P.algebraMap_pairingIn S, ← map_ofNat (algebraMap S R), (algebraMap_injective S R).eq_iff] @[simp] lemma pairingIn_neg_two_neg_two_iff : P.pairingIn S i j = -2 ∧ P.pairingIn S j i = -2 ↔ P.root i = -P.root j := by simp only [← P.pairing_neg_two_neg_two_iff, ← P.algebraMap_pairingIn S, ← map_ofNat (algebraMap S R), (algebraMap_injective S R).eq_iff, ← map_neg] variable [NoZeroSMulDivisors R N] lemma pairingIn_one_four_iff [IsDomain R] : P.pairingIn S i j = 1 ∧ P.pairingIn S j i = 4 ↔ P.root j = (2 : R) • P.root i := by rw [← P.pairing_one_four_iff, ← P.algebraMap_pairingIn S, ← P.algebraMap_pairingIn S, ← map_one (algebraMap S R), ← map_ofNat (algebraMap S R), (algebraMap_injective S R).eq_iff, (algebraMap_injective S R).eq_iff] lemma pairingIn_neg_one_neg_four_iff [IsDomain R] : P.pairingIn S i j = -1 ∧ P.pairingIn S j i = -4 ↔ P.root j = (-2 : R) • P.root i := by rw [← P.pairing_neg_one_neg_four_iff, ← P.algebraMap_pairingIn S, ← P.algebraMap_pairingIn S, ← map_one (algebraMap S R), ← map_ofNat (algebraMap S R), ← map_neg, ← map_neg, (algebraMap_injective S R).eq_iff, (algebraMap_injective S R).eq_iff] end IsValuedIn end Finite end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/Finite/Lemmas.lean
import Mathlib.LinearAlgebra.RootSystem.Finite.CanonicalBilinear import Mathlib.LinearAlgebra.RootSystem.Reduced import Mathlib.LinearAlgebra.RootSystem.Irreducible import Mathlib.Algebra.Ring.Torsion /-! # Structural lemmas about finite crystallographic root pairings In this file we gather basic lemmas necessary for the classification of finite crystallographic root pairings. ## Main results: * `RootPairing.coxeterWeightIn_mem_set_of_isCrystallographic`: the Coxeter weights of a finite crystallographic root pairing belong to the set `{0, 1, 2, 3, 4}`. * `RootPairing.root_sub_root_mem_of_pairingIn_pos`: if `α ≠ β` are both roots of a finite crystallographic root pairing, and the pairing of `α` with `β` is positive, then `α - β` is also a root. * `RootPairing.root_add_root_mem_of_pairingIn_neg`: if `α ≠ -β` are both roots of a finite crystallographic root pairing, and the pairing of `α` with `β` is negative, then `α + β` is also a root. -/ noncomputable section open Function Set open Submodule (span) open FaithfulSMul (algebraMap_injective) variable {ι R M N : Type*} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] namespace RootPairing variable (P : RootPairing ι R M N) [Finite ι] local notation "Φ" => range P.root local notation "α" => P.root /-- SGA3 XXI Prop. 2.3.1 -/ lemma coxeterWeightIn_le_four (S : Type*) [CommRing S] [LinearOrder S] [IsStrictOrderedRing S] [Algebra S R] [FaithfulSMul S R] [Module S M] [IsScalarTower S R M] [P.IsValuedIn S] (i j : ι) : P.coxeterWeightIn S i j ≤ 4 := by have : Fintype ι := Fintype.ofFinite ι let ri : span S Φ := ⟨α i, Submodule.subset_span (mem_range_self _)⟩ let rj : span S Φ := ⟨α j, Submodule.subset_span (mem_range_self _)⟩ set li := (P.posRootForm S).rootLength i set lj := (P.posRootForm S).rootLength j set lij := (P.posRootForm S).posForm ri rj obtain ⟨si, hsi, hsi'⟩ := (P.posRootForm S).exists_pos_eq i obtain ⟨sj, hsj, hsj'⟩ := (P.posRootForm S).exists_pos_eq j replace hsi' : si = li := algebraMap_injective S R <| by simpa [li] using hsi' replace hsj' : sj = lj := algebraMap_injective S R <| by simpa [lj] using hsj' rw [hsi'] at hsi rw [hsj'] at hsj have cs : 4 * lij ^ 2 ≤ 4 * (li * lj) := by rw [mul_le_mul_iff_right₀ four_pos] refine (P.posRootForm S).posForm.apply_sq_le_of_symm ?_ (P.posRootForm S).isSymm_posForm ri rj intro x obtain ⟨s, hs, hs'⟩ := P.exists_ge_zero_eq_rootForm S x x.property change _ = (P.posRootForm S).form x x at hs' rw [(P.posRootForm S).algebraMap_apply_eq_form_iff] at hs' rwa [← hs'] have key : 4 • lij ^ 2 = P.coxeterWeightIn S i j • (li * lj) := by apply algebraMap_injective S R simpa [map_ofNat, lij, posRootForm, ri, rj, li, lj] using P.four_smul_rootForm_sq_eq_coxeterWeight_smul i j simp only [nsmul_eq_mul, smul_eq_mul, Nat.cast_ofNat] at key rwa [key, mul_le_mul_iff_left₀ (by positivity)] at cs variable [CharZero R] [P.IsCrystallographic] (i j : ι) lemma coxeterWeightIn_mem_set_of_isCrystallographic : P.coxeterWeightIn ℤ i j ∈ ({0, 1, 2, 3, 4} : Set ℤ) := by have : Fintype ι := Fintype.ofFinite ι obtain ⟨n, hcn⟩ : ∃ n : ℕ, P.coxeterWeightIn ℤ i j = n := by have : 0 ≤ P.coxeterWeightIn ℤ i j := by simpa only [P.algebraMap_coxeterWeightIn] using P.coxeterWeight_nonneg (P.posRootForm ℤ) i j obtain ⟨n, hn⟩ := Int.eq_ofNat_of_zero_le this exact ⟨n, by simp [hn]⟩ have : P.coxeterWeightIn ℤ i j ≤ 4 := P.coxeterWeightIn_le_four ℤ i j simp only [hcn, mem_insert_iff, mem_singleton_iff] at this ⊢ norm_cast at this ⊢ cutsat variable [IsDomain R] -- This makes an `IsAddTorsionFree R` instance available, which `grind` needs below. open scoped IsDomain lemma pairingIn_pairingIn_mem_set_of_isCrystallographic : (P.pairingIn ℤ i j, P.pairingIn ℤ j i) ∈ ({(0, 0), (1, 1), (-1, -1), (1, 2), (2, 1), (-1, -2), (-2, -1), (1, 3), (3, 1), (-1, -3), (-3, -1), (4, 1), (1, 4), (-4, -1), (-1, -4), (2, 2), (-2, -2)} : Set (ℤ × ℤ)) := by refine (Int.mul_mem_zero_one_two_three_four_iff ?_).mp (P.coxeterWeightIn_mem_set_of_isCrystallographic i j) simpa [← P.algebraMap_pairingIn ℤ] using P.pairing_eq_zero_iff' (i := i) (j := j) lemma pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed [P.IsReduced] : (P.pairingIn ℤ i j, P.pairingIn ℤ j i) ∈ ({(0, 0), (1, 1), (-1, -1), (1, 2), (2, 1), (-1, -2), (-2, -1), (1, 3), (3, 1), (-1, -3), (-3, -1), (2, 2), (-2, -2)} : Set (ℤ × ℤ)) := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap rcases eq_or_ne i j with rfl | h₁; · simp rcases eq_or_ne (α i) (-α j) with h₂ | h₂; · simp_all have aux₁ := P.pairingIn_pairingIn_mem_set_of_isCrystallographic i j have aux₂ : P.pairingIn ℤ i j * P.pairingIn ℤ j i ≠ 4 := P.coxeterWeightIn_ne_four ℤ h₁ h₂ aesop -- https://github.com/leanprover-community/mathlib4/issues/24551 (this should be faster) lemma pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed' [P.IsReduced] (hij : α i ≠ α j) (hij' : α i ≠ -α j) : (P.pairingIn ℤ i j, P.pairingIn ℤ j i) ∈ ({(0, 0), (1, 1), (-1, -1), (1, 2), (2, 1), (-1, -2), (-2, -1), (1, 3), (3, 1), (-1, -3), (-3, -1)} : Set (ℤ × ℤ)) := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap have := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed i j simp_all variable {P} in lemma RootPositiveForm.rootLength_le_of_pairingIn_eq (B : P.RootPositiveForm ℤ) {i j : ι} (hij : P.pairingIn ℤ i j = -1 ∨ P.pairingIn ℤ i j = 1) : B.rootLength i ≤ B.rootLength j := by have h : (P.pairingIn ℤ i j, P.pairingIn ℤ j i) ∈ ({(1, 1), (1, 2), (1, 3), (1, 4), (-1, -1), (-1, -2), (-1, -3), (-1, -4)} : Set (ℤ × ℤ)) := by have := P.pairingIn_pairingIn_mem_set_of_isCrystallographic i j aesop -- https://github.com/leanprover-community/mathlib4/issues/24551 (this should be faster) simp only [mem_insert_iff, mem_singleton_iff, Prod.mk_one_one, Prod.mk_eq_one, Prod.mk.injEq] at h have h' := B.pairingIn_mul_eq_pairingIn_mul_swap i j have hi := B.rootLength_pos i rcases h with hij' | hij' | hij' | hij' | hij' | hij' | hij' | hij' <;> rw [hij'.1, hij'.2] at h' <;> omega variable {P} in lemma RootPositiveForm.rootLength_lt_of_pairingIn_notMem (B : P.RootPositiveForm ℤ) {i j : ι} (hne : α i ≠ α j) (hne' : α i ≠ -α j) (hij : P.pairingIn ℤ i j ∉ ({-1, 0, 1} : Set ℤ)) : B.rootLength j < B.rootLength i := by have hij' : P.pairingIn ℤ i j = -3 ∨ P.pairingIn ℤ i j = -2 ∨ P.pairingIn ℤ i j = 2 ∨ P.pairingIn ℤ i j = 3 ∨ P.pairingIn ℤ i j = -4 ∨ P.pairingIn ℤ i j = 4 := by have := P.pairingIn_pairingIn_mem_set_of_isCrystallographic i j aesop -- https://github.com/leanprover-community/mathlib4/issues/24551 (this should be faster) have aux₁ : P.pairingIn ℤ j i = -1 ∨ P.pairingIn ℤ j i = 1 := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap have := P.pairingIn_pairingIn_mem_set_of_isCrystallographic i j aesop -- https://github.com/leanprover-community/mathlib4/issues/24551 (this should be faster) have aux₂ := B.pairingIn_mul_eq_pairingIn_mul_swap i j have hi := B.rootLength_pos i rcases aux₁ with hji | hji <;> rcases hij' with hij' | hij' | hij' | hij' | hij' | hij' <;> rw [hji, hij'] at aux₂ <;> omega @[deprecated (since := "2025-05-23")] alias RootPositiveForm.rootLength_lt_of_pairingIn_nmem := RootPositiveForm.rootLength_lt_of_pairingIn_notMem variable {i j} in lemma pairingIn_pairingIn_mem_set_of_length_eq {B : P.InvariantForm} (len_eq : B.form (α i) (α i) = B.form (α j) (α j)) : (P.pairingIn ℤ i j, P.pairingIn ℤ j i) ∈ ({(0, 0), (1, 1), (-1, -1), (2, 2), (-2, -2)} : Set (ℤ × ℤ)) := by replace len_eq : P.pairingIn ℤ i j = P.pairingIn ℤ j i := by simp only [← (FaithfulSMul.algebraMap_injective ℤ R).eq_iff, algebraMap_pairingIn] exact mul_right_cancel₀ (B.ne_zero j) (len_eq ▸ B.pairing_mul_eq_pairing_mul_swap j i) have := P.pairingIn_pairingIn_mem_set_of_isCrystallographic i j aesop -- https://github.com/leanprover-community/mathlib4/issues/24551 (this should be faster) variable {i j} in lemma pairingIn_pairingIn_mem_set_of_length_eq_of_ne {B : P.InvariantForm} (len_eq : B.form (α i) (α i) = B.form (α j) (α j)) (ne : i ≠ j) (ne' : α i ≠ -α j) : (P.pairingIn ℤ i j, P.pairingIn ℤ j i) ∈ ({(0, 0), (1, 1), (-1, -1)} : Set (ℤ × ℤ)) := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap have := P.pairingIn_pairingIn_mem_set_of_length_eq len_eq simp_all omit [Finite ι] in lemma coxeterWeightIn_eq_zero_iff : P.coxeterWeightIn ℤ i j = 0 ↔ P.pairingIn ℤ i j = 0 := by refine ⟨fun h ↦ ?_, fun h ↦ by rw [coxeterWeightIn, h, zero_mul]⟩ rwa [← (algebraMap_injective ℤ R).eq_iff, map_zero, algebraMap_coxeterWeightIn, RootPairing.coxeterWeight_zero_iff_isOrthogonal, IsOrthogonal, P.pairing_eq_zero_iff' (i := j) (j := i), and_self, ← P.algebraMap_pairingIn ℤ, FaithfulSMul.algebraMap_eq_zero_iff] at h variable {i j} lemma root_sub_root_mem_of_pairingIn_pos (h : 0 < P.pairingIn ℤ i j) (h' : i ≠ j) : α i - α j ∈ Φ := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap have : Module.IsReflexive R N := .of_isPerfPair P.flip.toLinearMap have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M by_cases hli : LinearIndependent R ![α i, α j] · -- The case where the two roots are linearly independent suffices P.pairingIn ℤ i j = 1 ∨ P.pairingIn ℤ j i = 1 by rcases this with h₁ | h₁ · replace h₁ : P.pairing i j = 1 := by simpa [← P.algebraMap_pairingIn ℤ] exact ⟨P.reflectionPerm j i, by simpa [h₁] using P.reflection_apply_root j i⟩ · replace h₁ : P.pairing j i = 1 := by simpa [← P.algebraMap_pairingIn ℤ] rw [← neg_mem_range_root_iff, neg_sub] exact ⟨P.reflectionPerm i j, by simpa [h₁] using P.reflection_apply_root i j⟩ have : P.coxeterWeightIn ℤ i j ∈ ({1, 2, 3} : Set _) := by have aux₁ := P.coxeterWeightIn_mem_set_of_isCrystallographic i j have aux₂ := (linearIndependent_iff_coxeterWeightIn_ne_four P ℤ).mp hli have aux₃ : P.coxeterWeightIn ℤ i j ≠ 0 := by simpa only [ne_eq, P.coxeterWeightIn_eq_zero_iff] using h.ne' simp_all simp_rw [coxeterWeightIn, Int.mul_mem_one_two_three_iff, mem_insert_iff, mem_singleton_iff, Prod.mk.injEq] at this cutsat · -- The case where the two roots are linearly dependent have : (P.pairingIn ℤ i j, P.pairingIn ℤ j i) ∈ ({(1, 4), (2, 2), (4, 1)} : Set _) := by have := P.pairingIn_pairingIn_mem_set_of_isCrystallographic i j replace hli : P.pairingIn ℤ i j * P.pairingIn ℤ j i = 4 := (P.coxeterWeightIn_eq_four_iff_not_linearIndependent ℤ).mpr hli aesop -- https://github.com/leanprover-community/mathlib4/issues/24551 (this should be faster) simp only [mem_insert_iff, mem_singleton_iff, Prod.mk.injEq] at this rcases this with hij | hij | hij · rw [(P.pairingIn_one_four_iff ℤ i j).mp hij, two_smul, sub_add_cancel_right] exact neg_root_mem P i · rw [P.pairingIn_two_two_iff] at hij contradiction · rw [and_comm] at hij simp [(P.pairingIn_one_four_iff ℤ j i).mp hij, two_smul] /-- If two roots make an obtuse angle then their sum is a root (provided it is not zero). See `RootPairing.pairingIn_le_zero_of_root_add_mem` for a partial converse. -/ lemma root_add_root_mem_of_pairingIn_neg (h : P.pairingIn ℤ i j < 0) (h' : α i ≠ -α j) : α i + α j ∈ Φ := by let _i := P.indexNeg replace h : 0 < P.pairingIn ℤ i (-j) := by simpa replace h' : i ≠ -j := by contrapose! h'; simp [h'] simpa using P.root_sub_root_mem_of_pairingIn_pos h h' lemma pairingIn_eq_zero_of_add_notMem_of_sub_notMem (hp : i ≠ j) (hn : α i ≠ -α j) (h_add : α i + α j ∉ Φ) (h_sub : α i - α j ∉ Φ) : P.pairingIn ℤ i j = 0 := by apply le_antisymm · contrapose! h_sub exact root_sub_root_mem_of_pairingIn_pos P h_sub hp · contrapose! h_add exact root_add_root_mem_of_pairingIn_neg P h_add hn lemma pairing_eq_zero_of_add_notMem_of_sub_notMem (hp : i ≠ j) (hn : α i ≠ -α j) (h_add : α i + α j ∉ Φ) (h_sub : α i - α j ∉ Φ) : P.pairing i j = 0 := by rw [← P.algebraMap_pairingIn ℤ, P.pairingIn_eq_zero_of_add_notMem_of_sub_notMem hp hn h_add h_sub, map_zero] omit [Finite ι] in lemma root_mem_submodule_iff_of_add_mem_invtSubmodule {K : Type*} [Field K] [NeZero (2 : K)] [Module K M] [Module K N] {P : RootPairing ι K M N} (q : P.invtRootSubmodule) (hij : P.root i + P.root j ∈ range P.root) : P.root i ∈ (q : Submodule K M) ↔ P.root j ∈ (q : Submodule K M) := by obtain ⟨q, hq⟩ := q rw [mem_invtRootSubmodule_iff] at hq suffices ∀ i j, P.root i + P.root j ∈ range P.root → P.root i ∈ q → P.root j ∈ q by have aux := this j i (by rwa [add_comm]); tauto rintro i j ⟨k, hk⟩ hi rcases eq_or_ne (P.pairing i j) 0 with hij₀ | hij₀ · have hik : P.pairing i k ≠ 0 := by rw [ne_eq, P.pairing_eq_zero_iff, ← root_coroot_eq_pairing, hk] simpa [P.pairing_eq_zero_iff.mp hij₀] using two_ne_zero suffices P.root k ∈ q from (q.add_mem_iff_right hi).mp <| hk ▸ this replace hq : P.root i - P.pairing i k • P.root k ∈ q := by simpa [reflection_apply_root] using hq k hi rwa [q.sub_mem_iff_right hi, q.smul_mem_iff hik] at hq · replace hq : P.root i - P.pairing i j • P.root j ∈ q := by simpa [reflection_apply_root] using hq j hi rwa [q.sub_mem_iff_right hi, q.smul_mem_iff hij₀] at hq namespace InvariantForm variable [P.IsReduced] (B : P.InvariantForm) variable {P} lemma apply_eq_or_aux (i j : ι) (h : P.pairingIn ℤ i j ≠ 0) : B.form (α i) (α i) = B.form (α j) (α j) ∨ B.form (α i) (α i) = 2 * B.form (α j) (α j) ∨ B.form (α i) (α i) = 3 * B.form (α j) (α j) ∨ B.form (α j) (α j) = 2 * B.form (α i) (α i) ∨ B.form (α j) (α j) = 3 * B.form (α i) (α i) := by have h₁ := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed i j have h₂ : algebraMap ℤ R (P.pairingIn ℤ j i) * B.form (α i) (α i) = algebraMap ℤ R (P.pairingIn ℤ i j) * B.form (α j) (α j) := by simpa only [algebraMap_pairingIn] using B.pairing_mul_eq_pairing_mul_swap i j aesop -- https://github.com/leanprover-community/mathlib4/issues/24551 (this should be faster) variable [P.IsIrreducible] /-- Relative of lengths of roots in a reduced irreducible finite crystallographic root pairing are very constrained. -/ lemma apply_eq_or (i j : ι) : B.form (α i) (α i) = B.form (α j) (α j) ∨ B.form (α i) (α i) = 2 * B.form (α j) (α j) ∨ B.form (α i) (α i) = 3 * B.form (α j) (α j) ∨ B.form (α j) (α j) = 2 * B.form (α i) (α i) ∨ B.form (α j) (α j) = 3 * B.form (α i) (α i) := by obtain ⟨j', h₁, h₂⟩ := P.exists_form_eq_form_and_form_ne_zero B i j suffices P.pairingIn ℤ i j' ≠ 0 by simp only [← h₁, B.apply_eq_or_aux i j' this] contrapose! h₂ replace h₂ : P.pairing i j' = 0 := by rw [← P.algebraMap_pairingIn ℤ, h₂, map_zero] exact (B.apply_root_root_zero_iff i j').mpr h₂ /-- A reduced irreducible finite crystallographic root system has roots of at most two different lengths. -/ lemma exists_apply_eq_or [Nonempty ι] : ∃ i j, ∀ k, B.form (α k) (α k) = B.form (α i) (α i) ∨ B.form (α k) (α k) = B.form (α j) (α j) := by obtain ⟨i⟩ := inferInstanceAs (Nonempty ι) by_cases! h : (∀ j, B.form (α j) (α j) = B.form (α i) (α i)) · refine ⟨i, i, fun j ↦ by simp [h j]⟩ · obtain ⟨j, hji_ne⟩ := h refine ⟨i, j, fun k ↦ ?_⟩ by_contra! hk obtain ⟨hki_ne, hkj_ne⟩ := hk have hij := (B.apply_eq_or i j).resolve_left hji_ne.symm have hik := (B.apply_eq_or i k).resolve_left hki_ne.symm have hjk := (B.apply_eq_or j k).resolve_left hkj_ne.symm grind lemma apply_eq_or_of_apply_ne (h : B.form (α i) (α i) ≠ B.form (α j) (α j)) (k : ι) : B.form (α k) (α k) = B.form (α i) (α i) ∨ B.form (α k) (α k) = B.form (α j) (α j) := by have : Nonempty ι := ⟨i⟩ obtain ⟨i', j', h'⟩ := B.exists_apply_eq_or rcases h' i with hi | hi <;> rcases h' j with hj | hj <;> specialize h' k <;> aesop end InvariantForm lemma forall_pairing_eq_swap_or [P.IsReduced] [P.IsIrreducible] : (∀ i j, P.pairing i j = P.pairing j i ∨ P.pairing i j = 2 * P.pairing j i ∨ P.pairing j i = 2 * P.pairing i j) ∨ (∀ i j, P.pairing i j = P.pairing j i ∨ P.pairing i j = 3 * P.pairing j i ∨ P.pairing j i = 3 * P.pairing i j) := by have : Fintype ι := Fintype.ofFinite ι have B := (P.posRootForm ℤ).toInvariantForm by_cases! h : ∀ i j, B.form (α i) (α i) = B.form (α j) (α j) · refine Or.inl fun i j ↦ Or.inl ?_ have := B.pairing_mul_eq_pairing_mul_swap j i rwa [h i j, mul_left_inj' (B.ne_zero j)] at this obtain ⟨i, j, hij⟩ := h have key := B.apply_eq_or_of_apply_ne hij set li := B.form (α i) (α i) set lj := B.form (α j) (α j) have : (li = 2 * lj ∨ lj = 2 * li) ∨ (li = 3 * lj ∨ lj = 3 * li) := by have := B.apply_eq_or i j; tauto rcases this with this | this · refine Or.inl fun k₁ k₂ ↦ ?_ have hk := B.pairing_mul_eq_pairing_mul_swap k₁ k₂ rcases this with h₀ | h₀ <;> rcases key k₁ with h₁ | h₁ <;> rcases key k₂ with h₂ | h₂ <;> simp only [h₁, h₂, h₀, ← mul_assoc, mul_comm, mul_eq_mul_right_iff] at hk <;> aesop -- https://github.com/leanprover-community/mathlib4/issues/24551 (this should be faster) · refine Or.inr fun k₁ k₂ ↦ ?_ have hk := B.pairing_mul_eq_pairing_mul_swap k₁ k₂ rcases this with h₀ | h₀ <;> rcases key k₁ with h₁ | h₁ <;> rcases key k₂ with h₂ | h₂ <;> simp only [h₁, h₂, h₀, ← mul_assoc, mul_comm, mul_eq_mul_right_iff] at hk <;> aesop -- https://github.com/leanprover-community/mathlib4/issues/24551 (this should be faster) lemma forall_pairingIn_eq_swap_or [P.IsReduced] [P.IsIrreducible] : (∀ i j, P.pairingIn ℤ i j = P.pairingIn ℤ j i ∨ P.pairingIn ℤ i j = 2 * P.pairingIn ℤ j i ∨ P.pairingIn ℤ j i = 2 * P.pairingIn ℤ i j) ∨ (∀ i j, P.pairingIn ℤ i j = P.pairingIn ℤ j i ∨ P.pairingIn ℤ i j = 3 * P.pairingIn ℤ j i ∨ P.pairingIn ℤ j i = 3 * P.pairingIn ℤ i j) := by simpa only [← P.algebraMap_pairingIn ℤ, eq_intCast, ← Int.cast_mul, Int.cast_inj, ← map_ofNat (algebraMap ℤ R)] using P.forall_pairing_eq_swap_or end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/Finite/Nondegenerate.lean
import Mathlib.LinearAlgebra.BilinearForm.Basic import Mathlib.LinearAlgebra.BilinearForm.Orthogonal import Mathlib.LinearAlgebra.Dimension.Localization import Mathlib.LinearAlgebra.QuadraticForm.Basic import Mathlib.LinearAlgebra.RootSystem.BaseChange import Mathlib.LinearAlgebra.RootSystem.Finite.CanonicalBilinear /-! # Nondegeneracy of the polarization on a finite root pairing We show that if the base ring of a finite root pairing is linearly ordered, then the canonical bilinear form is root-positive and positive-definite on the span of roots. From these facts, it is easy to show that Coxeter weights in a finite root pairing are bounded above by 4. Thus, the pairings of roots and coroots in a root pairing are restricted to the interval `[-4, 4]`. Furthermore, a linearly independent pair of roots cannot have Coxeter weight 4. For the case of crystallographic root pairings, we are thus reduced to a finite set of possible options for each pair. Another application is to the faithfulness of the Weyl group action on roots, and finiteness of the Weyl group. ## Main results: * `RootPairing.IsAnisotropic`: We say a finite root pairing is anisotropic if there are no roots / coroots which have length zero w.r.t. the root / coroot forms. * `RootPairing.rootForm_pos_of_nonzero`: `RootForm` is strictly positive on non-zero linear combinations of roots. This gives us a convenient way to eliminate certain Dynkin diagrams from the classification, since it suffices to produce a nonzero linear combination of simple roots with non-positive norm. * `RootPairing.rootForm_restrict_nondegenerate_of_ordered`: The root form is non-degenerate if the coefficients are ordered. * `RootPairing.rootForm_restrict_nondegenerate_of_isAnisotropic`: the root form is non-degenerate if the coefficients are a field and the pairing is crystallographic. ## References: * [N. Bourbaki, *Lie groups and Lie algebras. Chapters 4--6*][bourbaki1968] * [M. Demazure, *SGA III, Exposé XXI, Données Radicielles*][demazure1970] ## Todo * Weyl-invariance of `RootForm` and `CorootForm` * Faithfulness of Weyl group perm action, and finiteness of Weyl group, over ordered rings. * Relation to Coxeter weight. -/ noncomputable section open Set Function open Module hiding reflection open Submodule (span) namespace RootPairing variable {ι R M N : Type*} [Fintype ι] [AddCommGroup M] [AddCommGroup N] section CommRing variable [CommRing R] [Module R M] [Module R N] (P : RootPairing ι R M N) /-- We say a finite root pairing is anisotropic if there are no roots / coroots which have length zero w.r.t. the root / coroot forms. Examples include crystallographic pairings in characteristic zero `RootPairing.instIsAnisotropicOfIsCrystallographic` and pairings over ordered scalars. `RootPairing.instIsAnisotropicOfLinearOrderedCommRing`. -/ class IsAnisotropic : Prop where rootForm_root_ne_zero (i : ι) : P.RootForm (P.root i) (P.root i) ≠ 0 corootForm_coroot_ne_zero (i : ι) : P.CorootForm (P.coroot i) (P.coroot i) ≠ 0 instance [P.IsAnisotropic] : P.flip.IsAnisotropic where rootForm_root_ne_zero := IsAnisotropic.corootForm_coroot_ne_zero corootForm_coroot_ne_zero := IsAnisotropic.rootForm_root_ne_zero (P := P) lemma isAnisotropic_of_isValuedIn (S : Type*) [CommRing S] [LinearOrder S] [IsStrictOrderedRing S] [Algebra S R] [FaithfulSMul S R] [P.IsValuedIn S] : IsAnisotropic P where rootForm_root_ne_zero i := (P.posRootForm S).form_apply_root_ne_zero i corootForm_coroot_ne_zero i := (P.flip.posRootForm S).form_apply_root_ne_zero i instance instIsAnisotropicOfIsCrystallographic [CharZero R] [P.IsCrystallographic] : IsAnisotropic P := P.isAnisotropic_of_isValuedIn ℤ /-- The root form of an anisotropic pairing as an invariant form. -/ @[simps] def toInvariantForm [P.IsAnisotropic] : P.InvariantForm where form := P.RootForm symm := P.rootForm_symmetric ne_zero := IsAnisotropic.rootForm_root_ne_zero isOrthogonal_reflection := P.rootForm_reflection_reflection_apply lemma smul_coroot_eq_of_root_add_root_eq [P.IsAnisotropic] [NoZeroSMulDivisors R N] {i j k : ι} {m n : R} (hk : m • P.root i + n • P.root j = P.root k) : letI Q := (m * m) * P.pairing i j + (m * n) * (P.pairing i j * P.pairing j i) + (n * n) * P.pairing j i Q • P.coroot k = m • P.pairing i j • P.coroot i + n • P.pairing j i • P.coroot j := by let B := P.toInvariantForm let lsq (i) : R := B.form (P.root i) (P.root i) have hlsq (i : ι) : lsq i = P.RootForm (P.root i) (P.root i) := rfl have h₁ : lsq k • P.coroot k = (m • lsq i) • P.coroot i + (n • lsq j) • P.coroot j := by simp only [hlsq, smul_assoc, P.rootForm_self_smul_coroot, smul_comm _ 2] rw [← map_smul _ m, ← map_smul _ n, ← nsmul_add, ← map_add, hk] have h₂ : lsq k = (m * m) * lsq i + (m * n) * (2 * B.form (P.root i) (P.root j)) + (n * n) * lsq j := by have aux : P.RootForm (P.root j) (P.root i) = B.form (P.root i) (P.root j) := P.rootForm_symmetric.eq (P.root j) (P.root i) simp [hlsq, ← hk, aux, B] ring have h₃ : 2 * B.form (P.root i) (P.root j) = P.pairing i j * lsq j := B.two_mul_apply_root_root i j have h₄ : P.pairing j i * lsq i = P.pairing i j * lsq j := B.pairing_mul_eq_pairing_mul_swap i j replace h₁ : (m * m * (P.pairing j i * lsq i)) • P.coroot k + (m * n * (P.pairing j i * P.pairing i j * lsq j)) • P.coroot k + (n * n * (P.pairing j i * lsq j)) • P.coroot k = (m * (P.pairing j i * lsq i)) • P.coroot i + (n * (P.pairing j i * lsq j)) • P.coroot j := by rw [h₂, h₃] at h₁ replace h₁ := congr_arg (fun n ↦ P.pairing j i • n) h₁ simp only [add_smul, smul_add, ← mul_smul, smul_eq_mul] at h₁ convert h₁ using 1 · module · ring_nf simp only [h₄] at h₁ apply smul_right_injective _ (c := lsq j) (RootPairing.IsAnisotropic.rootForm_root_ne_zero j) simp only convert h₁ using 1 · module · module section DomainAlg variable (S : Type*) [CommRing S] [IsDomain R] [IsDomain S] [Algebra S R] [FaithfulSMul S R] [P.IsValuedIn S] [Module S M] [IsScalarTower S R M] [Module S N] [IsScalarTower S R N] lemma finrank_range_polarization_eq_finrank_span_coroot [P.IsAnisotropic] : finrank S (LinearMap.range (P.PolarizationIn S)) = finrank S (P.corootSpan S) := by apply (Submodule.finrank_mono (P.range_polarizationIn_le_span_coroot S)).antisymm have : IsReflexive R N := .of_isPerfPair P.flip.toLinearMap have : NoZeroSMulDivisors S N := NoZeroSMulDivisors.trans_faithfulSMul S R N have h_ne : ∏ i, (P.RootFormIn S (P.rootSpanMem S i) (P.rootSpanMem S i)) ≠ 0 := by refine Finset.prod_ne_zero_iff.mpr fun i _ h ↦ ?_ have := (FaithfulSMul.algebraMap_eq_zero_iff S R).mpr h rw [algebraMap_rootFormIn] at this apply IsAnisotropic.rootForm_root_ne_zero i this refine LinearMap.finrank_le_of_isSMulRegular (P.corootSpan S) (LinearMap.range (M₂ := N) (P.PolarizationIn S)) (smul_right_injective N h_ne) ?_ intro _ hx obtain ⟨c, hc⟩ := (Submodule.mem_span_range_iff_exists_fun S).mp hx rw [← hc, Finset.smul_sum] simp_rw [smul_smul, mul_comm, ← smul_smul] exact Submodule.sum_smul_mem (LinearMap.range (P.PolarizationIn S)) c fun j _ ↦ prod_rootFormIn_smul_coroot_mem_range_PolarizationIn P S j /-- An auxiliary lemma en route to `RootPairing.finrank_corootSpan_eq`. -/ private lemma finrank_corootSpan_le [P.IsAnisotropic] : finrank S (P.corootSpan S) ≤ finrank S (P.rootSpan S) := by rw [← finrank_range_polarization_eq_finrank_span_coroot] exact LinearMap.finrank_range_le (P.PolarizationIn S) lemma finrank_corootSpan_eq [P.IsAnisotropic] : finrank S (P.corootSpan S) = finrank S (P.rootSpan S) := le_antisymm (P.finrank_corootSpan_le S) (P.flip.finrank_corootSpan_le S) lemma polarizationIn_Injective [P.IsAnisotropic] : Function.Injective (P.PolarizationIn S) := by have : IsReflexive R M := .of_isPerfPair P.toLinearMap have : NoZeroSMulDivisors S M := NoZeroSMulDivisors.trans_faithfulSMul S R M rw [← LinearMap.ker_eq_bot, ← top_disjoint] refine Submodule.disjoint_ker_of_finrank_le (L := ⊤) (P.PolarizationIn S) ?_ rw [finrank_top, ← finrank_corootSpan_eq, ← finrank_range_polarization_eq_finrank_span_coroot] exact Submodule.finrank_mono <| le_of_eq <| LinearMap.range_eq_map (P.PolarizationIn S) lemma exists_coroot_ne [P.IsAnisotropic] {x : P.rootSpan S} (hx : x ≠ 0) : ∃ i, P.coroot'In S i x ≠ 0 := by have hI := P.polarizationIn_Injective S have h := (map_ne_zero_iff (P.PolarizationIn S) hI).mpr hx rw [PolarizationIn_apply] at h contrapose! h exact Fintype.sum_eq_zero (fun a ↦ (P.coroot'In S a) x • P.coroot a) fun i ↦ by simp [h i] end DomainAlg section LinearOrderedCommRingAlg variable (S : Type*) [CommRing S] [LinearOrder S] [IsStrictOrderedRing S] [IsDomain R] [Algebra S R] [FaithfulSMul S R] [P.IsValuedIn S] [Module S M] [IsScalarTower S R M] [Module S N] [IsScalarTower S R N] theorem posRootForm_posForm_pos_of_ne_zero {x : P.rootSpan S} (hx : x ≠ 0) : 0 < (P.posRootForm S).posForm x x := by rw [posRootForm_posForm_apply_apply] have := P.isAnisotropic_of_isValuedIn S have : ∃ i ∈ Finset.univ, 0 < (P.coroot'In S i) x * (P.coroot'In S i) x := by obtain ⟨i, hi⟩ := P.exists_coroot_ne S hx use i exact ⟨Finset.mem_univ i, mul_self_pos.mpr hi⟩ exact Finset.sum_pos' (fun i a ↦ mul_self_nonneg ((P.coroot'In S i) x)) this lemma posRootForm_posForm_anisotropic : (P.posRootForm S).posForm.toQuadraticMap.Anisotropic := fun _ hx ↦ Classical.byContradiction fun h ↦ (ne_of_lt (posRootForm_posForm_pos_of_ne_zero P S h)).symm hx lemma posRootForm_posForm_nondegenerate : (P.posRootForm S).posForm.Nondegenerate := by refine LinearMap.BilinForm.nondegenerate_iff_ker_eq_bot.mpr <| LinearMap.ker_eq_bot'.mpr ?_ intro x hx contrapose! hx rw [DFunLike.ne_iff] use x exact (posRootForm_posForm_pos_of_ne_zero P S hx).ne' end LinearOrderedCommRingAlg end CommRing section IsDomain variable [CommRing R] [IsDomain R] [Module R M] [Module R N] (P : RootPairing ι R M N) [P.IsAnisotropic] @[simp] lemma finrank_rootSpan_map_polarization_eq_finrank_corootSpan : finrank R ((P.rootSpan R).map P.Polarization) = finrank R (P.corootSpan R) := by rw [← P.finrank_range_polarization_eq_finrank_span_coroot R, range_polarizationIn] /-- An auxiliary lemma en route to `RootPairing.finrank_corootSpan_eq'`. -/ private lemma finrank_corootSpan_le' : finrank R (P.corootSpan R) ≤ finrank R (P.rootSpan R) := by rw [← finrank_rootSpan_map_polarization_eq_finrank_corootSpan] exact Submodule.finrank_map_le P.Polarization (P.rootSpan R) /-- Equality of `finrank`s when the base is a domain. -/ lemma finrank_corootSpan_eq' : finrank R (P.corootSpan R) = finrank R (P.rootSpan R) := le_antisymm P.finrank_corootSpan_le' P.flip.finrank_corootSpan_le' lemma disjoint_rootSpan_ker_rootForm : Disjoint (P.rootSpan R) (LinearMap.ker P.RootForm) := by have : IsReflexive R M := .of_isPerfPair P.toLinearMap rw [← P.ker_polarization_eq_ker_rootForm] refine Submodule.disjoint_ker_of_finrank_le (L := P.rootSpan R) P.Polarization ?_ rw [P.finrank_rootSpan_map_polarization_eq_finrank_corootSpan, P.finrank_corootSpan_eq'] lemma disjoint_corootSpan_ker_corootForm : Disjoint (P.corootSpan R) (LinearMap.ker P.CorootForm) := P.flip.disjoint_rootSpan_ker_rootForm lemma _root_.RootSystem.rootForm_nondegenerate (P : RootSystem ι R M N) [P.IsAnisotropic] : P.RootForm.Nondegenerate := LinearMap.BilinForm.nondegenerate_iff_ker_eq_bot.mpr <| by simpa using P.disjoint_rootSpan_ker_rootForm end IsDomain section Field variable [Field R] [Module R M] [Module R N] (P : RootPairing ι R M N) [P.IsAnisotropic] lemma isCompl_rootSpan_ker_rootForm : IsCompl (P.rootSpan R) (LinearMap.ker P.RootForm) := by have : IsReflexive R M := .of_isPerfPair P.toLinearMap have : IsReflexive R N := .of_isPerfPair P.flip.toLinearMap refine (Submodule.isCompl_iff_disjoint _ _ ?_).mpr P.disjoint_rootSpan_ker_rootForm have aux : finrank R M = finrank R (P.rootSpan R) + finrank R (P.corootSpan R).dualAnnihilator := by rw [P.toPerfPair.finrank_eq, ← P.finrank_corootSpan_eq', Subspace.finrank_add_finrank_dualAnnihilator_eq (P.corootSpan R), Subspace.dual_finrank_eq] rw [aux, add_le_add_iff_left] convert Submodule.finrank_mono P.corootSpan_dualAnnihilator_le_ker_rootForm exact (LinearEquiv.finrank_map_eq _ _).symm lemma isCompl_corootSpan_ker_corootForm : IsCompl (P.corootSpan R) (LinearMap.ker P.CorootForm) := P.flip.isCompl_rootSpan_ker_rootForm lemma ker_rootForm_eq_dualAnnihilator : LinearMap.ker P.RootForm = (P.corootSpan R).dualAnnihilator.map P.toPerfPair.symm := by have : IsReflexive R M := .of_isPerfPair P.toLinearMap have : IsReflexive R N := .of_isPerfPair P.flip.toLinearMap suffices finrank R (LinearMap.ker P.RootForm) = finrank R (P.corootSpan R).dualAnnihilator by refine (Submodule.eq_of_le_of_finrank_eq P.corootSpan_dualAnnihilator_le_ker_rootForm ?_).symm rw [this] apply LinearEquiv.finrank_map_eq have aux0 := Subspace.finrank_add_finrank_dualAnnihilator_eq (P.corootSpan R) have aux1 := Submodule.finrank_add_eq_of_isCompl P.isCompl_rootSpan_ker_rootForm rw [← P.finrank_corootSpan_eq', P.toPerfPair.finrank_eq, Subspace.dual_finrank_eq] at aux1 omega lemma ker_corootForm_eq_dualAnnihilator : LinearMap.ker P.CorootForm = (P.rootSpan R).dualAnnihilator.map P.flip.toPerfPair.symm := P.flip.ker_rootForm_eq_dualAnnihilator instance : P.IsBalanced where isPerfectCompl := { isCompl_left := by simpa only [ker_rootForm_eq_dualAnnihilator] using P.isCompl_rootSpan_ker_rootForm isCompl_right := by simpa only [ker_corootForm_eq_dualAnnihilator] using P.isCompl_corootSpan_ker_corootForm } /-- See also `RootPairing.rootForm_restrict_nondegenerate_of_ordered`. Note that this applies to crystallographic root systems in characteristic zero via `RootPairing.instIsAnisotropicOfIsCrystallographic`. -/ lemma rootForm_restrict_nondegenerate_of_isAnisotropic : LinearMap.Nondegenerate (P.RootForm.restrict (P.rootSpan R)) := P.rootForm_symmetric.nondegenerate_restrict_of_isCompl_ker P.isCompl_rootSpan_ker_rootForm @[simp] lemma orthogonal_rootSpan_eq : P.RootForm.orthogonal (P.rootSpan R) = LinearMap.ker P.RootForm := by rw [← LinearMap.BilinForm.orthogonal_top_eq_ker P.rootForm_symmetric.isRefl] refine le_antisymm ?_ (by intro; simp_all) rintro x hx y - simp only [LinearMap.BilinForm.mem_orthogonal_iff, LinearMap.BilinForm.IsOrtho] at hx ⊢ obtain ⟨u, hu, v, hv, rfl⟩ : ∃ᵉ (u ∈ P.rootSpan R) (v ∈ LinearMap.ker P.RootForm), u + v = y := by rw [← Submodule.mem_sup, P.isCompl_rootSpan_ker_rootForm.sup_eq_top]; exact Submodule.mem_top simp only [LinearMap.mem_ker] at hv simp [hx _ hu, hv] @[simp] lemma orthogonal_corootSpan_eq : P.CorootForm.orthogonal (P.corootSpan R) = LinearMap.ker P.CorootForm := P.flip.orthogonal_rootSpan_eq lemma rootSpan_eq_top_iff : P.rootSpan R = ⊤ ↔ P.corootSpan R = ⊤ := by have : IsReflexive R M := .of_isPerfPair P.toLinearMap have : IsReflexive R N := .of_isPerfPair P.flip.toLinearMap refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ <;> apply Submodule.eq_top_of_finrank_eq · rw [P.finrank_corootSpan_eq', h, finrank_top, P.toPerfPair.finrank_eq, Subspace.dual_finrank_eq] · rw [← P.finrank_corootSpan_eq', h, finrank_top, P.toPerfPair.finrank_eq, Subspace.dual_finrank_eq] end Field section LinearOrderedCommRing variable [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] [Module R M] [Module R N] (P : RootPairing ι R M N) instance instIsAnisotropicOfLinearOrderedCommRing : IsAnisotropic P := P.isAnisotropic_of_isValuedIn R lemma zero_le_rootForm (x : M) : 0 ≤ P.RootForm x x := (P.rootForm_self_sum_of_squares x).nonneg /-- See also `RootPairing.rootForm_restrict_nondegenerate_of_isAnisotropic`. -/ lemma rootForm_restrict_nondegenerate_of_ordered : LinearMap.Nondegenerate (P.RootForm.restrict (P.rootSpan R)) := (P.RootForm.nondegenerate_restrict_iff_disjoint_ker P.zero_le_rootForm P.rootForm_symmetric).mpr P.disjoint_rootSpan_ker_rootForm lemma rootForm_self_eq_zero_iff {x : M} : P.RootForm x x = 0 ↔ x ∈ LinearMap.ker P.RootForm := P.RootForm.apply_apply_same_eq_zero_iff P.zero_le_rootForm P.rootForm_symmetric lemma eq_zero_of_mem_rootSpan_of_rootForm_self_eq_zero {x : M} (hx : x ∈ P.rootSpan R) (hx' : P.RootForm x x = 0) : x = 0 := by have : x ∈ P.rootSpan R ⊓ LinearMap.ker P.RootForm := ⟨hx, P.rootForm_self_eq_zero_iff.mp hx'⟩ simpa [P.disjoint_rootSpan_ker_rootForm.eq_bot] using this lemma rootForm_pos_of_ne_zero {x : M} (hx : x ∈ P.rootSpan R) (h : x ≠ 0) : 0 < P.RootForm x x := by apply (P.zero_le_rootForm x).lt_of_ne contrapose! h exact P.eq_zero_of_mem_rootSpan_of_rootForm_self_eq_zero hx h.symm lemma _root_.RootSystem.rootForm_anisotropic (P : RootSystem ι R M N) : P.RootForm.toQuadraticMap.Anisotropic := fun x ↦ P.eq_zero_of_mem_rootSpan_of_rootForm_self_eq_zero <| by simpa only [rootSpan, P.span_root_eq_top] using Submodule.mem_top end LinearOrderedCommRing end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/Finite/G2.lean
import Mathlib.LinearAlgebra.RootSystem.Base import Mathlib.LinearAlgebra.RootSystem.Chain import Mathlib.LinearAlgebra.RootSystem.Finite.Lemmas /-! # Properties of the `𝔤₂` root system. The `𝔤₂` root pairing is special enough to deserve its own API. We provide one in this file. As an application we prove the key result that a crystallographic, reduced, irreducible root pairing containing two roots of Coxeter weight three is spanned by this pair of roots (and thus is two-dimensional). This result is usually proved only for pairs of roots belonging to a base (as a corollary of the fact that no node can have degree greater than three) and moreover usually requires stronger assumptions on the coefficients than here. ## Main results: * `RootPairing.EmbeddedG2`: a data-bearing typeclass which distinguishes a pair of roots whose pairing is `-3` (equivalently, with a distinguished choice of base). This is a sufficient condition for the span of this pair of roots to be a `𝔤₂` root system. * `RootPairing.IsG2`: a prop-valued typeclass characterising the `𝔤₂` root system. * `RootPairing.IsNotG2`: a prop-valued typeclass stating that a crystallographic, reduced, irreducible root system is not `𝔤₂`. * `RootPairing.EmbeddedG2.shortRoot`: the distinguished short root, which we often donate `α` * `RootPairing.EmbeddedG2.longRoot`: the distinguished long root, which we often donate `β` * `RootPairing.EmbeddedG2.shortAddLong`: the short root `α + β` * `RootPairing.EmbeddedG2.twoShortAddLong`: the short root `2α + β` * `RootPairing.EmbeddedG2.threeShortAddLong`: the long root `3α + β` * `RootPairing.EmbeddedG2.threeShortAddTwoLong`: the long root `3α + 2β` * `RootPairing.EmbeddedG2.span_eq_top`: a crystallographic reduced irreducible root pairing containing two roots with pairing `-3` is spanned by this pair (thus two-dimensional). * `RootPairing.EmbeddedG2.card_index_eq_twelve`: the `𝔤₂`root pairing has twelve roots. ## TODO Once sufficient API for `RootPairing.Base` has been developed: * Add `def EmbeddedG2.toBase [P.EmbeddedG2] : P.Base` with `support := {long P, short P}` * Given `P` satisfying `[P.IsG2]`, distinct elements of a base must pair to `-3` (in one order). -/ noncomputable section open FaithfulSMul Function Set Submodule open List hiding mem_toFinset variable {ι R M N : Type*} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] (P : RootPairing ι R M N) namespace RootPairing /-- A data-bearing typeclass which distinguishes a pair of roots whose pairing is `-3`. This is a sufficient condition for the span of this pair of roots to be a `𝔤₂` root system. -/ class EmbeddedG2 extends P.IsCrystallographic, P.IsReduced where /-- The distinguished long root of an embedded `𝔤₂` root pairing. -/ long : ι /-- The distinguished short root of an embedded `𝔤₂` root pairing. -/ short : ι pairingIn_long_short : P.pairingIn ℤ long short = -3 /-- A prop-valued typeclass characterising the `𝔤₂` root system. -/ class IsG2 : Prop extends P.IsCrystallographic, P.IsReduced, P.IsIrreducible where exists_pairingIn_neg_three : ∃ i j, P.pairingIn ℤ i j = -3 /-- A prop-valued typeclass stating that a crystallographic, reduced, irreducible root system is not `𝔤₂`. -/ class IsNotG2 : Prop extends P.IsCrystallographic, P.IsReduced, P.IsIrreducible where pairingIn_mem_zero_one_two (i j : ι) : P.pairingIn ℤ i j ∈ ({-2, -1, 0, 1, 2} : Set ℤ) section IsG2 /-- By making an arbitrary choice of roots pairing to `-3`, we can obtain an embedded `𝔤₂` root system just from the knowledge that such a pairs exists. -/ def IsG2.toEmbeddedG2 [P.IsG2] : P.EmbeddedG2 where long := (IsG2.exists_pairingIn_neg_three (P := P)).choose short := (IsG2.exists_pairingIn_neg_three (P := P)).choose_spec.choose pairingIn_long_short := (IsG2.exists_pairingIn_neg_three (P := P)).choose_spec.choose_spec lemma IsG2.nonempty [P.IsG2] : Nonempty ι := ⟨(IsG2.exists_pairingIn_neg_three (P := P)).choose⟩ variable [P.IsCrystallographic] [P.IsReduced] [P.IsIrreducible] lemma isG2_iff : P.IsG2 ↔ ∃ i j, P.pairingIn ℤ i j = -3 := ⟨fun _ ↦ IsG2.exists_pairingIn_neg_three, fun h ↦ ⟨h⟩⟩ lemma isNotG2_iff : P.IsNotG2 ↔ ∀ i j, P.pairingIn ℤ i j ∈ ({-2, -1, 0, 1, 2} : Set ℤ) := ⟨fun _ ↦ IsNotG2.pairingIn_mem_zero_one_two, fun h ↦ ⟨h⟩⟩ variable [Finite ι] [CharZero R] [IsDomain R] @[simp] lemma not_isG2_iff_isNotG2 : ¬ P.IsG2 ↔ P.IsNotG2 := by simp only [isG2_iff, isNotG2_iff, not_exists, Set.mem_insert_iff, mem_singleton_iff] refine ⟨fun h i j ↦ ?_, fun h i j ↦ ?_⟩ · have hij := h (P.reflectionPerm i i) j have := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed i j aesop · specialize h i j cutsat lemma IsG2.pairingIn_mem_zero_one_three [P.IsG2] (i j : ι) (h : P.root i ≠ P.root j) (h' : P.root i ≠ -P.root j) : P.pairingIn ℤ i j ∈ ({-3, -1, 0, 1, 3} : Set ℤ) := by suffices ¬ (∀ i j, P.pairingIn ℤ i j = P.pairingIn ℤ j i ∨ P.pairingIn ℤ i j = 2 * P.pairingIn ℤ j i ∨ P.pairingIn ℤ j i = 2 * P.pairingIn ℤ i j) by have aux₁ := P.forall_pairingIn_eq_swap_or.resolve_left this i j have aux₂ := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed' i j h h' simp only [mem_insert_iff, mem_singleton_iff, Prod.mk_zero_zero, Prod.mk_eq_zero, Prod.mk_one_one, Prod.mk_eq_one, Prod.mk.injEq] at aux₂ ⊢ cutsat obtain ⟨k, l, hkl⟩ := exists_pairingIn_neg_three (P := P) push_neg refine ⟨k, l, ?_⟩ have aux := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed k l simp only [mem_insert_iff, mem_singleton_iff, Prod.mk_zero_zero, Prod.mk_eq_zero, Prod.mk_one_one, Prod.mk_eq_one, Prod.mk.injEq] at aux omega end IsG2 section IsNotG2 variable {P} variable [Finite ι] [CharZero R] [IsDomain R] {i j : ι} variable (i j) in lemma chainBotCoeff_add_chainTopCoeff_le_two [P.IsNotG2] : P.chainBotCoeff i j + P.chainTopCoeff i j ≤ 2 := by by_cases h : LinearIndependent R ![P.root i, P.root j] swap; · simp [chainTopCoeff_of_not_linearIndependent, chainBotCoeff_of_not_linearIndependent, h] rw [← Int.ofNat_le, Nat.cast_add, Nat.cast_ofNat, chainBotCoeff_add_chainTopCoeff_eq_pairingIn_chainTopIdx h] have := IsNotG2.pairingIn_mem_zero_one_two (P := P) (P.chainTopIdx i j) i aesop /-- For a reduced, crystallographic, irreducible root pairing other than `𝔤₂`, if the sum of two roots is a root, they cannot make an acute angle. To see that this lemma fails for `𝔤₂`, let `α` (short) and `β` (long) be a base. Then the roots `α + β` and `2α + β` make an angle `π / 3` even though `3α + 2β` is a root. We can even witness as: ```lean example (P : RootPairing ι R M N) [P.EmbeddedG2] : P.pairingIn ℤ (EmbeddedG2.shortAddLong P) (EmbeddedG2.twoShortAddLong P) = 1 := by simp ``` -/ lemma pairingIn_le_zero_of_root_add_mem [P.IsNotG2] (h : P.root i + P.root j ∈ range P.root) : P.pairingIn ℤ i j ≤ 0 := by have aux₁ := P.linearIndependent_of_add_mem_range_root' <| add_comm (P.root i) (P.root j) ▸ h have aux₂ := P.chainBotCoeff_add_chainTopCoeff_le_two j i have aux₃ : 1 ≤ P.chainTopCoeff j i := by rwa [← root_add_nsmul_mem_range_iff_le_chainTopCoeff aux₁, one_smul] rw [← P.chainBotCoeff_sub_chainTopCoeff aux₁] cutsat lemma zero_le_pairingIn_of_root_sub_mem [P.IsNotG2] (h : P.root i - P.root j ∈ range P.root) : 0 ≤ P.pairingIn ℤ i j := by replace h : P.root i + P.root (P.reflectionPerm j j) ∈ range P.root := by simpa [← sub_eq_add_neg] simpa using P.pairingIn_le_zero_of_root_add_mem h /-- For a reduced, crystallographic, irreducible root pairing other than `𝔤₂`, if the sum of two roots is a root, the bottom chain coefficient is either one or zero according to whether they are perpendicular. To see that this lemma fails for `𝔤₂`, let `α` (short) and `β` (long) be a base. Then the roots `α` and `α + β` provide a counterexample. -/ lemma chainBotCoeff_if_one_zero [P.IsNotG2] (h : P.root i + P.root j ∈ range P.root) : P.chainBotCoeff i j = if P.pairingIn ℤ i j = 0 then 1 else 0 := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap have aux₁ := P.linearIndependent_of_add_mem_range_root' h have aux₂ := P.chainBotCoeff_add_chainTopCoeff_le_two i j have aux₃ : 1 ≤ P.chainTopCoeff i j := P.one_le_chainTopCoeff_of_root_add_mem h rcases eq_or_ne (P.chainBotCoeff i j) (P.chainTopCoeff i j) with aux₄ | aux₄ <;> simp_rw [P.pairingIn_eq_zero_iff (i := i) (j := j), ← P.chainBotCoeff_sub_chainTopCoeff aux₁, sub_eq_zero, Nat.cast_inj, aux₄, reduceIte] <;> omega lemma chainTopCoeff_if_one_zero [P.IsNotG2] (h : P.root i - P.root j ∈ range P.root) : P.chainTopCoeff i j = if P.pairingIn ℤ i j = 0 then 1 else 0 := by letI := P.indexNeg replace h : P.root i + P.root (-j) ∈ range P.root := by simpa [← sub_eq_add_neg] using h simpa using P.chainBotCoeff_if_one_zero h end IsNotG2 namespace EmbeddedG2 /-- A pair of roots which pair to `+3` are also sufficient to distinguish an embedded `𝔤₂`. -/ @[simps] def ofPairingInThree [CharZero R] [P.IsCrystallographic] [P.IsReduced] (long short : ι) (h : P.pairingIn ℤ long short = 3) : P.EmbeddedG2 where long := P.reflectionPerm long long short := short pairingIn_long_short := by simp [h] variable [P.EmbeddedG2] attribute [simp] pairingIn_long_short instance [P.IsIrreducible] : P.IsG2 where exists_pairingIn_neg_three := ⟨long P, short P, by simp⟩ @[simp] lemma pairing_long_short : P.pairing (long P) (short P) = -3 := by rw [← P.algebraMap_pairingIn ℤ, pairingIn_long_short] simp /-- The index of the root `α + β` where `α` is the short root and `β` is the long root. -/ def shortAddLong : ι := P.reflectionPerm (long P) (short P) /-- The index of the root `2α + β` where `α` is the short root and `β` is the long root. -/ def twoShortAddLong : ι := P.reflectionPerm (short P) <| P.reflectionPerm (long P) (short P) /-- The index of the root `3α + β` where `α` is the short root and `β` is the long root. -/ def threeShortAddLong : ι := P.reflectionPerm (short P) (long P) /-- The index of the root `3α + 2β` where `α` is the short root and `β` is the long root. -/ def threeShortAddTwoLong : ι := P.reflectionPerm (long P) <| P.reflectionPerm (short P) (long P) /-- The short root `α`. -/ abbrev shortRoot := P.root (short P) /-- The long root `β`. -/ abbrev longRoot := P.root (long P) /-- The short root `α + β`. -/ abbrev shortAddLongRoot : M := P.root (shortAddLong P) /-- The short root `2α + β`. -/ abbrev twoShortAddLongRoot : M := P.root (twoShortAddLong P) /-- The short root `3α + β`. -/ abbrev threeShortAddLongRoot : M := P.root (threeShortAddLong P) /-- The short root `3α + 2β`. -/ abbrev threeShortAddTwoLongRoot : M := P.root (threeShortAddTwoLong P) /-- The list of all 12 roots belonging to the embedded `𝔤₂`. -/ abbrev allRoots : List M := [ longRoot P, -longRoot P, shortRoot P, -shortRoot P, shortAddLongRoot P, -shortAddLongRoot P, twoShortAddLongRoot P, -twoShortAddLongRoot P, threeShortAddLongRoot P, -threeShortAddLongRoot P, threeShortAddTwoLongRoot P, -threeShortAddTwoLongRoot P ] lemma allRoots_subset_range_root [DecidableEq M] : ↑(allRoots P).toFinset ⊆ range P.root := by intro x hx simp only [toFinset_cons, toFinset_nil, insert_empty_eq, Finset.coe_insert, Finset.coe_singleton, mem_insert_iff, mem_singleton_iff] at hx rcases hx with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> simp variable [Finite ι] [CharZero R] [IsDomain R] @[simp] lemma pairingIn_short_long : P.pairingIn ℤ (short P) (long P) = -1 := by have := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed (long P) (short P) aesop @[simp] lemma pairing_short_long : P.pairing (short P) (long P) = -1 := by rw [← P.algebraMap_pairingIn ℤ, pairingIn_short_long] simp lemma shortAddLongRoot_eq : shortAddLongRoot P = shortRoot P + longRoot P := by simp [shortAddLongRoot, shortAddLong, reflection_apply_root] lemma twoShortAddLongRoot_eq : twoShortAddLongRoot P = (2 : R) • shortRoot P + longRoot P := by simp [twoShortAddLongRoot, twoShortAddLong, reflection_apply_root] module omit [Finite ι] [CharZero R] [IsDomain R] in lemma threeShortAddLongRoot_eq : threeShortAddLongRoot P = (3 : R) • shortRoot P + longRoot P := by simp [threeShortAddLongRoot, threeShortAddLong, reflection_apply_root] module lemma threeShortAddTwoLongRoot_eq : threeShortAddTwoLongRoot P = (3 : R) • shortRoot P + (2 : R) • longRoot P := by simp [threeShortAddTwoLongRoot, threeShortAddTwoLong, reflection_apply_root] module lemma linearIndependent_short_long : LinearIndependent R ![shortRoot P, longRoot P] := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap simp [P.linearIndependent_iff_coxeterWeightIn_ne_four ℤ, coxeterWeightIn] /-- The coefficients of each root in the `𝔤₂` root pairing, relative to the base. -/ abbrev allCoeffs : List (Fin 2 → ℤ) := [![0, 1], ![0, -1], ![1, 0], ![-1, 0], ![1, 1], ![-1, -1], ![2, 1], ![-2, -1], ![3, 1], ![-3, -1], ![3, 2], ![-3, -2]] lemma allRoots_eq_map_allCoeffs : allRoots P = allCoeffs.map (Fintype.linearCombination ℤ ![shortRoot P, longRoot P]) := by simp [Fintype.linearCombination_apply, neg_add, -neg_add_rev, shortAddLongRoot_eq, twoShortAddLongRoot_eq, threeShortAddLongRoot_eq, threeShortAddTwoLongRoot_eq, ← Int.cast_smul_eq_zsmul R] lemma allRoots_nodup : (allRoots P).Nodup := by have hli : Injective (Fintype.linearCombination ℤ ![shortRoot P, longRoot P]) := by rw [← linearIndependent_iff_injective_fintypeLinearCombination] exact (linearIndependent_short_long P).restrict_scalars' ℤ rw [allRoots_eq_map_allCoeffs, nodup_map_iff hli] decide lemma mem_span_of_mem_allRoots {x : M} (hx : x ∈ allRoots P) : x ∈ span ℤ {longRoot P, shortRoot P} := by have : {longRoot P, shortRoot P} = range ![shortRoot P, longRoot P] := by simp simp_rw [this, Submodule.mem_span_range_iff_exists_fun, ← Fintype.linearCombination_apply] simp [allRoots_eq_map_allCoeffs] at hx tauto section InvariantForm variable {P} variable (B : P.InvariantForm) lemma long_eq_three_mul_short : B.form (longRoot P) (longRoot P) = 3 * B.form (shortRoot P) (shortRoot P) := by simpa using B.pairing_mul_eq_pairing_mul_swap (long P) (short P) omit [Finite ι] [CharZero R] [IsDomain R] /-- `α + β` is short. -/ @[simp] lemma shortAddLongRoot_shortRoot : B.form (shortAddLongRoot P) (shortAddLongRoot P) = B.form (shortRoot P) (shortRoot P) := by simp [shortAddLongRoot, shortAddLong] /-- `2α + β` is short. -/ @[simp] lemma twoShortAddLongRoot_shortRoot : B.form (twoShortAddLongRoot P) (twoShortAddLongRoot P) = B.form (shortRoot P) (shortRoot P) := by simp [twoShortAddLongRoot, twoShortAddLong] /-- `3α + β` is long. -/ @[simp] lemma threeShortAddLongRoot_longRoot : B.form (threeShortAddLongRoot P) (threeShortAddLongRoot P) = B.form (longRoot P) (longRoot P) := by simp [threeShortAddLongRoot, threeShortAddLong] /-- `3α + 2β` is long. -/ @[simp] lemma threeShortAddTwoLongRoot_longRoot : B.form (threeShortAddTwoLongRoot P) (threeShortAddTwoLongRoot P) = B.form (longRoot P) (longRoot P) := by simp [threeShortAddTwoLongRoot, threeShortAddTwoLong] end InvariantForm section Pairing variable (i : ι) @[simp] lemma pairingIn_shortAddLong_left : P.pairingIn ℤ (shortAddLong P) i = P.pairingIn ℤ (short P) i + P.pairingIn ℤ (long P) i := by rw [pairingIn_eq_add_of_root_eq_add (shortAddLongRoot_eq P)] @[simp] lemma pairingIn_shortAddLong_right : P.pairingIn ℤ i (shortAddLong P) = P.pairingIn ℤ i (short P) + 3 * P.pairingIn ℤ i (long P) := by suffices P.pairing i (shortAddLong P) = P.pairing i (short P) + 3 * P.pairing i (long P) from algebraMap_injective ℤ R <| by simpa only [algebraMap_pairingIn, map_add, map_mul, map_ofNat] have : Fintype ι := Fintype.ofFinite ι have B := (P.posRootForm ℤ).toInvariantForm apply mul_right_cancel₀ (B.ne_zero (shortAddLong P)) calc P.pairing i (shortAddLong P) * B.form (P.root (shortAddLong P)) (P.root (shortAddLong P)) _ = 2 * B.form (P.root i) (shortAddLongRoot P) := ?_ _ = 2 * B.form (P.root i) (shortRoot P) + 2 * B.form (P.root i) (longRoot P) := ?_ _ = P.pairing i (short P) * B.form (shortRoot P) (shortRoot P) + P.pairing i (long P) * B.form (longRoot P) (longRoot P) := ?_ _ = (P.pairing i (short P) + 3 * P.pairing i (long P)) * B.form (shortAddLongRoot P) (shortAddLongRoot P) := ?_ · rw [B.two_mul_apply_root_root] · rw [shortAddLongRoot_eq, map_add, mul_add] · rw [B.two_mul_apply_root_root, B.two_mul_apply_root_root] · rw [long_eq_three_mul_short, shortAddLongRoot_shortRoot]; ring @[simp] lemma pairingIn_twoShortAddLong_left : P.pairingIn ℤ (twoShortAddLong P) i = 2 * P.pairingIn ℤ (short P) i + P.pairingIn ℤ (long P) i := by rw [pairingIn_eq_add_of_root_eq_smul_add_smul (x := 2) (y := 1) (i := short P) (l := long P)] · simp · simp only [twoShortAddLongRoot_eq, one_smul, add_left_inj] norm_cast @[simp] lemma pairingIn_twoShortAddLong_right : P.pairingIn ℤ i (twoShortAddLong P) = 2 * P.pairingIn ℤ i (short P) + 3 * P.pairingIn ℤ i (long P) := by suffices P.pairing i (twoShortAddLong P) = 2 * P.pairing i (short P) + 3 * P.pairing i (long P) from algebraMap_injective ℤ R <| by simpa only [algebraMap_pairingIn, map_add, map_mul, map_ofNat] have : Fintype ι := Fintype.ofFinite ι have B := (P.posRootForm ℤ).toInvariantForm apply mul_right_cancel₀ (B.ne_zero <| twoShortAddLong P) calc P.pairing i (twoShortAddLong P) * B.form (twoShortAddLongRoot P) (twoShortAddLongRoot P) _ = 2 * B.form (P.root i) (twoShortAddLongRoot P) := ?_ _ = 2 * (2 * B.form (P.root i) (shortRoot P)) + 2 * B.form (P.root i) (longRoot P) := ?_ _ = 2 * P.pairing i (short P) * B.form (shortRoot P) (shortRoot P) + P.pairing i (long P) * B.form (longRoot P) (longRoot P) := ?_ _ = (2 * P.pairing i (short P) + 3 * P.pairing i (long P)) * B.form (twoShortAddLongRoot P) (twoShortAddLongRoot P) := ?_ · rw [B.two_mul_apply_root_root] · rw [twoShortAddLongRoot_eq, map_add, mul_add, map_smul, smul_eq_mul] · rw [B.two_mul_apply_root_root, B.two_mul_apply_root_root, mul_assoc] · rw [long_eq_three_mul_short, twoShortAddLongRoot_shortRoot]; ring omit [Finite ι] [IsDomain R] in @[simp] lemma pairingIn_threeShortAddLong_left : P.pairingIn ℤ (threeShortAddLong P) i = 3 * P.pairingIn ℤ (short P) i + P.pairingIn ℤ (long P) i := by rw [pairingIn_eq_add_of_root_eq_smul_add_smul (x := 3) (y := 1) (i := short P) (l := long P)] · simp · simp only [threeShortAddLongRoot_eq, one_smul, add_left_inj] norm_cast @[simp] lemma pairingIn_threeShortAddLong_right : P.pairingIn ℤ i (threeShortAddLong P) = P.pairingIn ℤ i (short P) + P.pairingIn ℤ i (long P) := by suffices P.pairing i (threeShortAddLong P) = P.pairing i (short P) + P.pairing i (long P) from algebraMap_injective ℤ R <| by simpa only [algebraMap_pairingIn, map_add, map_mul, map_ofNat] have : Fintype ι := Fintype.ofFinite ι have B := (P.posRootForm ℤ).toInvariantForm apply mul_right_cancel₀ (B.ne_zero <| threeShortAddLong P) calc P.pairing i (threeShortAddLong P) * B.form (threeShortAddLongRoot P) (threeShortAddLongRoot P) _ = 2 * B.form (P.root i) (threeShortAddLongRoot P) := ?_ _ = 3 * (2 * B.form (P.root i) (shortRoot P)) + 2 * B.form (P.root i) (longRoot P) := ?_ _ = P.pairing i (short P) * B.form (longRoot P) (longRoot P) + P.pairing i (long P) * B.form (longRoot P) (longRoot P) := ?_ _ = (P.pairing i (short P) + P.pairing i (long P)) * B.form (threeShortAddLongRoot P) (threeShortAddLongRoot P) := ?_ · rw [B.two_mul_apply_root_root] · rw [threeShortAddLongRoot_eq, map_add, mul_add, map_smul, smul_eq_mul]; ring · rw [B.two_mul_apply_root_root, B.two_mul_apply_root_root, long_eq_three_mul_short]; ring · rw [threeShortAddLongRoot_longRoot]; ring @[simp] lemma pairingIn_threeShortAddTwoLong_left : P.pairingIn ℤ (threeShortAddTwoLong P) i = 3 * P.pairingIn ℤ (short P) i + 2 * P.pairingIn ℤ (long P) i := by rw [pairingIn_eq_add_of_root_eq_smul_add_smul (x := 3) (y := 2) (i := short P) (l := long P)] · simp · simp only [threeShortAddTwoLongRoot_eq] norm_cast @[simp] lemma pairingIn_threeShortAddTwoLong_right : P.pairingIn ℤ i (threeShortAddTwoLong P) = P.pairingIn ℤ i (short P) + 2 * P.pairingIn ℤ i (long P) := by suffices P.pairing i (threeShortAddTwoLong P) = P.pairing i (short P) + 2 * P.pairing i (long P) from algebraMap_injective ℤ R <| by simpa only [algebraMap_pairingIn, map_add, map_mul, map_ofNat] have : Fintype ι := Fintype.ofFinite ι have B := (P.posRootForm ℤ).toInvariantForm apply mul_right_cancel₀ (B.ne_zero <| threeShortAddTwoLong P) calc P.pairing i (threeShortAddTwoLong P) * B.form (threeShortAddTwoLongRoot P) (threeShortAddTwoLongRoot P) _ = 2 * B.form (P.root i) (threeShortAddTwoLongRoot P) := ?_ _ = 3 * (2 * B.form (P.root i) (shortRoot P)) + 2 * (2 * B.form (P.root i) (longRoot P)) := ?_ _ = P.pairing i (short P) * B.form (longRoot P) (longRoot P) + 2 * P.pairing i (long P) * B.form (longRoot P) (longRoot P) := ?_ _ = (P.pairing i (short P) + 2 * P.pairing i (long P)) * B.form (threeShortAddTwoLongRoot P) (threeShortAddTwoLongRoot P) := ?_ · rw [B.two_mul_apply_root_root] · simp only [threeShortAddTwoLongRoot_eq, map_add, mul_add, map_smul, smul_eq_mul]; ring · rw [B.two_mul_apply_root_root, B.two_mul_apply_root_root, long_eq_three_mul_short]; ring · rw [threeShortAddTwoLongRoot_longRoot]; ring end Pairing private lemma isOrthogonal_short_and_long_aux {a b c d e f a' b' c' d' e' f' : ℤ} {S : Set (ℤ × ℤ)} (S_def : S = {(0, 0), (1, 1), (-1, -1), (1, 2), (2, 1), (-1, -2), (-2, -1), (1, 3), (3, 1), (-1, -3), (-3, -1)}) (ha : (a, a') ∈ S) (hb : (b, b') ∈ S) (hc : (c, c') ∈ S) (hd : (d, d') ∈ S) (he : (e, e') ∈ S) (hf : (f, f') ∈ S) (h₁ : c = a + 3 * b) (h₂ : c' = a' + b') (h₃ : d = 2 * a + 3 * b) (h₄ : d' = 2 * a' + b') (h₅ : e = a + b) (h₆ : e' = 3 * a' + b') (h₇ : f = a + 2 * b) (h₈ : f' = 3 * a' + 2 * b') : a = 0 ∧ b = 0 := by simp [S_def] at ha hb hc hd he hf omega lemma isOrthogonal_short_and_long {i : ι} (hi : P.root i ∉ allRoots P) : P.IsOrthogonal i (short P) ∧ P.IsOrthogonal i (long P) := by suffices P.pairingIn ℤ i (short P) = 0 ∧ P.pairingIn ℤ i (long P) = 0 by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap simpa [isOrthogonal_iff_pairing_eq_zero, ← P.algebraMap_pairingIn ℤ] simp only [mem_cons, not_mem_nil, or_false, not_or] at hi obtain ⟨h₁, h₂, h₃, h₄, h₅, h₆, h₇, h₈, h₉, h₁₀, h₁₁, h₁₂⟩ := hi have ha := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed' i (short P) ‹_› ‹_› have hb := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed' i (long P) ‹_› ‹_› have hc := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed' i (shortAddLong P) ‹_› ‹_› have hd := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed' i (twoShortAddLong P) ‹_› ‹_› have he := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed' i (threeShortAddLong P) ‹_› ‹_› have hf := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed' i (threeShortAddTwoLong P) ‹_› ‹_› apply isOrthogonal_short_and_long_aux rfl ha hb hc hd he hf <;> simp section IsIrreducible variable [P.IsIrreducible] @[simp] lemma span_eq_top : span R {longRoot P, shortRoot P} = ⊤ := by have := P.span_root_image_eq_top_of_forall_orthogonal {long P, short P} (by simp) rw [show P.root '' {long P, short P} = {longRoot P, shortRoot P} by aesop] at this refine this fun k hk ij hij ↦ ?_ replace hk : P.root k ∉ allRoots P := fun contra ↦ hk <| span_subset_span ℤ _ _ <| mem_span_of_mem_allRoots P contra have aux := isOrthogonal_short_and_long P hk rcases hij with rfl | rfl <;> tauto /-- The distinguished basis carried by an `EmbeddedG2`. In fact this is a `RootPairing.Base`. TODO Upgrade to this stronger statement. -/ def basis : Module.Basis (Fin 2) R M := have : LinearIndependent R ![EmbeddedG2.shortRoot P, EmbeddedG2.longRoot P] := by have := pairing_long_short P refine (IsReduced.linearIndependent_iff P).mpr ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · norm_num [h] at this · simp only [root_eq_neg_iff] at h norm_num [h] at this Module.Basis.mk this (by simp) lemma mem_allRoots (i : ι) : P.root i ∈ allRoots P := by by_contra hi obtain ⟨h₁, h₂⟩ := isOrthogonal_short_and_long P hi have : Fintype ι := Fintype.ofFinite ι have B := (P.posRootForm ℤ).toInvariantForm have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap rw [isOrthogonal_iff_pairing_eq_zero, ← B.apply_root_root_zero_iff] at h₁ h₂ have key : B.form (P.root i) = 0 := by ext x have hx : x ∈ span R {longRoot P, shortRoot P} := by simp simp only [LinearMap.zero_apply] induction hx using Submodule.span_induction with | zero => simp | mem => aesop | add => simp_all | smul => simp_all simpa using LinearMap.congr_fun key (P.root i) open scoped Classical in /-- The natural labelling of `RootPairing.EmbeddedG2.allRoots`. -/ @[simps] def indexEquivAllRoots : ι ≃ (allRoots P).toFinset := { toFun i := ⟨P.root i, List.mem_toFinset.mpr <| mem_allRoots P i⟩ invFun x := (allRoots_subset_range_root P x.property).choose left_inv i := by simp right_inv := by rintro ⟨x, hx⟩ simp only [Subtype.mk.injEq] exact (allRoots_subset_range_root P hx).choose_spec } include P in lemma card_index_eq_twelve : Nat.card ι = 12 := by classical have this : Nat.card (allRoots P).toFinset = 12 := by rw [Nat.card_eq_fintype_card, Fintype.card_coe, toFinset_card_of_nodup (allRoots_nodup P)] simp rw [← this] exact Nat.card_congr <| indexEquivAllRoots P lemma setOf_index_eq_univ : letI _i := P.indexNeg { long P, -long P, short P, -short P, shortAddLong P, -shortAddLong P, twoShortAddLong P, -twoShortAddLong P, threeShortAddLong P, -threeShortAddLong P, threeShortAddTwoLong P, -threeShortAddTwoLong P } = univ := eq_univ_iff_forall.mpr fun i ↦ by simpa using mem_allRoots P i end IsIrreducible end EmbeddedG2 namespace IsG2 variable {P} variable [P.IsG2] (b : P.Base) [Finite ι] [CharZero R] [IsDomain R] @[simp] lemma card_base_support_eq_two : b.support.card = 2 := by have _i : P.EmbeddedG2 := toEmbeddedG2 P have _i : Nonempty ι := IsG2.nonempty P rw [← Fintype.card_fin 2, ← Module.finrank_eq_card_basis (EmbeddedG2.basis P), Module.finrank_eq_card_basis (b.toWeightBasis (P := P.toRootSystem)), Fintype.card_coe] variable {b} in lemma span_eq_rootSpan_int {i j : ι} (hi : i ∈ b.support) (hj : j ∈ b.support) (h_ne : i ≠ j) : Submodule.span ℤ {P.root i, P.root j} = P.rootSpan ℤ := by classical have : {i, j} ⊆ b.support := by grind rw [← image_pair, ← Finset.coe_pair, Finset.eq_of_subset_of_card_le this (by aesop), b.span_int_root_support] end IsG2 end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/Finite/CanonicalBilinear.lean
import Mathlib.Algebra.Ring.SumsOfSquares import Mathlib.LinearAlgebra.RootSystem.RootPositive /-! # The canonical bilinear form on a finite root pairing Given a finite root pairing, we define a canonical map from weight space to coweight space, and the corresponding bilinear form. This form is symmetric and Weyl-invariant, and if the base ring is linearly ordered, then the form is root-positive, positive-semidefinite on the weight space, and positive-definite on the span of roots. From these facts, it is easy to show that Coxeter weights in a finite root pairing are bounded above by 4. Thus, the pairings of roots and coroots in a crystallographic root pairing are restricted to a small finite set of possibilities. Another application is to the faithfulness of the Weyl group action on roots, and finiteness of the Weyl group. ## Main definitions: * `RootPairing.Polarization`: A distinguished linear map from the weight space to the coweight space. * `RootPairing.RootForm` : The bilinear form on weight space corresponding to `Polarization`. ## Main results: * `RootPairing.rootForm_self_sum_of_squares` : The inner product of any weight vector is a sum of squares. * `RootPairing.rootForm_reflection_reflection_apply` : `RootForm` is invariant with respect to reflections. * `RootPairing.rootForm_self_smul_coroot`: The inner product of a root with itself times the corresponding coroot is equal to two times Polarization applied to the root. * `RootPairing.exists_ge_zero_eq_rootForm`: `RootForm` is positive semidefinite. ## References: * [N. Bourbaki, *Lie groups and Lie algebras. Chapters 4--6*][bourbaki1968] * [M. Demazure, *SGA III, Exposé XXI, Données Radicielles*][demazure1970] -/ open Set Function open Module hiding reflection open Submodule (span) noncomputable section variable {ι R M N : Type*} namespace RootPairing variable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] (P : RootPairing ι R M N) section Fintype variable [Fintype ι] /-- An invariant linear map from weight space to coweight space. -/ def Polarization : M →ₗ[R] N := ∑ i, LinearMap.toSpanSingleton R N (P.coroot i) ∘ₗ P.coroot' i @[simp] lemma Polarization_apply (x : M) : P.Polarization x = ∑ i, P.coroot' i x • P.coroot i := by simp [Polarization] /-- An invariant linear map from coweight space to weight space. -/ def CoPolarization : N →ₗ[R] M := P.flip.Polarization @[simp] lemma CoPolarization_apply (x : N) : P.CoPolarization x = ∑ i, P.root' i x • P.root i := P.flip.Polarization_apply x lemma CoPolarization_eq : P.CoPolarization = P.flip.Polarization := rfl /-- An invariant inner product on the weight space. -/ def RootForm : LinearMap.BilinForm R M := ∑ i, (P.coroot' i).smulRight (P.coroot' i) /-- An invariant inner product on the coweight space. -/ def CorootForm : LinearMap.BilinForm R N := P.flip.RootForm lemma rootForm_apply_apply (x y : M) : P.RootForm x y = ∑ i, P.coroot' i x * P.coroot' i y := by simp [RootForm] lemma corootForm_apply_apply (x y : N) : P.CorootForm x y = ∑ i, P.root' i x * P.root' i y := P.flip.rootForm_apply_apply x y lemma toLinearMap_apply_apply_Polarization (x y : M) : P.toLinearMap y (P.Polarization x) = P.RootForm x y := by simp [RootForm] lemma toLinearMap_apply_CoPolarization (x : N) : P.toLinearMap (P.CoPolarization x) = P.CorootForm x := by ext y exact P.flip.toLinearMap_apply_apply_Polarization x y lemma flip_comp_polarization_eq_rootForm : P.flip.toLinearMap ∘ₗ P.Polarization = P.RootForm := by ext; simp [rootForm_apply_apply, RootPairing.flip] lemma self_comp_coPolarization_eq_corootForm : P.toLinearMap ∘ₗ P.CoPolarization = P.CorootForm := P.flip.flip_comp_polarization_eq_rootForm lemma polarization_apply_eq_zero_iff (m : M) : P.Polarization m = 0 ↔ P.RootForm m = 0 := by rw [← flip_comp_polarization_eq_rootForm] refine ⟨fun h ↦ by simp [h], ?_⟩ rintro (h : P.flip.toPerfPair (P.Polarization m) = 0) simpa only [EmbeddingLike.map_eq_zero_iff] using h lemma coPolarization_apply_eq_zero_iff (n : N) : P.CoPolarization n = 0 ↔ P.CorootForm n = 0 := P.flip.polarization_apply_eq_zero_iff n lemma ker_polarization_eq_ker_rootForm : LinearMap.ker P.Polarization = LinearMap.ker P.RootForm := by ext; simp only [LinearMap.mem_ker, P.polarization_apply_eq_zero_iff] lemma ker_copolarization_eq_ker_corootForm : LinearMap.ker P.CoPolarization = LinearMap.ker P.CorootForm := P.flip.ker_polarization_eq_ker_rootForm lemma rootForm_symmetric : LinearMap.IsSymm P.RootForm := by simp [LinearMap.isSymm_def, mul_comm, rootForm_apply_apply] @[simp] lemma rootForm_reflection_reflection_apply (i : ι) (x y : M) : P.RootForm (P.reflection i x) (P.reflection i y) = P.RootForm x y := by simp only [rootForm_apply_apply, coroot'_reflection] exact Fintype.sum_equiv (P.reflectionPerm i) (fun j ↦ (P.coroot' (P.reflectionPerm i j) x) * (P.coroot' (P.reflectionPerm i j) y)) (fun j ↦ P.coroot' j x * P.coroot' j y) (congrFun rfl) lemma rootForm_self_sum_of_squares (x : M) : IsSumSq (P.RootForm x x) := P.rootForm_apply_apply x x ▸ IsSumSq.sum_mul_self Finset.univ _ lemma rootForm_root_self (j : ι) : P.RootForm (P.root j) (P.root j) = ∑ (i : ι), (P.pairing j i) * (P.pairing j i) := by simp [rootForm_apply_apply] theorem range_polarization_domRestrict_le_span_coroot : LinearMap.range (P.Polarization.domRestrict (P.rootSpan R)) ≤ P.corootSpan R := by intro y hy obtain ⟨x, hx⟩ := hy rw [← hx, LinearMap.domRestrict_apply, Polarization_apply] refine (Submodule.mem_span_range_iff_exists_fun R).mpr ?_ use fun i => P.toLinearMap x (P.coroot i) simp theorem corootSpan_dualAnnihilator_le_ker_rootForm : (P.corootSpan R).dualAnnihilator.map P.toPerfPair.symm ≤ LinearMap.ker P.RootForm := by rw [P.corootSpan_dualAnnihilator_map_eq_iInf_ker_coroot'] intro x hx ext y simp_all [coroot', rootForm_apply_apply] theorem rootSpan_dualAnnihilator_le_ker_rootForm : (P.rootSpan R).dualAnnihilator.map P.flip.toPerfPair.symm ≤ LinearMap.ker P.CorootForm := P.flip.corootSpan_dualAnnihilator_le_ker_rootForm end Fintype section IsValuedIn variable (S : Type*) [CommRing S] [Algebra S R] [FaithfulSMul S R] [Module S M] [IsScalarTower S R M] [Module S N] [IsScalarTower S R N] [P.IsValuedIn S] [Fintype ι] {i j : ι} /-- Polarization restricted to `S`-span of roots. -/ def PolarizationIn : P.rootSpan S →ₗ[S] N := ∑ i : ι, LinearMap.toSpanSingleton S N (P.coroot i) ∘ₗ P.coroot'In S i omit [IsScalarTower S R N] in lemma PolarizationIn_apply (x : P.rootSpan S) : P.PolarizationIn S x = ∑ i, P.coroot'In S i x • P.coroot i := by simp [PolarizationIn] lemma PolarizationIn_eq (x : P.rootSpan S) : P.PolarizationIn S x = P.Polarization x := by simp only [PolarizationIn, LinearMap.coeFn_sum, LinearMap.coe_comp, Finset.sum_apply, comp_apply, LinearMap.toSpanSingleton_apply, Polarization_apply] refine Finset.sum_congr rfl fun i hi ↦ ?_ rw [algebra_compatible_smul R (P.coroot'In S i x) (P.coroot i), algebraMap_coroot'In_apply] lemma range_polarizationIn : Submodule.map P.Polarization (P.rootSpan R) = LinearMap.range (P.PolarizationIn R) := by ext x simp [PolarizationIn_eq] /-- Polarization restricted to `S`-span of roots. -/ def CoPolarizationIn : P.corootSpan S →ₗ[S] M := P.flip.PolarizationIn S omit [IsScalarTower S R M] in lemma CoPolarizationIn_apply (x : P.corootSpan S) : P.CoPolarizationIn S x = ∑ i, P.root'In S i x • P.root i := P.flip.PolarizationIn_apply S x lemma CoPolarizationIn_eq (x : P.corootSpan S) : P.CoPolarizationIn S x = P.CoPolarization x := P.flip.PolarizationIn_eq S x /-- A canonical bilinear form on the span of roots in a finite root pairing, taking values in a commutative ring, where the root-coroot pairing takes values in that ring. -/ def RootFormIn : LinearMap.BilinForm S (P.rootSpan S) := ∑ i, (P.coroot'In S i).smulRight (P.coroot'In S i) omit [Module S N] [IsScalarTower S R N] in @[simp] lemma algebraMap_rootFormIn (x y : P.rootSpan S) : (algebraMap S R) (P.RootFormIn S x y) = P.RootForm x y := by simp [RootFormIn, rootForm_apply_apply] lemma toLinearMap_apply_PolarizationIn (x y : P.rootSpan S) : P.toLinearMap y (P.PolarizationIn S x) = (algebraMap S R) (P.RootFormIn S x y) := by rw [PolarizationIn_eq, algebraMap_rootFormIn] exact toLinearMap_apply_apply_Polarization P x y omit [IsScalarTower S R N] in lemma range_polarizationIn_le_span_coroot : LinearMap.range (P.PolarizationIn S) ≤ P.corootSpan S := by intro x hx obtain ⟨y, hy⟩ := hx rw [PolarizationIn_apply] at hy exact (Submodule.mem_span_range_iff_exists_fun S).mpr (Exists.intro (fun i ↦ (P.coroot'In S i) y) hy) /-- A version of SGA3 XXI Lemma 1.2.1 (10), adapted to change of rings. -/ lemma rootFormIn_self_smul_coroot (i : ι) : P.RootFormIn S (P.rootSpanMem S i) (P.rootSpanMem S i) • P.coroot i = 2 • P.PolarizationIn S (P.rootSpanMem S i) := by have hP : P.PolarizationIn S (P.rootSpanMem S i) = ∑ j : ι, P.pairingIn S i (P.reflectionPerm i j) • P.coroot (P.reflectionPerm i j) := by simp_rw [PolarizationIn_apply, coroot'In_rootSpanMem_eq_pairingIn] exact (Fintype.sum_equiv (P.reflectionPerm i) (fun j ↦ P.pairingIn S i (P.reflectionPerm i j) • P.coroot (P.reflectionPerm i j)) (fun j ↦ P.pairingIn S i j • P.coroot j) (congrFun rfl)).symm rw [two_nsmul] nth_rw 2 [hP] rw [PolarizationIn_apply] simp only [coroot'In_rootSpanMem_eq_pairingIn, pairingIn_reflectionPerm, pairingIn_reflectionPerm_self_left, ← reflectionPerm_coroot, neg_smul, smul_sub, sub_neg_eq_add] rw [Finset.sum_add_distrib, ← add_assoc, ← sub_eq_iff_eq_add, RootFormIn] simp only [LinearMap.coeFn_sum, LinearMap.coe_smulRight, Finset.sum_apply, coroot'In_rootSpanMem_eq_pairingIn, LinearMap.smul_apply, smul_eq_mul, Finset.sum_smul, root_coroot_eq_pairing, Finset.sum_neg_distrib, add_neg_cancel, sub_eq_zero] refine Finset.sum_congr rfl ?_ intro j hj rw [← P.algebraMap_pairingIn S, IsScalarTower.algebraMap_smul, ← mul_smul] lemma prod_rootFormIn_smul_coroot_mem_range_PolarizationIn (i : ι) : (∏ j : ι, P.RootFormIn S (P.rootSpanMem S j) (P.rootSpanMem S j)) • P.coroot i ∈ LinearMap.range (P.PolarizationIn S) := by obtain ⟨c, hc⟩ := Finset.dvd_prod_of_mem (fun j ↦ P.RootFormIn S (P.rootSpanMem S j) (P.rootSpanMem S j)) (Finset.mem_univ i) rw [hc, mul_comm, mul_smul, rootFormIn_self_smul_coroot] refine LinearMap.mem_range.mpr ?_ use c • 2 • (P.rootSpanMem S i) rw [map_smul, two_smul, two_smul, map_add] end IsValuedIn section MoreFintype variable [Fintype ι] /-- A version of SGA3 XXI Lemma 1.2.1 (10). -/ lemma rootForm_self_smul_coroot (i : ι) : (P.RootForm (P.root i) (P.root i)) • P.coroot i = 2 • P.Polarization (P.root i) := by have : (algebraMap R R) ((P.RootFormIn R) (P.rootSpanMem R i) (P.rootSpanMem R i)) • P.coroot i = 2 • P.Polarization (P.root i) := by rw [Algebra.algebraMap_self_apply, P.rootFormIn_self_smul_coroot R i, PolarizationIn_eq] rw [← this, algebraMap_rootFormIn] lemma corootForm_self_smul_root (i : ι) : (P.CorootForm (P.coroot i) (P.coroot i)) • P.root i = 2 • P.CoPolarization (P.coroot i) := rootForm_self_smul_coroot (P.flip) i lemma four_nsmul_coPolarization_compl_polarization_apply_root (i : ι) : (4 • P.CoPolarization ∘ₗ P.Polarization) (P.root i) = (P.RootForm (P.root i) (P.root i) * P.CorootForm (P.coroot i) (P.coroot i)) • P.root i := by rw [LinearMap.smul_apply, LinearMap.comp_apply, show 4 = 2 * 2 from rfl, mul_smul, ← map_nsmul, ← rootForm_self_smul_coroot, map_smul, smul_comm, ← corootForm_self_smul_root, smul_smul] lemma four_smul_rootForm_sq_eq_coxeterWeight_smul (i j : ι) : 4 • (P.RootForm (P.root i) (P.root j)) ^ 2 = P.coxeterWeight i j • (P.RootForm (P.root i) (P.root i) * P.RootForm (P.root j) (P.root j)) := by have hij : 4 • (P.RootForm (P.root i)) (P.root j) = 2 • P.toLinearMap (P.root j) (2 • P.Polarization (P.root i)) := by rw [← toLinearMap_apply_apply_Polarization, LinearMap.map_smul_of_tower, ← smul_assoc, Nat.nsmul_eq_mul] have hji : 2 • (P.RootForm (P.root i)) (P.root j) = P.toLinearMap (P.root i) (2 • P.Polarization (P.root j)) := by rw [show (P.RootForm (P.root i)) (P.root j) = (P.RootForm (P.root j)) (P.root i) by apply (rootForm_symmetric P).eq, ← toLinearMap_apply_apply_Polarization, LinearMap.map_smul_of_tower] rw [sq, nsmul_eq_mul, ← mul_assoc, ← nsmul_eq_mul, hij, ← rootForm_self_smul_coroot, smul_mul_assoc 2, ← mul_smul_comm, hji, ← rootForm_self_smul_coroot, map_smul, ← pairing, map_smul, ← pairing, smul_eq_mul, smul_eq_mul, smul_eq_mul, coxeterWeight] ring lemma prod_rootForm_smul_coroot_mem_range_domRestrict (i : ι) : (∏ a : ι, P.RootForm (P.root a) (P.root a)) • P.coroot i ∈ LinearMap.range (P.Polarization.domRestrict (P.rootSpan R)) := by obtain ⟨c, hc⟩ := Finset.dvd_prod_of_mem (fun a ↦ P.RootForm (P.root a) (P.root a)) (Finset.mem_univ i) rw [hc, mul_comm, mul_smul, rootForm_self_smul_coroot] refine LinearMap.mem_range.mpr ?_ use ⟨c • 2 • P.root i, by aesop⟩ simp end MoreFintype section IsValuedInOrdered variable (S : Type*) [CommRing S] [LinearOrder S] [IsStrictOrderedRing S] [Algebra S R] [FaithfulSMul S R] [Module S M] [IsScalarTower S R M] [P.IsValuedIn S] [Fintype ι] {i j : ι} /-- The bilinear form of a finite root pairing taking values in a linearly-ordered ring, as a root-positive form. -/ def posRootForm : P.RootPositiveForm S where form := P.RootForm symm := P.rootForm_symmetric isOrthogonal_reflection := P.rootForm_reflection_reflection_apply exists_eq i j := ⟨∑ k, P.pairingIn S i k * P.pairingIn S j k, by simp [rootForm_apply_apply]⟩ exists_pos_eq i := by refine ⟨∑ k, P.pairingIn S i k ^ 2, ?_, by simp [sq, rootForm_apply_apply]⟩ exact Finset.sum_pos' (fun j _ ↦ sq_nonneg _) ⟨i, by simp⟩ lemma algebraMap_posRootForm_posForm (x y : span S (range P.root)) : (algebraMap S R) ((P.posRootForm S).posForm x y) = P.RootForm x y := by simp [posRootForm] @[simp] lemma posRootForm_eq : (P.posRootForm S).posForm = P.RootFormIn S := by ext apply FaithfulSMul.algebraMap_injective S R simp only [algebraMap_posRootForm_posForm, algebraMap_rootFormIn] theorem exists_ge_zero_eq_rootForm (x : M) (hx : x ∈ span S (range P.root)) : ∃ s ≥ 0, algebraMap S R s = P.RootForm x x := by refine ⟨(P.posRootForm S).posForm ⟨x, hx⟩ ⟨x, hx⟩, IsSumSq.nonneg ?_, by simp [posRootForm]⟩ choose s hs using P.coroot'_apply_apply_mem_of_mem_span S hx suffices (P.posRootForm S).posForm ⟨x, hx⟩ ⟨x, hx⟩ = ∑ i, s i * s i from this ▸ IsSumSq.sum_mul_self Finset.univ s apply FaithfulSMul.algebraMap_injective S R simp only [posRootForm, RootPositiveForm.algebraMap_posForm, map_sum, map_mul] simp [hs, rootForm_apply_apply] lemma posRootForm_posForm_apply_apply (x y : P.rootSpan S) : (P.posRootForm S).posForm x y = ∑ i, P.coroot'In S i x * P.coroot'In S i y := by refine (FaithfulSMul.algebraMap_injective S R) ?_ simp [posRootForm, rootForm_apply_apply] lemma zero_le_posForm (x : span S (range P.root)) : 0 ≤ (P.posRootForm S).posForm x x := by obtain ⟨s, _, hs⟩ := P.exists_ge_zero_eq_rootForm S x.1 x.2 have : s = (P.posRootForm S).posForm x x := FaithfulSMul.algebraMap_injective S R <| (P.algebraMap_posRootForm_posForm S x x) ▸ hs rwa [← this] omit [Fintype ι] variable [Finite ι] lemma zero_lt_pairingIn_iff' : 0 < P.pairingIn S i j ↔ 0 < P.pairingIn S j i := let _i : Fintype ι := Fintype.ofFinite ι zero_lt_pairingIn_iff (P.posRootForm S) i j lemma pairingIn_lt_zero_iff : P.pairingIn S i j < 0 ↔ P.pairingIn S j i < 0 := by simpa using P.zero_lt_pairingIn_iff' S (i := i) (j := P.reflectionPerm j j) lemma pairingIn_le_zero_iff [NeZero (2 : R)] [NoZeroSMulDivisors R M] : P.pairingIn S i j ≤ 0 ↔ P.pairingIn S j i ≤ 0 := by rcases eq_or_ne (P.pairingIn S i j) 0 with hij | hij <;> rcases eq_or_ne (P.pairingIn S j i) 0 with hji | hji · rw [hij, hji] · rw [hij, P.pairingIn_eq_zero_iff.mp hij] · rw [hji, P.pairingIn_eq_zero_iff.mp hji] · rw [le_iff_eq_or_lt, le_iff_eq_or_lt, or_iff_right hij, or_iff_right hji] exact P.pairingIn_lt_zero_iff S end IsValuedInOrdered end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/GeckConstruction/Lemmas.lean
import Mathlib.LinearAlgebra.RootSystem.Base import Mathlib.LinearAlgebra.RootSystem.Chain import Mathlib.LinearAlgebra.RootSystem.Finite.G2 /-! # Supporting lemmas for Geck's construction of a Lie algebra associated to a root system -/ open Set open FaithfulSMul (algebraMap_injective) namespace RootPairing variable {ι R M N : Type*} [CommRing R] [CharZero R] [IsDomain R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] {P : RootPairing ι R M N} [Finite ι] [P.IsCrystallographic] local notation "Φ" => range P.root local notation "α" => P.root namespace Base variable {b : P.Base} (i j k : ι) (hij : i ≠ j) (hi : i ∈ b.support) (hj : j ∈ b.support) include hij hi hj /-- This is Lemma 2.5 (a) from [Geck](Geck2017). -/ lemma root_sub_root_mem_of_mem_of_mem (hk : α k + α i - α j ∈ Φ) (hkj : k ≠ j) (hk' : α k + α i ∈ Φ) : α k - α j ∈ Φ := by rcases lt_or_ge 0 (P.pairingIn ℤ j k) with hm | hm · rw [← neg_mem_range_root_iff, neg_sub] exact P.root_sub_root_mem_of_pairingIn_pos hm hkj.symm obtain ⟨l, hl⟩ := hk have hli : l ≠ i := by rintro rfl rw [add_comm, add_sub_assoc, left_eq_add, sub_eq_zero, P.root.injective.eq_iff] at hl exact hkj hl suffices 0 < P.pairingIn ℤ l i by convert P.root_sub_root_mem_of_pairingIn_pos this hli using 1 rw [hl] module have hkl : l ≠ k := by rintro rfl; exact hij <| by simpa [add_sub_assoc, sub_eq_zero] using hl replace hkl : P.pairingIn ℤ l k ≤ 0 := by suffices α l - α k ∉ Φ by contrapose! this; exact P.root_sub_root_mem_of_pairingIn_pos this hkl replace hl : α l - α k = α i - α j := by rw [hl]; module rw [hl] exact b.sub_notMem_range_root hi hj have hki : P.pairingIn ℤ i k ≤ -2 := by suffices P.pairingIn ℤ l k = 2 + P.pairingIn ℤ i k - P.pairingIn ℤ j k by linarith apply algebraMap_injective ℤ R simp only [algebraMap_pairingIn, map_sub, map_add, map_ofNat] simpa using (P.coroot' k : M →ₗ[R] R).congr_arg hl replace hki : P.pairingIn ℤ k i = -1 := by replace hk' : α i ≠ - α k := by rw [← sub_ne_zero, sub_neg_eq_add, add_comm] intro contra rw [contra] at hk' exact P.ne_zero _ hk'.choose_spec have aux (h : P.pairingIn ℤ i k = -2) : ¬P.pairingIn ℤ k i = -2 := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap contrapose! hk'; exact (P.pairingIn_neg_two_neg_two_iff ℤ i k).mp ⟨h, hk'⟩ have := P.pairingIn_pairingIn_mem_set_of_isCrystallographic i k aesop -- https://github.com/leanprover-community/mathlib4/issues/24551 (this should be faster) replace hki : P.pairing k i = -1 := by rw [← P.algebraMap_pairingIn ℤ, hki]; simp have : P.pairingIn ℤ l i = 1 - P.pairingIn ℤ j i := by apply algebraMap_injective ℤ R simp only [algebraMap_pairingIn, map_sub, map_one, algebraMap_pairingIn] convert (P.coroot' i : M →ₗ[R] R).congr_arg hl using 1 simp only [map_sub, map_add, LinearMap.flip_apply, root_coroot_eq_pairing, hki, pairing_same, sub_left_inj] ring replace hij := pairingIn_le_zero_of_ne b hij.symm hj hi omega /-- This is Lemma 2.5 (b) from [Geck](Geck2017). -/ lemma root_add_root_mem_of_mem_of_mem (hk : α k + α i - α j ∈ Φ) (hkj : α k ≠ -α i) (hk' : α k - α j ∈ Φ) : α k + α i ∈ Φ := by let _i := P.indexNeg replace hk : α (-k) + α j - α i ∈ Φ := by rw [← neg_mem_range_root_iff] convert hk using 1 simp only [indexNeg_neg, root_reflectionPerm, reflection_apply_self] module rw [← neg_mem_range_root_iff] convert b.root_sub_root_mem_of_mem_of_mem j i (-k) hij.symm hj hi hk (by contrapose! hkj; aesop) (by convert P.neg_mem_range_root_iff.mpr hk' using 1; simp [neg_add_eq_sub]) using 1 simp only [indexNeg_neg, root_reflectionPerm, reflection_apply_self] module lemma root_sub_mem_iff_root_add_mem (hkj : k ≠ j) (hkj' : α k ≠ -α i) (hk : α k + α i - α j ∈ Φ) : α k - α j ∈ Φ ↔ α k + α i ∈ Φ := ⟨b.root_add_root_mem_of_mem_of_mem i j k hij hi hj hk hkj', b.root_sub_root_mem_of_mem_of_mem i j k hij hi hj hk hkj⟩ end Base section chainBotCoeff_mul_chainTopCoeff /-! The proof of Lemma 2.6 from [Geck](Geck2017). -/ variable {b : P.Base} {i j k l m : ι} private lemma chainBotCoeff_mul_chainTopCoeff.aux_0 [P.IsNotG2] (hik_mem : P.root k + P.root i ∈ range P.root) : P.pairingIn ℤ k i = 0 ∨ (P.pairingIn ℤ k i < 0 ∧ P.chainBotCoeff i k = 0) := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap have := pairingIn_le_zero_of_root_add_mem hik_mem rw [add_comm] at hik_mem rw [P.chainBotCoeff_if_one_zero hik_mem, ite_eq_right_iff, P.pairingIn_eq_zero_iff (i := i)] cutsat variable [P.IsReduced] [P.IsIrreducible] (hi : i ∈ b.support) (hj : j ∈ b.support) (hij : i ≠ j) (h₁ : P.root k + P.root i = P.root l) (h₂ : P.root k - P.root j = P.root m) (h₃ : P.root k + P.root i - P.root j ∈ range P.root) include hi hj hij h₁ h₂ h₃ lemma chainBotCoeff_mul_chainTopCoeff.isNotG2 : P.IsNotG2 := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M rw [← P.not_isG2_iff_isNotG2] intro contra obtain ⟨n, h₃⟩ := h₃ obtain ⟨x, y, h₀⟩ : ∃ x y : ℤ, x • P.root i + y • P.root j = P.root k := by rw [← Submodule.mem_span_pair, IsG2.span_eq_rootSpan_int hi hj hij] exact Submodule.subset_span (mem_range_self k) let s : Set ℤ := {-3, -1, 0, 1, 3} let A : ℤ := P.pairingIn ℤ j i have hki : P.root k ≠ P.root i := fun contra ↦ by replace h₁ : 2 • P.root i = P.root l := by rwa [contra, ← two_nsmul] at h₁ exact P.nsmul_notMem_range_root ⟨_, h₁.symm⟩ have hki' : P.root k ≠ -P.root i := fun contra ↦ by replace h₁ : P.root l = 0 := by rwa [contra, neg_add_cancel, eq_comm] at h₁ exact P.ne_zero _ h₁ have hli : P.root l ≠ P.root i := fun contra ↦ by replace h₁ : P.root k = 0 := by rwa [contra, add_eq_right] at h₁ exact P.ne_zero _ h₁ have hli' : P.root l ≠ -P.root i := fun contra ↦ by replace h₁ : P.root k = 2 • P.root l := by rwa [← neg_eq_iff_eq_neg.mpr contra, ← sub_eq_add_neg, sub_eq_iff_eq_add, ← two_nsmul] at h₁ exact P.nsmul_notMem_range_root ⟨_, h₁⟩ have hmi : P.root m ≠ P.root i := fun contra ↦ by replace h₂ : P.root k = P.root i + P.root j := by rwa [contra, sub_eq_iff_eq_add] at h₂ replace h₃ : P.root n = 2 • P.root i := by rw [h₃, h₂]; abel exact P.nsmul_notMem_range_root ⟨_, h₃⟩ have hmi' : P.root m ≠ -P.root i := fun contra ↦ by replace h₂ : P.root k = -P.root i + P.root j := by rwa [contra, sub_eq_iff_eq_add] at h₂ replace h₃ : P.root n = 0 := by rw [h₃, h₂]; abel exact P.ne_zero _ h₃ have hni : P.root n ≠ P.root i := fun contra ↦ by replace h₃ : P.root k = P.root j := by rwa [contra, add_comm, add_sub_assoc, left_eq_add, sub_eq_zero] at h₃ replace h₂ : P.root m = 0 := by rw [← h₂, h₃, sub_self] exact P.ne_zero _ h₂ have hni' : P.root n ≠ -P.root i := fun contra ↦ by replace h₃ : 2 • P.root n = P.root m := by rwa [← neg_eq_iff_eq_neg.mpr contra, add_comm, add_sub_assoc, eq_neg_add_iff_add_eq, ← two_nsmul, h₂] at h₃ exact P.nsmul_notMem_range_root ⟨_, h₃.symm⟩ replace h₁ : 2 * (x + 1) + A * y ∈ s := by convert IsG2.pairingIn_mem_zero_one_three P l i hli hli' replace h₁ : P.root l = (x + 1) • P.root i + y • P.root j := by rw [← h₁, ← h₀]; module rw [pairingIn_eq_add_of_root_eq_smul_add_smul (S := ℤ) (j := i) h₁, pairingIn_same, Int.zsmul_eq_mul, Int.zsmul_eq_mul] ring replace h₂ : 2 * x + A * (y - 1) ∈ s := by convert IsG2.pairingIn_mem_zero_one_three P m i hmi hmi' replace h₂ : P.root m = x • P.root i + (y - 1) • P.root j := by rw [← h₂, ← h₀]; module rw [pairingIn_eq_add_of_root_eq_smul_add_smul (S := ℤ) (j := i) h₂, pairingIn_same, Int.zsmul_eq_mul, Int.zsmul_eq_mul] ring replace h₃ : 2 * (x + 1) + A * (y - 1) ∈ s := by convert IsG2.pairingIn_mem_zero_one_three P n i hni hni' replace h₃ : P.root n = (x + 1) • P.root i + (y - 1) • P.root j := by rw [h₃, ← h₀]; module rw [pairingIn_eq_add_of_root_eq_smul_add_smul (S := ℤ) (j := i) h₃, pairingIn_same, Int.zsmul_eq_mul, Int.zsmul_eq_mul] ring replace h₀ : 2 * x + A * y ∈ s := by convert IsG2.pairingIn_mem_zero_one_three P k i hki hki' rw [pairingIn_eq_add_of_root_eq_smul_add_smul (j := i) h₀.symm, pairingIn_same, Int.zsmul_eq_mul, Int.zsmul_eq_mul] ring have hA : A ∈ s := IsG2.pairingIn_mem_zero_one_three P j i (P.root.injective.ne_iff.mpr hij.symm) (b.root_ne_neg_of_ne hj hi hij.symm) subst s simp only [mem_insert_iff, mem_singleton_iff] at h₀ h₁ h₂ h₃ hA rcases hA with hA | hA | hA | hA | hA <;> rw [hA] at h₀ h₁ h₂ h₃ <;> omega /- An auxiliary result en route to `RootPairing.chainBotCoeff_mul_chainTopCoeff`. -/ private lemma chainBotCoeff_mul_chainTopCoeff.aux_1 (hki : P.pairingIn ℤ k i = 0) : have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap letI := P.indexNeg P.root i + P.root m ∈ range P.root → P.root j + P.root (-l) ∈ range P.root → P.root j + P.root (-k) ∈ range P.root → (P.chainBotCoeff i m + 1) * (P.chainBotCoeff j (-k) + 1) = (P.chainBotCoeff j (-l) + 1) * (P.chainBotCoeff i k + 1) := by intro _ him_mem hjl_mem hjk_mem /- Setup some typeclasses and name the 6th root `n`. -/ have := chainBotCoeff_mul_chainTopCoeff.isNotG2 hi hj hij h₁ h₂ h₃ letI := P.indexNeg have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M obtain ⟨n, hn⟩ := h₃ /- Establish basic relationships about roots and their sums / differences. -/ have hnk_ne : n ≠ k := by rintro rfl; simp [sub_eq_zero, hij, add_sub_assoc] at hn have hkj_ne : k ≠ j ∧ P.root k ≠ -P.root j := (IsReduced.linearIndependent_iff _).mp <| P.linearIndependent_of_sub_mem_range_root <| h₂ ▸ mem_range_self m have hnk_notMem : P.root n - P.root k ∉ range P.root := by convert b.sub_notMem_range_root hi hj using 2; rw [hn]; module /- Calculate some auxiliary relationships between root pairings. -/ have aux₀ : P.pairingIn ℤ j i = - P.pairingIn ℤ m i := by suffices P.pairing j i = - P.pairing m i from algebraMap_injective ℤ R <| by simpa only [algebraMap_pairingIn, map_neg] replace hki : P.pairing k i = 0 := by rw [← P.algebraMap_pairingIn ℤ, hki, map_zero] simp only [← root_coroot_eq_pairing, ← h₂] simp [hki] have aux₁ : P.pairingIn ℤ j i = 0 := by refine le_antisymm (b.pairingIn_le_zero_of_ne hij.symm hj hi) ?_ rw [aux₀, neg_nonneg] refine P.pairingIn_le_zero_of_root_add_mem ⟨n, ?_⟩ rw [hn, ← h₂] abel /- Calculate the pairings between four key root pairs. -/ have key₁ : P.pairingIn ℤ i k = 0 := by rwa [pairingIn_eq_zero_iff] have key₂ : P.pairingIn ℤ i m = 0 := P.pairingIn_eq_zero_iff.mp <| by simpa [aux₁] using aux₀ have key₃ : P.pairingIn ℤ j k = 2 := by suffices 2 ≤ P.pairingIn ℤ j k by have := IsNotG2.pairingIn_mem_zero_one_two (P := P) j k; aesop have hn₁ : P.pairingIn ℤ n k = 2 + P.pairingIn ℤ i k - P.pairingIn ℤ j k := by apply algebraMap_injective ℤ R simp only [map_add, map_sub, algebraMap_pairingIn, ← root_coroot_eq_pairing, hn] simp have hn₂ : P.pairingIn ℤ n k ≤ 0 := by by_contra! contra; exact hnk_notMem <| P.root_sub_root_mem_of_pairingIn_pos contra hnk_ne omega have key₄ : P.pairingIn ℤ l j = 1 := by have hij : P.pairing i j = 0 := by rw [pairing_eq_zero_iff, ← P.algebraMap_pairingIn ℤ, aux₁, map_zero] have hkj : P.pairing k j = 1 := by rw [← P.algebraMap_pairingIn ℤ] have := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed' j k (by aesop) (by aesop) aesop apply algebraMap_injective ℤ R rw [algebraMap_pairingIn, ← root_coroot_eq_pairing, ← h₁] simp [hkj, hij] replace key₄ : P.pairingIn ℤ j l ≠ 0 := by rw [ne_eq, P.pairingIn_eq_zero_iff]; omega /- Calculate the value of each of the four terms in the goal. -/ have hik_mem : P.root i + P.root k ∈ range P.root := ⟨l, by rw [← h₁, add_comm]⟩ simp only [P.chainBotCoeff_if_one_zero, hik_mem, him_mem, hjl_mem, hjk_mem] simp [key₁, key₂, key₃, key₄] /- An auxiliary result en route to `RootPairing.chainBotCoeff_mul_chainTopCoeff`. -/ open RootPositiveForm in private lemma chainBotCoeff_mul_chainTopCoeff.aux_2 (hki' : P.pairingIn ℤ k i < 0) (hkj' : 0 < P.pairingIn ℤ k j) : have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap letI := P.indexNeg P.root i + P.root m ∈ range P.root → P.root j + P.root (-l) ∈ range P.root → P.root j + P.root (-k) ∈ range P.root → ¬ (P.chainBotCoeff i m = 1 ∧ P.chainBotCoeff j (-l) = 0) := by intro _ him_mem hjl_mem hjk_mem letI := P.indexNeg /- Setup some typeclasses. -/ have := chainBotCoeff_mul_chainTopCoeff.isNotG2 hi hj hij h₁ h₂ h₃ have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M /- Establish basic relationships about roots and their sums / differences. -/ have hkj_ne : k ≠ j ∧ P.root k ≠ -P.root j := (IsReduced.linearIndependent_iff _).mp <| P.linearIndependent_of_sub_mem_range_root <| h₂ ▸ mem_range_self m have hlj_mem : P.root l - P.root j ∈ range P.root := by rwa [← h₁] /- It is sufficient to prove that two key pairings vanish. -/ suffices ¬ (P.pairingIn ℤ m i = 0 ∧ P.pairingIn ℤ l j ≠ 0) by contrapose! this rcases ne_or_eq (P.pairingIn ℤ m i) 0 with hmi | hmi · simpa [hmi, this.1, P.pairingIn_eq_zero_iff (i := i)] using chainBotCoeff_if_one_zero him_mem refine ⟨hmi, fun hlj ↦ ?_⟩ rw [chainBotCoeff_if_one_zero hjl_mem] at this simp [P.pairingIn_eq_zero_iff (i := j), hlj] at this /- Assume for contradiction that the two pairings do not vanish. -/ rintro ⟨hmi, hlj⟩ /- Use the assumptions to calculate various relationships between root pairings. -/ have aux₀ : P.pairingIn ℤ j i = P.pairingIn ℤ k i := by suffices P.pairing j i = P.pairing k i from algebraMap_injective ℤ R <| by simpa only [algebraMap_pairingIn] replace h₂ : P.root k = P.root j + P.root m := (add_eq_of_eq_sub' h₂.symm).symm simpa [← P.root_coroot_eq_pairing k, h₂, ← P.algebraMap_pairingIn ℤ] obtain ⟨aux₁, aux₂⟩ : P.pairingIn ℤ i j = -1 ∧ P.pairingIn ℤ k j = 2 := by suffices 0 < - P.pairingIn ℤ i j ∧ - P.pairingIn ℤ i j < P.pairingIn ℤ k j ∧ P.pairingIn ℤ k j ≤ 2 by cutsat refine ⟨?_, ?_, ?_⟩ · rwa [neg_pos, P.pairingIn_lt_zero_iff, aux₀] · suffices P.pairingIn ℤ l j = P.pairingIn ℤ i j + P.pairingIn ℤ k j by have := zero_le_pairingIn_of_root_sub_mem hlj_mem; cutsat suffices P.pairing l j = P.pairing i j + P.pairing k j from algebraMap_injective ℤ R <| by simpa only [algebraMap_pairingIn, map_add] simp [← P.root_coroot_eq_pairing l, ← h₁, add_comm] · have := IsNotG2.pairingIn_mem_zero_one_two (P := P) k j aesop /- Choose a positive invariant form. -/ obtain B : RootPositiveForm ℤ P := have : Fintype ι := Fintype.ofFinite ι; P.posRootForm ℤ /- Calculate root length relationships implied by the pairings calculated above. -/ have ⟨aux₃, aux₄⟩ : B.rootLength i = B.rootLength j ∧ B.rootLength j < B.rootLength k := by have hij_le : B.rootLength i ≤ B.rootLength j := B.rootLength_le_of_pairingIn_eq <| Or.inl aux₁ have hjk_lt : B.rootLength j < B.rootLength k := B.rootLength_lt_of_pairingIn_notMem (by aesop) hkj_ne.2 <| by aesop refine ⟨?_, hjk_lt⟩ simpa [posForm, rootLength] using (B.toInvariantForm.apply_eq_or_of_apply_ne (i := j) (j := k) (by simpa [posForm, rootLength] using hjk_lt.ne) i).resolve_right (by simpa [posForm, rootLength] using (lt_of_le_of_lt hij_le hjk_lt).ne) /- Use the root length results to calculate a final root pairing. -/ have aux₅ : P.pairingIn ℤ k i = -1 := by suffices P.pairingIn ℤ j i = -1 by cutsat have aux : B.toInvariantForm.form (P.root i) (P.root i) = B.toInvariantForm.form (P.root j) (P.root j) := by simpa [posForm, rootLength] using aux₃ have := P.pairingIn_pairingIn_mem_set_of_length_eq_of_ne aux hij (b.root_ne_neg_of_ne hi hj hij) aesop /- Use the newly calculated pairing result to obtain further information about root lengths. -/ have aux₆ : B.rootLength k ≤ B.rootLength i := B.rootLength_le_of_pairingIn_eq <| Or.inl aux₅ /- We now have contradictory information about root lengths. -/ cutsat open chainBotCoeff_mul_chainTopCoeff in /-- This is Lemma 2.6 from [Geck](Geck2017). -/ lemma chainBotCoeff_mul_chainTopCoeff : (P.chainBotCoeff i m + 1) * (P.chainTopCoeff j k + 1) = (P.chainTopCoeff j l + 1) * (P.chainBotCoeff i k + 1) := by /- Setup some typeclasses. -/ have := chainBotCoeff_mul_chainTopCoeff.isNotG2 hi hj hij h₁ h₂ h₃ letI := P.indexNeg suffices (P.chainBotCoeff i m + 1) * (P.chainBotCoeff j (-k) + 1) = (P.chainBotCoeff j (-l) + 1) * (P.chainBotCoeff i k + 1) by simpa /- Establish basic relationships about roots and their sums / differences. -/ have him_mem : P.root i + P.root m ∈ range P.root := by rw [← h₂]; convert h₃ using 1; abel have hik_mem : P.root k + P.root i ∈ range P.root := h₁ ▸ mem_range_self l have hjk_mem : P.root j + P.root (-k) ∈ range P.root := by convert mem_range_self (-m) using 1; simpa [sub_eq_add_neg] using congr(-$h₂) have hjl_mem : P.root j + P.root (-l) ∈ range P.root := by rw [h₁, ← neg_mem_range_root_iff] at h₃; convert h₃ using 1; simp [sub_eq_add_neg] have h₁' : P.root (-k) - P.root i = P.root (-l) := by simp only [root_reflectionPerm, reflection_apply_self, indexNeg_neg]; rw [← h₁]; abel have h₂' : P.root (-k) + P.root j = P.root (-m) := by simp only [root_reflectionPerm, reflection_apply_self, indexNeg_neg]; rw [← h₂]; abel have h₃' : P.root (-k) + P.root j - P.root i ∈ range P.root := by grind /- Proceed to the main argument, following Geck's case splits. It's all just bookkeeping. -/ rcases aux_0 hik_mem with hki | ⟨hki, hik⟩ · /- Geck "Case 1" -/ exact aux_1 hi hj hij h₁ h₂ h₃ hki him_mem hjl_mem hjk_mem rw [add_comm] at hik_mem hjk_mem rcases aux_0 hjk_mem with hkj | ⟨hkj, hjk⟩ · /- Geck "Case 2" -/ simpa only [neg_neg] using (aux_1 hj hi hij.symm h₂' h₁' h₃' hkj hjl_mem (by simpa only [neg_neg]) (by simpa only [neg_neg])).symm /- Geck "Case 3" -/ suffices P.chainBotCoeff i m = P.chainBotCoeff j (-l) by rw [hik, hjk, this] have aux₁ : ¬ (P.chainBotCoeff i m = 1 ∧ P.chainBotCoeff j (-l) = 0) := aux_2 hi hj hij h₁ h₂ h₃ hki (by simpa using hkj) him_mem hjl_mem <| by rwa [add_comm] have aux₂ : ¬(P.chainBotCoeff j (-l) = 1 ∧ P.chainBotCoeff i m = 0) := by simpa using aux_2 hj hi hij.symm h₂' h₁' h₃' hkj (by simpa) hjl_mem (by simpa only [neg_neg]) (by simpa only [neg_neg]) have aux₃ : P.chainBotCoeff i m = 0 ∨ P.chainBotCoeff i m = 1 := by have := P.chainBotCoeff_if_one_zero him_mem split at this <;> simp [this] have aux₄ : P.chainBotCoeff j (-l) = 0 ∨ P.chainBotCoeff j (-l) = 1 := by have := P.chainBotCoeff_if_one_zero hjl_mem split at this <;> simp only [this, true_or, or_true] cutsat end chainBotCoeff_mul_chainTopCoeff end RootPairing
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/GeckConstruction/Basic.lean
import Mathlib.Algebra.Lie.Matrix import Mathlib.Algebra.Lie.OfAssociative import Mathlib.Algebra.Lie.Weights.Basic import Mathlib.LinearAlgebra.Eigenspace.Matrix import Mathlib.LinearAlgebra.RootSystem.CartanMatrix /-! # Geck's construction of a Lie algebra associated to a root system This file contains an implementation of Geck's construction of a semisimple Lie algebra from a reduced crystallographic root system. It follows [Geck](Geck2017) quite closely. ## Main definitions: * `RootPairing.GeckConstruction.lieAlgebra`: the Geck construction of the Lie algebra associated to a root system with distinguished base. * `RootPairing.GeckConstruction.cartanSubalgebra`: a distinguished subalgebra corresponding to a Cartan subalgebra of the Geck construction. * `RootPairing.GeckConstruction.cartanSubalgebra_le_lieAlgebra`: the distinguished subalgebra is contained in the Geck construction. ## Alternative approaches The are at least three ways to construct a Lie algebra from a root system: 1. As a quotient of a free Lie algebra, using the Serre relations 2. Directly defining the Lie bracket on $H ⊕ K^∣Φ|$ 3. The Geck construction We comment on these as follows: 1. This construction takes just a matrix as input. It yields a semisimple Lie algebra iff the matrix is a Cartan matrix but it is quite a lot of work to prove this. On the other hand, it also allows construction of Kac-Moody Lie algebras. It has been implemented as `Matrix.ToLieAlgebra` but as of May 2025, almost nothing has been proved about it in Mathlib. 2. This construction takes a root system with base as input, together with sufficient additional data to determine a collection of extraspecial pairs of roots. The additional data for the extraspecial pairs is required to pin down certain signs when defining the Lie bracket. (These signs can be interpreted as a set-theoretic splitting of Tits's extension of the Weyl group by an elementary 2-group of order $2^l$ where $l$ is the rank.) 3. This construction takes a root system with base as input and is implemented here. There seems to be no known construction of a Lie algebra from a root system without first choosing a base: https://mathoverflow.net/questions/495434/ -/ noncomputable section open Function Set Submodule open scoped Matrix attribute [local simp] Matrix.mul_apply Matrix.one_apply Matrix.diagonal_apply namespace RootPairing.GeckConstruction variable {ι R M N : Type*} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] {P : RootPairing ι R M N} [P.IsCrystallographic] {b : P.Base} /-- Part of an `sl₂` triple used in Geck's construction of a Lie algebra from a root system. -/ def h (i : b.support) : Matrix (b.support ⊕ ι) (b.support ⊕ ι) R := open scoped Classical in .fromBlocks 0 0 0 (.diagonal (P.pairingIn ℤ · i)) lemma h_def [DecidableEq ι] (i : b.support) : h i = .fromBlocks 0 0 0 (.diagonal (P.pairingIn ℤ · i)) := by ext (j | j) (k | k) <;> simp [h, Matrix.diagonal_apply] lemma h_eq_diagonal [DecidableEq ι] (i : b.support) : h i = .diagonal (Sum.elim 0 (P.pairingIn ℤ · i)) := by ext (j | j) (k | k) <;> simp [h, Matrix.diagonal_apply] lemma span_range_h_le_range_diagonal [DecidableEq ι] : span R (range h) ≤ LinearMap.range (Matrix.diagonalLinearMap (b.support ⊕ ι) R R) := by rw [span_le] rintro - ⟨i, rfl⟩ rw [h_eq_diagonal] exact LinearMap.mem_range_self _ _ open Matrix in @[simp] lemma diagonal_elim_mem_span_h_iff [DecidableEq ι] {d : ι → R} : diagonal (Sum.elim 0 d) ∈ span R (range <| h (b := b)) ↔ d ∈ span R (range <| fun (i : b.support) j ↦ (P.pairingIn ℤ j i : R)) := by let g : Matrix ι ι R →ₗ[R] Matrix (b.support ⊕ ι) (b.support ⊕ ι) R := { toFun := .fromBlocks 0 0 0 map_add' x y := by ext (i | i) (j | j) <;> simp map_smul' t x := by ext (i | i) (j | j) <;> simp } have h₀ : Injective (g ∘ diagonalLinearMap ι R R) := fun _ _ hd ↦ funext <| by simpa [g] using hd have h₁ {d : ι → R} : diagonal (Sum.elim 0 d) = g (diagonalLinearMap ι R R d) := by ext (i | i) (j | j) <;> simp [g] have h₂ : range h = g '' (diagonalLinearMap ι R R '' (range <| fun (i : b.support) j ↦ (P.pairingIn ℤ j i : R))) := by ext; simp [g, h_def] simp_rw [h₁, h₂, span_image, ← map_comp, ← comp_apply (f := g), mem_map, LinearMap.coe_comp, h₀.eq_iff, exists_eq_right] lemma apply_sum_inl_eq_zero_of_mem_span_h (i : b.support) (j : b.support ⊕ ι) {x : Matrix (b.support ⊕ ι) (b.support ⊕ ι) R} (hx : x ∈ span R (range h)) : x j (Sum.inl i) = 0 := by induction hx using span_induction with | mem x h => obtain ⟨i, rfl⟩ := h; cases j <;> simp [h] | zero => simp | add u v _ _ hu hv => simp [hu, hv] | smul t u _ hu => simp [hu] lemma lie_h_h [Fintype ι] (i j : b.support) : ⁅h i, h j⁆ = 0 := by classical simpa only [h_eq_diagonal, ← commute_iff_lie_eq] using Matrix.commute_diagonal _ _ variable [Finite ι] [IsDomain R] [CharZero R] /-- Part of an `sl₂` triple used in Geck's construction of a Lie algebra from a root system. -/ def e (i : b.support) : Matrix (b.support ⊕ ι) (b.support ⊕ ι) R := open scoped Classical in letI := P.indexNeg .fromBlocks 0 (.of fun i' j ↦ if i' = i ∧ j = -i then 1 else 0) (.of fun i' j ↦ if i' = i then ↑|b.cartanMatrix i j| else 0) (.of fun i' j ↦ if P.root i' = P.root i + P.root j then P.chainBotCoeff i j + 1 else 0) /-- Part of an `sl₂` triple used in Geck's construction of a Lie algebra from a root system. -/ def f (i : b.support) : Matrix (b.support ⊕ ι) (b.support ⊕ ι) R := open scoped Classical in letI := P.indexNeg .fromBlocks 0 (.of fun i' j ↦ if i' = i ∧ j = i then 1 else 0) (.of fun i' j ↦ if i' = -i then ↑|b.cartanMatrix i j| else 0) (.of fun i' j ↦ if P.root i' = P.root j - P.root i then P.chainTopCoeff i j + 1 else 0) variable (b) /-- An involutive matrix which can transfer results between `RootPairing.GeckConstruction.e` and `RootPairing.GeckConstruction.f`. -/ def ω : Matrix (b.support ⊕ ι) (b.support ⊕ ι) R := open scoped Classical in letI := P.indexNeg .fromBlocks 1 0 0 <| .of fun i j ↦ if i = -j then 1 else 0 /-- Geck's construction of the Lie algebra associated to a root system with distinguished base. Note that it is convenient to include `range h` in the Lie span, to make it elementary that it contains `RootPairing.GeckConstruction.cartanSubalgebra`, and not depend on `RootPairing.GeckConstruction.lie_e_f_same`. -/ def lieAlgebra [Fintype ι] [DecidableEq ι] : LieSubalgebra R (Matrix (b.support ⊕ ι) (b.support ⊕ ι) R) := LieSubalgebra.lieSpan R _ (range h ∪ range e ∪ range f) /-- A distinguished subalgebra corresponding to a Cartan subalgebra of the Geck construction. See also `RootPairing.GeckConstruction.cartanSubalgebra'`. -/ def cartanSubalgebra [Fintype ι] [DecidableEq ι] : LieSubalgebra R (Matrix (b.support ⊕ ι) (b.support ⊕ ι) R) where __ := Submodule.span R (range h) lie_mem' {x y} hx hy := by have aux : (∀ u ∈ range (h (b := b)), ∀ v ∈ range (h (b := b)), ⁅u, v⁆ = 0) := by rintro - ⟨i, rfl⟩ - ⟨j, rfl⟩; exact lie_h_h i j simp only [Submodule.carrier_eq_coe, SetLike.mem_coe, LieSubalgebra.mem_toSubmodule, ← LieSubalgebra.coe_lieSpan_eq_span_of_forall_lie_eq_zero (R := R) aux] at hx hy ⊢ exact LieSubalgebra.lie_mem _ hx hy /-- A distinguished Cartan subalgebra of the Geck construction. -/ def cartanSubalgebra' [Fintype ι] [DecidableEq ι] : LieSubalgebra R (lieAlgebra b) := (cartanSubalgebra b).comap (lieAlgebra b).incl omit [Finite ι] [IsDomain R] [CharZero R] in lemma cartanSubalgebra_eq_lieSpan [Fintype ι] [DecidableEq ι] : cartanSubalgebra b = LieSubalgebra.lieSpan R _ (range h) := by refine le_antisymm LieSubalgebra.submodule_span_le_lieSpan ?_ rw [LieSubalgebra.lieSpan_le, cartanSubalgebra] exact Submodule.subset_span variable {b} omit [Finite ι] [IsDomain R] [CharZero R] in @[simp] lemma h_mem_cartanSubalgebra [Fintype ι] [DecidableEq ι] (i : b.support) : h i ∈ cartanSubalgebra b := Submodule.subset_span <| mem_range_self i @[simp] lemma h_mem_cartanSubalgebra' [Fintype ι] [DecidableEq ι] (i : b.support) (hi) : ⟨h i, hi⟩ ∈ cartanSubalgebra' b := by simp [cartanSubalgebra'] lemma h_mem_lieAlgebra [Fintype ι] [DecidableEq ι] (i : b.support) : h i ∈ lieAlgebra b := LieSubalgebra.subset_lieSpan <| by simp lemma e_mem_lieAlgebra [Fintype ι] [DecidableEq ι] (i : b.support) : e i ∈ lieAlgebra b := LieSubalgebra.subset_lieSpan <| by simp lemma f_mem_lieAlgebra [Fintype ι] [DecidableEq ι] (i : b.support) : f i ∈ lieAlgebra b := LieSubalgebra.subset_lieSpan <| by simp /-- The element `h i`, as a term of the Cartan subalgebra `cartanSubalgebra' b`. -/ def h' [Fintype ι] [DecidableEq ι] (i : b.support) : cartanSubalgebra' b := ⟨⟨h i, h_mem_lieAlgebra i⟩, h_mem_cartanSubalgebra' i (h_mem_lieAlgebra i)⟩ variable (b) in @[simp] lemma span_range_h'_eq_top [Fintype ι] [DecidableEq ι] : span R (range h') = (⊤ : Submodule R (cartanSubalgebra' b)) := by rw [eq_top_iff] rintro ⟨⟨x, -⟩, hx : x ∈ span R (range h)⟩ - let g : cartanSubalgebra' b →ₗ[R] Matrix (b.support ⊕ ι) (b.support ⊕ ι) R := (lieAlgebra b).subtype ∘ₗ (cartanSubalgebra' b).subtype suffices x ∈ (span R (range h')).map g by rwa [← SetLike.mem_coe, ← (injective_subtype _).mem_set_image, ← (injective_subtype _).mem_set_image, ← image_comp] rwa [map_span, ← range_comp] omit [Finite ι] [IsDomain R] [CharZero R] [P.IsCrystallographic] in @[simp] lemma ω_mul_ω [DecidableEq ι] [Fintype ι] : ω b * ω b = 1 := by ext (k | k) (l | l) <;> simp [ω, -indexNeg_neg] omit [Finite ι] [IsDomain R] in lemma ω_mul_h [Fintype ι] (i : b.support) : ω b * h i = -h i * ω b := by classical ext (k | k) (l | l) · simp [ω, h] · simp [ω, h] · simp [ω, h] · simp only [ω, h, Matrix.mul_apply, Fintype.sum_sum_type, Matrix.fromBlocks_apply₂₂] aesop lemma ω_mul_e [Fintype ι] (i : b.support) : ω b * e i = f i * ω b := by letI := P.indexNeg classical ext (k | k) (l | l) · simp [ω, e, f] · simp only [ω, e, f, mul_ite, mul_zero, Fintype.sum_sum_type, Matrix.mul_apply, Matrix.of_apply, Matrix.fromBlocks_apply₁₂, Matrix.fromBlocks_apply₂₂, Finset.sum_ite_eq'] rw [Finset.sum_eq_single_of_mem i (Finset.mem_univ _) (by simp_all)] simp [← ite_and, and_comm, -indexNeg_neg, neg_eq_iff_eq_neg] · simp [ω, e, f] · simp only [ω, e, f, Matrix.mul_apply, Fintype.sum_sum_type, Matrix.fromBlocks_apply₂₁, Matrix.fromBlocks_apply₂₂, Matrix.of_apply, mul_ite, ← neg_eq_iff_eq_neg (a := k)] rw [Finset.sum_eq_single_of_mem (-k) (Finset.mem_univ _) (by aesop)] simp [neg_eq_iff_eq_neg, sub_eq_add_neg] lemma ω_mul_f [Fintype ι] (i : b.support) : ω b * f i = e i * ω b := by classical have := congr_arg (· * ω b) (congr_arg (ω b * ·) (ω_mul_e i)) simp only [← mul_assoc, ω_mul_ω] at this simpa [mul_assoc, ω_mul_ω] using this.symm lemma lie_e_f_mul_ω [Fintype ι] (i j : b.support) : ⁅e i, f j⁆ * ω b = -ω b * ⁅e j, f i⁆ := by classical calc ⁅e i, f j⁆ * ω b = e i * f j * ω b - f j * e i * ω b := by rw [Ring.lie_def, sub_mul] _ = e i * (f j * ω b) - f j * (e i * ω b) := by rw [mul_assoc, mul_assoc] _ = e i * (ω b * e j) - f j * (ω b * f i) := by rw [← ω_mul_e, ← ω_mul_f] _ = (e i * ω b) * e j - (f j * ω b) * f i := by rw [← mul_assoc, ← mul_assoc] _ = (ω b * f i) * e j - (ω b * e j) * f i := by rw [← ω_mul_e, ← ω_mul_f] _ = ω b * (f i * e j) - ω b * (e j * f i) := by rw [mul_assoc, mul_assoc] _ = -ω b * ⁅e j, f i⁆ := ?_ rw [Ring.lie_def, mul_sub, neg_mul, neg_mul, sub_neg_eq_add] abel variable [DecidableEq ι] /-- Geck's name for the "left" basis elements of `b.support ⊕ ι`. -/ abbrev u (i : b.support) : b.support ⊕ ι → R := Pi.single (Sum.inl i) 1 variable (b) in /-- Geck's name for the "right" basis elements of `b.support ⊕ ι`. -/ abbrev v (i : ι) : b.support ⊕ ι → R := Pi.single (Sum.inr i) 1 variable (b) in omit [Finite ι] [IsDomain R] [CharZero R] [P.IsCrystallographic] in lemma apply_inr_eq_zero_of_mem_span_range_u (j : ι) {x : b.support ⊕ ι → R} (hx : x ∈ span R (range u)) : x (Sum.inr j) = 0 := by induction hx using span_induction with | mem x h => obtain ⟨i, rfl⟩ := h; simp [u] | zero => simp | add u v _ _ hu hv => simp [hu, hv] | smul t u _ hu => simp [hu] lemma lie_e_lie_f_apply [Fintype ι] (i j : b.support) : ⁅e i, ⁅f i, u j⁆⁆ = |b.cartanMatrix i j| • u i := by ext (k | k) · simp [e, f, Matrix.mulVec, dotProduct, Pi.single_apply] · simp [e, f, Matrix.mulVec, dotProduct, P.ne_zero] variable [Fintype ι] instance : IsLieAbelian (cartanSubalgebra b) := by rw [cartanSubalgebra_eq_lieSpan, LieSubalgebra.isLieAbelian_lieSpan_iff] rintro - ⟨i, rfl⟩ - ⟨j, rfl⟩ exact lie_h_h i j instance : IsLieAbelian (cartanSubalgebra' b) := by refine ⟨fun ⟨⟨x, hx⟩, hx'⟩ ⟨⟨y, hy⟩, hy'⟩ ↦ ?_⟩ let x' : cartanSubalgebra b := ⟨x, hx'⟩ let y' : cartanSubalgebra b := ⟨y, hy'⟩ suffices ⁅x', y'⁆ = 0 by simpa [x', y', Subtype.ext_iff, -trivial_lie_zero] using this simp instance : LieModule.IsTriangularizable R (cartanSubalgebra' b) (b.support ⊕ ι → R) := by refine ⟨fun ⟨⟨x, hx'⟩, hx⟩ ↦ ?_⟩ obtain ⟨d, rfl⟩ : ∃ d : b.support ⊕ ι → R, Matrix.diagonal d = x := span_range_h_le_range_diagonal <| by simpa using hx simp lemma cartanSubalgebra_le_lieAlgebra : cartanSubalgebra b ≤ lieAlgebra b := by rw [cartanSubalgebra, lieAlgebra, ← LieSubalgebra.toSubmodule_le_toSubmodule, Submodule.span_le] rintro - ⟨i, rfl⟩ exact LieSubalgebra.subset_lieSpan <| Or.inl <| Or.inl <| mem_range_self i lemma e_lie_u (i j : b.support) : ⁅e i, u j⁆ = |b.cartanMatrix i j| • v b i := by ext (k | k) <;> simp [e, Pi.single_apply] lemma e_lie_v_ne {i j : ι} {k : b.support} (h : P.root j = P.root k + P.root i) : ⁅e k, v b i⁆ = (P.chainBotCoeff k i + 1 : R) • v b j := by letI := P.indexNeg ext (l | l) · replace h : i ≠ -k := by rintro rfl; exact P.ne_zero j <| by simpa using h simp [e, h, -indexNeg_neg] · simp [e, ← h, Pi.single_apply] lemma f_lie_v_same (i : b.support) : ⁅f i, v b i⁆ = u i := by ext (j | j) · simp [f, Pi.single_apply] · simp [f, P.ne_zero j] lemma f_lie_v_ne {i j : ι} {k : b.support} (h : P.root i = P.root j + P.root k) : ⁅f k, v b i⁆ = (P.chainTopCoeff k i + 1 : R) • v b j := by ext (l | l) · replace h : i ≠ k := by rintro rfl; exact P.ne_zero j <| by simpa using h simp [f, h] · simp [f, h, Pi.single_apply] section ωConj variable (b) in /-- The conjugation `x ↦ ωxω` as an equivalence of Lie algebras. -/ @[simps] def ωConj : Matrix (b.support ⊕ ι) (b.support ⊕ ι) R ≃ₗ⁅R⁆ Matrix (b.support ⊕ ι) (b.support ⊕ ι) R where toFun x := ω b * x * ω b invFun x := ω b * x * ω b map_add' x y := by noncomm_ring map_smul' t x := by simp map_lie' {x y} := by simp only [Ring.lie_def] nth_rw 1 [← mul_one x] nth_rw 2 [← one_mul x] simp only [← ω_mul_ω (b := b)] noncomm_ring left_inv x := by simp only [← mul_assoc, ω_mul_ω, one_mul] simp [mul_assoc] right_inv x := by simp only [← mul_assoc, ω_mul_ω, one_mul] simp [mul_assoc] lemma ωConj_mem_of_mem {x : Matrix (b.support ⊕ ι) (b.support ⊕ ι) R} (hx : x ∈ lieAlgebra b) : ωConj b x ∈ lieAlgebra b := by induction hx using LieSubalgebra.lieSpan_induction with | mem u hu => obtain (⟨i, rfl⟩ | ⟨i, rfl⟩ | ⟨i, rfl⟩) : (∃ j, h j = u) ∨ (∃ j, e j = u) ∨ (∃ j, f j = u) := by simpa only [mem_union, mem_range, or_assoc] using hu · rw [← neg_mem_iff] exact LieSubalgebra.subset_lieSpan <| by simp [ω_mul_h, mul_assoc] · exact LieSubalgebra.subset_lieSpan <| by simp [ω_mul_e, mul_assoc] · exact LieSubalgebra.subset_lieSpan <| by simp [ω_mul_f, mul_assoc] | zero => simp | add u v _ _ hu hv => simpa [mul_add, add_mul] using add_mem hu hv | smul t u _ hu => simpa using SMulMemClass.smul_mem _ hu | lie u v _ _ hu hv => rw [LieEquiv.map_lie] exact (lieAlgebra b).lie_mem hu hv variable (N : LieSubmodule R (lieAlgebra b) (b.support ⊕ ι → R)) /-- The equivalence `x ↦ ωxω` as an operation on Lie submodules of the Geck construction. -/ def ωConjLieSubmodule : LieSubmodule R (lieAlgebra b) (b.support ⊕ ι → R) where __ := N.toSubmodule.comap (ω b).toLin' lie_mem A {x} hx := by let A' : lieAlgebra b := ⟨ωConj b _, ωConj_mem_of_mem A.property⟩ suffices ⁅A', ω b *ᵥ x⁆ ∈ N by simpa [A', mul_assoc] using this exact LieSubmodule.lie_mem _ hx @[simp] lemma mem_ωConjLieSubmodule_iff {x : b.support ⊕ ι → R} : x ∈ ωConjLieSubmodule N ↔ (ω b) *ᵥ x ∈ N := Iff.rfl @[simp] lemma ωConjLieSubmodule_eq_top_iff : ωConjLieSubmodule N = ⊤ ↔ N = ⊤ := by rw [← LieSubmodule.toSubmodule_eq_top] let e : Submodule R (b.support ⊕ ι → R) ≃o Submodule R (b.support ⊕ ι → R) := Submodule.orderIsoMapComapOfBijective (ω b).toLin' (Involutive.bijective fun x ↦ by simp) change e.symm N = ⊤ ↔ _ simp end ωConj end RootPairing.GeckConstruction
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/GeckConstruction/Relations.lean
import Mathlib.LinearAlgebra.RootSystem.GeckConstruction.Basic import Mathlib.LinearAlgebra.RootSystem.GeckConstruction.Lemmas import Mathlib.Algebra.Lie.Sl2 /-! # Relations in Geck's construction of a Lie algebra associated to a root system This file contains proofs that `RootPairing.GeckConstruction.lieAlgebra` contains `sl₂` triples satisfying relations associated to the Cartan matrix of the input root system. ## Main definitions: * `RootPairing.GeckConstruction.isSl2Triple`: a distinguished family of `sl₂` triples contained in the Geck construction. * `RootPairing.GeckConstruction.lie_h_e`: an interaction relation between different `sl₂` triples. * `RootPairing.GeckConstruction.lie_h_f`: an interaction relation between different `sl₂` triples. * `RootPairing.GeckConstruction.lie_e_f_ne`: an interaction relation between different `sl₂` triples. -/ noncomputable section namespace RootPairing.GeckConstruction open Function Module.End open Set hiding diagonal variable {ι R M N : Type*} [Finite ι] [CommRing R] [IsDomain R] [CharZero R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] {P : RootSystem ι R M N} [P.IsCrystallographic] {b : P.Base} [Fintype ι] (i j : b.support) attribute [local simp] Ring.lie_def Matrix.mul_apply Matrix.one_apply Matrix.diagonal_apply /-- Lemma 3.3 (a) from [Geck](Geck2017). -/ lemma lie_h_e : ⁅h j, e i⁆ = b.cartanMatrix i j • e i := by classical ext (k | k) (l | l) · simp [h, e] · simp only [h, e, Ring.lie_def, Matrix.sub_apply, Matrix.mul_apply, Fintype.sum_sum_type, Matrix.fromBlocks_apply₁₂, Matrix.zero_apply, zero_mul, add_zero, Finset.sum_const_zero] rw [Finset.sum_eq_ite l (by aesop)] aesop · simp only [h, e] aesop · simp only [h, e, indexNeg_neg, Ring.lie_def, Matrix.sub_apply, Matrix.mul_apply, Fintype.sum_sum_type, Matrix.fromBlocks_apply₂₁, Matrix.zero_apply, Matrix.fromBlocks_apply₁₂, Matrix.of_apply, mul_ite, mul_one, mul_zero, ite_self, Finset.sum_const_zero, Matrix.fromBlocks_apply₂₂, zero_add, ite_mul, zero_mul, Matrix.smul_apply, smul_ite, smul_add, zsmul_eq_mul, smul_zero] rw [← Finset.sum_sub_distrib, ← Finset.sum_subset (Finset.subset_univ {k, l}) (by aesop)] rcases eq_or_ne k l with rfl | hkl; · simp [P.ne_zero i] simp only [Matrix.diagonal_apply, ite_mul, zero_mul, mul_ite, mul_zero, Finset.sum_sub_distrib, Finset.mem_singleton, Finset.sum_singleton, Finset.sum_insert, hkl, not_false_eq_true, reduceIte, right_eq_add, ite_self, add_zero, zero_add, ite_sub_ite, sub_self, Base.cartanMatrix, Base.cartanMatrixIn_def] refine ite_congr rfl (fun hkil ↦ ?_) (fun _ ↦ rfl) simp only [pairingIn_eq_add_of_root_eq_add hkil, Int.cast_add] ring /-- Lemma 3.3 (b) from [Geck](Geck2017). -/ lemma lie_h_f : ⁅h j, f i⁆ = -b.cartanMatrix i j • f i := by classical suffices ω b * ⁅h j, f i⁆ = ω b * (-b.cartanMatrix i j • f i) by replace this := congr_arg (ω b * ·) this simpa [← mul_assoc, ω_mul_ω] using this calc ω b * ⁅h j, f i⁆ = ω b * (h j * f i - f i * h j) := by rw [Ring.lie_def] _ = - (h j * e i - e i * h j) * ω b := ?_ _ = - ⁅h j, e i⁆ * ω b := by rw [Ring.lie_def] _ = - (b.cartanMatrix i j • e i) * ω b := by rw [lie_h_e] _ = ω b * (-b.cartanMatrix i j • f i) := ?_ · rw [mul_sub, ← mul_assoc, ← mul_assoc, ω_mul_h, ω_mul_f, mul_assoc, mul_assoc, ω_mul_f, ω_mul_h, neg_sub, neg_mul, neg_mul, mul_neg, sub_mul, mul_assoc, mul_assoc] abel · rw [Matrix.mul_smul, ω_mul_f] simp [mul_assoc] variable [P.IsReduced] /-- An auxiliary lemma en route to `RootPairing.Base.lie_e_f_same`. -/ private lemma lie_e_f_same_aux (k : ι) (hki : k ≠ i) (hki' : k ≠ P.reflectionPerm i i) : ⁅e i, f i⁆ (Sum.inr k) (Sum.inr k) = h i (Sum.inr k) (Sum.inr k) := by classical have h_lin_ind : LinearIndependent R ![P.root i, P.root k] := by rw [LinearIndependent.pair_symm_iff, IsReduced.linearIndependent_iff]; aesop suffices (∑ x, if P.root k = P.root i + P.root x then (P.chainBotCoeff i x + 1 : R) * (P.chainTopCoeff i k + 1) else 0) - (∑ x, if P.root k = P.root x - P.root i then (P.chainTopCoeff i x + 1 : R) * (P.chainBotCoeff i k + 1) else 0) = P.chainBotCoeff i k - P.chainTopCoeff i k by have aux (x : ι) : P.root x = P.root k - P.root i ↔ P.root k = P.root i + P.root x := by rw [eq_sub_iff_add_eq', eq_comm] have aux' (x : ι) : P.root x = P.root i + P.root k ↔ P.root k = P.root x - P.root i := by rw [eq_sub_iff_add_eq', eq_comm] simpa [e, f, h, hki, hki', aux, aux', ← ite_and, ← P.chainBotCoeff_sub_chainTopCoeff h_lin_ind] rcases exists_or_forall_not (fun x ↦ P.root k = P.root i + P.root x) with ⟨x, hx⟩ | h₁ <;> rcases exists_or_forall_not (fun x ↦ P.root k = P.root x - P.root i) with ⟨y, hy⟩ | h₂ · have h_lin_ind_x : LinearIndependent R ![P.root i, P.root x] := by simpa [hx] using h_lin_ind have h_lin_ind_y : LinearIndependent R ![P.root i, P.root y] := by rw [← add_eq_of_eq_sub hy, add_comm]; simpa have hx' : P.chainBotCoeff i k = P.chainBotCoeff i x + 1 := chainBotCoeff_of_add h_lin_ind_x (add_comm (P.root i) _ ▸ hx) have hy' : P.chainTopCoeff i k = P.chainTopCoeff i y + 1 := chainTopCoeff_of_sub h_lin_ind_y hy rw [Finset.sum_eq_single_of_mem x (Finset.mem_univ _) (by aesop), Finset.sum_eq_single_of_mem y (Finset.mem_univ _) (by aesop)] simp only [hx, hy.symm, hx', hy', reduceIte, Nat.cast_add] ring · simp_rw [if_neg (h₂ _), Finset.sum_const_zero, sub_zero] replace h₂ : P.chainTopCoeff i k = 0 := P.chainTopCoeff_eq_zero_iff.mpr <| Or.inr fun ⟨x, hx⟩ ↦ h₂ x <| by simp [hx] have h_lin_ind_x : LinearIndependent R ![P.root i, P.root x] := by simpa [hx] using h_lin_ind have hx' : P.chainBotCoeff i k = P.chainBotCoeff i x + 1 := chainBotCoeff_of_add h_lin_ind_x (add_comm (P.root i) _ ▸ hx) simp [hx, hx', h₂] · simp_rw [if_neg (h₁ _), Finset.sum_const_zero, zero_sub] replace h₁ : P.chainBotCoeff i k = 0 := P.chainBotCoeff_eq_zero_iff.mpr <| Or.inr fun ⟨x, hx⟩ ↦ h₁ x <| by simp [hx] have h_lin_ind_y : LinearIndependent R ![P.root i, P.root y] := by rw [← add_eq_of_eq_sub hy, add_comm]; simpa have hy' : P.chainTopCoeff i k = P.chainTopCoeff i y + 1 := chainTopCoeff_of_sub h_lin_ind_y hy simp [hy, hy', h₁] · suffices P.chainBotCoeff i k = 0 ∧ P.chainTopCoeff i k = 0 by simp [h₁, h₂, this] exact ⟨P.chainBotCoeff_eq_zero_iff.mpr <| Or.inr fun ⟨x, hx⟩ ↦ h₁ x <| by simp [hx], P.chainTopCoeff_eq_zero_iff.mpr <| Or.inr fun ⟨x, hx⟩ ↦ h₂ x <| by simp [hx]⟩ /-- Lemma 3.4 from [Geck](Geck2017). -/ lemma lie_e_f_same : ⁅e i, f i⁆ = h i := by letI := P.indexNeg have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M classical ext (k | k) (l | l) · simp [e, f, h] · have h₁ (x : ι) : ¬ (P.root x = P.root l - P.root i ∧ k = i ∧ x = -i) := by simp only [not_and] rintro contra rfl rfl simp [P.ne_zero, sub_eq_add_neg] at contra have h₂ (x : ι) : ¬ (P.root x = P.root i + P.root l ∧ k = i ∧ x = i) := by simp only [not_and] rintro contra rfl rfl simp [P.ne_zero] at contra simp [e, f, h, h₁, h₂, - indexNeg_neg, ← ite_and] · simp [e, f, h] · rcases eq_or_ne k i with rfl | hki · have hx (x : ι) : ¬ (P.root x = P.root i + P.root l ∧ P.root i = P.root x - P.root i) := by rintro ⟨-, contra⟩ refine P.nsmul_notMem_range_root (n := 2) (i := i) ⟨x, ?_⟩ rwa [eq_sub_iff_add_eq, ← two_smul ℕ, eq_comm] at contra simp only [e, f, h, P.ne_zero, P.ne_neg, Ring.lie_def, Fintype.sum_sum_type, Matrix.sub_apply, Matrix.mul_apply, Matrix.fromBlocks_apply₂₁, Matrix.of_apply, Matrix.fromBlocks_apply₂₂, left_eq_add, zero_mul, mul_zero, ite_mul, mul_ite, ← ite_and] rw [Finset.sum_eq_single_of_mem i (Finset.mem_univ _) (by aesop)] simp [hx, eq_comm] rcases eq_or_ne k (-i) with rfl | hki' · have hx (x : ι) : ¬ (P.root x = P.root l - P.root i ∧ P.root (-i) = P.root i + P.root x) := by rintro ⟨-, contra⟩ refine P.nsmul_notMem_range_root (n := 2) (i := -i) ⟨x, ?_⟩ replace contra : P.root x = -(P.root i + P.root i) := by simpa [neg_eq_iff_add_eq_zero, ← add_assoc, add_eq_zero_iff_eq_neg'] using contra simp [contra, two_smul] have aux (x : ι) : ¬ P.root (-i) = P.root x - P.root i := by simp [P.ne_zero x, eq_comm] simp only [e, f, h, Ring.lie_def, Matrix.sub_apply, Matrix.mul_apply, Fintype.sum_sum_type, Matrix.fromBlocks_apply₂₁, Matrix.of_apply, hki, reduceIte, zero_mul, Finset.sum_const_zero, Matrix.fromBlocks_apply₂₂, mul_ite, ite_mul, mul_zero, ← ite_and, if_neg (hx _), add_zero, aux, zero_sub, Matrix.diagonal_apply] rw [Finset.sum_eq_single_of_mem i (Finset.mem_univ _) (by aesop)] simp [eq_comm, apply_ite ((- ·) : R → R)] rcases eq_or_ne k l with rfl | hkl · exact lie_e_f_same_aux i k hki hki' · simp_all [h, e, f] lemma isSl2Triple [DecidableEq ι] : IsSl2Triple (h i) (e i) (f i) where h_ne_zero := fun contra ↦ by simpa [h] using congr_fun₂ contra (.inr i) (.inr i) lie_e_f := by rw [lie_e_f_same] lie_h_e_nsmul := by rw [lie_h_e]; simp lie_h_f_nsmul := by rw [lie_h_f]; simp section lie_e_f_ne open scoped Matrix variable {i j} variable (hij : i ≠ j) omit [P.IsReduced] /-- An auxiliary lemma en route to `RootPairing.Base.lie_e_f_ne`. -/ private lemma lie_e_f_ne_aux₀ (k : b.support) (l : ι) : ⁅e i, f j⁆ (Sum.inl k) (Sum.inr l) = 0 := by classical letI := P.indexNeg have aux₁ : ∀ x ∈ Finset.univ, ¬ (P.root x = P.root i + P.root l ∧ k = j ∧ x = j) := by rintro x - ⟨hl, -, rfl⟩ exact b.sub_notMem_range_root i.property j.property ⟨-l, by simp [hl]⟩ have aux₂ : ∀ x ∈ Finset.univ, ¬ (P.root x = P.root l - P.root j ∧ k = i ∧ x = -i) := by rintro x - ⟨hl, -, rfl⟩ replace hl : P.root i = P.root j - P.root l := by simpa [neg_eq_iff_eq_neg] using hl exact b.sub_notMem_range_root i.property j.property ⟨-l, by simp [hl]⟩ simp [e, f, -indexNeg_neg, ← ite_and, Finset.sum_ite_of_false aux₁, Finset.sum_ite_of_false aux₂] include hij /-- An auxiliary lemma en route to `RootPairing.Base.lie_e_f_ne`. -/ private lemma lie_e_f_ne_aux₁ : ⁅e i, f j⁆ᵀ (Sum.inr j) = 0 := by letI := P.indexNeg classical ext (k | k) · rw [Matrix.transpose_apply, lie_e_f_ne_aux₀, Pi.zero_apply] · suffices ((if k = i then ↑|b.cartanMatrix i j| else (0 : R)) - ∑ x, if P.root x = P.root i + P.root j ∧ P.root k = P.root x - P.root j then (P.chainTopCoeff j x : R) + 1 else 0) = 0 by have hij : (j : ι) ≠ -i := by simpa using b.root_ne_neg_of_ne j.property i.property (by aesop) have aux : ∀ x ∈ Finset.univ, x ≠ j → (if x = j ∧ k = i then ↑|b.cartanMatrix i x| else 0) = (0 : R) := by aesop simpa [e, f, P.ne_zero, hij, -indexNeg_neg, -Finset.univ_eq_attach, ← ite_and, Finset.sum_eq_single_of_mem j (Finset.mem_univ _) aux] rcases eq_or_ne k i with rfl | hk; swap · rw [if_neg (by tauto), Finset.sum_ite_of_false (by aesop)]; simp by_cases hij_mem : P.root i + P.root j ∈ range P.root · obtain ⟨m, hm⟩ := hij_mem rw [Finset.sum_eq_single_of_mem m (Finset.mem_univ _) (by rintro x - hx; simp [← hm, hx]), b.abs_cartanMatrix_apply, Base.cartanMatrix, Base.cartanMatrixIn_def] have aux₁ := b.chainTopCoeff_eq_of_ne hij.symm have aux₂ := chainTopCoeff_of_add (b.linearIndependent_pair_of_ne hij.symm) hm norm_cast aesop · have aux : ∀ x ∈ Finset.univ, ¬ (P.root x = P.root i + P.root j ∧ P.root i = P.root x - P.root j) := by rintro x - ⟨hx, -⟩; exact hij_mem ⟨x, hx⟩ simp [Finset.sum_ite_of_false aux, b.cartanMatrix_apply_eq_zero_iff hij, hij_mem] /-- An auxiliary lemma en route to `RootPairing.Base.lie_e_f_ne`. -/ private lemma lie_e_f_ne_aux₂ : letI := P.indexNeg ⁅e i, f j⁆ᵀ (Sum.inr (-i)) = 0 := by letI := P.indexNeg classical ext (k | k) · rw [Matrix.transpose_apply, lie_e_f_ne_aux₀, Pi.zero_apply] · have aux : ⁅e i, f j⁆ (.inr k) (.inr (-i)) = (⁅e i, f j⁆ * ω b) (.inr k) (.inr i) := by simp [ω] rw [Matrix.transpose_apply, aux, lie_e_f_mul_ω, ← (-ω b * ⁅e j, f i⁆).transpose_apply, Matrix.transpose_mul, Matrix.mul_apply', lie_e_f_ne_aux₁ hij.symm] simp /-- Lemma 3.5 from [Geck](Geck2017). -/ lemma lie_e_f_ne [P.IsReduced] [P.IsIrreducible] : ⁅e i, f j⁆ = 0 := by letI := P.indexNeg classical ext (k | k) (l | l) · aesop (erase simp indexNeg_neg) (add simp [e, f, Matrix.mul_apply, mul_ite, ite_mul]) · exact lie_e_f_ne_aux₀ k l · have aux₁ : P.root k ≠ P.root i - P.root j := fun contra ↦ b.sub_notMem_range_root i.property j.property ⟨k, contra⟩ simp [e, f, ← sub_eq_add_neg, if_neg aux₁] · /- Geck Case 1 (covered by the auxiliary lemmas above). -/ rcases eq_or_ne l j with rfl | h₃ · rw [← ⁅e i, f j⁆.transpose_apply, lie_e_f_ne_aux₁ hij, Pi.zero_apply, Matrix.zero_apply] rcases eq_or_ne l (-i) with rfl | h₄ · rw [← ⁅e i, f j⁆.transpose_apply, lie_e_f_ne_aux₂ hij, Pi.zero_apply, Matrix.zero_apply] /- Geck Case 2. It's all just definition unfolding and case analysis: the only real content is the external lemma `chainBotCoeff_mul_chainTopCoeff`. -/ suffices (∑ x, if P.root x = P.root l - P.root j ∧ P.root k = P.root i + P.root x then ((P.chainBotCoeff i x : R) + 1) * (P.chainTopCoeff j l + 1) else 0) = (∑ x, if P.root x = P.root i + P.root l ∧ P.root k = P.root x - P.root j then ((P.chainTopCoeff j x : R) + 1) * (P.chainBotCoeff i l + 1) else 0) by have h₁ : ∀ x ∈ Finset.univ, ¬ ((x = i ∧ l = -i) ∧ k = -j) := by rintro - - ⟨⟨-, contra⟩, -⟩; contradiction have h₂ : ∀ x ∈ Finset.univ, ¬ ((x = j ∧ l = j) ∧ k = i) := by rintro - - ⟨⟨-, contra⟩, -⟩; contradiction rw [← sub_eq_zero] at this simpa [e, f, ← ite_and, Finset.sum_ite_of_false h₁, Finset.sum_ite_of_false h₂, -indexNeg_neg, -Finset.univ_eq_attach] by_cases h₅ : P.root l + P.root i - P.root j ∈ range P.root; swap · have aux₃ : ∀ x ∈ Finset.univ, ¬ (P.root x = P.root i + P.root l ∧ P.root k = P.root x - P.root j) := by rintro x - ⟨hx, hx'⟩; exact h₅ ⟨k, by rw [hx', hx]; abel⟩ have aux₄ : ∀ x ∈ Finset.univ, ¬ (P.root x = P.root l - P.root j ∧ P.root k = P.root i + P.root x) := by rintro x - ⟨hx, hx'⟩; exact h₅ ⟨k, by rw [hx', hx]; abel⟩ simp [Finset.sum_ite_of_false aux₃, Finset.sum_ite_of_false aux₄] by_cases h₆ : P.root l + P.root i ∈ range P.root; swap · have h₇ : P.root l - P.root j ∉ range P.root := by rwa [b.root_sub_mem_iff_root_add_mem i j l (by aesop) i.property j.property (by aesop) (by aesop) h₅] have aux₃ : ∀ x ∈ Finset.univ, ¬ (P.root x = P.root i + P.root l ∧ P.root k = P.root x - P.root j) := by rintro x - ⟨hx, -⟩; exact h₆ ⟨x, by rw [hx]; abel⟩ have aux₄ : ∀ x ∈ Finset.univ, ¬ (P.root x = P.root l - P.root j ∧ P.root k = P.root i + P.root x) := by rintro x - ⟨hx, hx'⟩; exact h₇ ⟨x, hx⟩ simp [Finset.sum_ite_of_false aux₃, Finset.sum_ite_of_false aux₄] obtain ⟨m, hm : P.root m = P.root l - P.root j⟩ := b.root_sub_root_mem_of_mem_of_mem i j l (by aesop) i.property j.property h₅ h₃ h₆ obtain ⟨l', hl'⟩ := h₆ by_cases hk : P.root k = P.root l + P.root i - P.root j; swap · grind have aux₃ (x) (hx : x ≠ m) : ¬ (P.root x = P.root l - P.root j ∧ P.root k = P.root i + P.root x) := by grind [EmbeddingLike.apply_eq_iff_eq] have aux₄ (x) (hx : x ≠ l') : ¬ (P.root x = P.root i + P.root l ∧ P.root k = P.root x - P.root j) := by grind [EmbeddingLike.apply_eq_iff_eq] rw [Finset.sum_eq_single_of_mem m (Finset.mem_univ _) (by rintro x - h; rw [if_neg (aux₃ _ h)]), Finset.sum_eq_single_of_mem l' (Finset.mem_univ _) (by rintro x - h; rw [if_neg (aux₄ _ h)]), if_pos (⟨hm, by rw [hm, hk]; abel⟩), if_pos ⟨by rw [hl', add_comm], by rw [hl', hk]⟩] have := chainBotCoeff_mul_chainTopCoeff i.property j.property (by aesop) hl'.symm hm.symm h₅ norm_cast end lie_e_f_ne end RootPairing.GeckConstruction
.lake/packages/mathlib/Mathlib/LinearAlgebra/RootSystem/GeckConstruction/Semisimple.lean
import Mathlib.Algebra.Lie.Matrix import Mathlib.Algebra.Lie.Semisimple.Lemmas import Mathlib.Algebra.Lie.Weights.Linear import Mathlib.LinearAlgebra.RootSystem.GeckConstruction.Basic import Mathlib.RingTheory.Finiteness.Nilpotent /-! # Geck's construction of a Lie algebra associated to a root system yields semisimple algebras This file contains a proof that `RootPairing.GeckConstruction.lieAlgebra` yields semisimple Lie algebras. ## Main definitions: * `RootPairing.GeckConstruction.trace_toEnd_eq_zero`: the Geck construction yields trace-free matrices. * `RootPairing.GeckConstruction.instIsIrreducible`: the defining representation of the Geck construction is irreducible. * `RootPairing.GeckConstruction.instHasTrivialRadical`: the Geck construction yields semisimple Lie algebras. -/ noncomputable section namespace RootPairing.GeckConstruction open Function Submodule open Set hiding diagonal open scoped Matrix attribute [local simp] Ring.lie_def Matrix.mul_apply Matrix.one_apply Matrix.diagonal_apply section IsDomain variable {ι R M N : Type*} [CommRing R] [IsDomain R] [CharZero R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] {P : RootPairing ι R M N} [P.IsCrystallographic] [P.IsReduced] {b : P.Base} [Fintype ι] [DecidableEq ι] (i : b.support) /-- An auxiliary lemma en route to `RootPairing.GeckConstruction.isNilpotent_e`. -/ private lemma isNilpotent_e_aux {j : ι} (n : ℕ) (h : letI _i := P.indexNeg; j ≠ -i) : (e i ^ n).col (.inr j) = 0 ∨ ∃ (k : ι) (x : ℕ), P.root k = P.root j + n • P.root i ∧ (e i ^ n).col (.inr j) = x • Pi.single (.inr k) 1 := by have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M letI := P.indexNeg have aux (n : ℕ) : (e i ^ (n + 1)).col (.inr j) = (e i).mulVec ((e i ^ n).col (.inr j)) := by rw [pow_succ', ← Matrix.mulVec_single_one, ← Matrix.mulVec_mulVec]; simp induction n with | zero => exact Or.inr ⟨j, 1, by simp, by ext; simp [Pi.single_apply]⟩ | succ n ih => rcases ih with hn | ⟨k, x, hk₁, hk₂⟩ · left; simp [aux, hn] rw [aux, hk₂, Matrix.mulVec_smul] have hki : k ≠ -i := by rintro rfl replace hk₁ : P.root (-j) = (n + 1) • P.root i := by simp only [indexNeg_neg, root_reflectionPerm, reflection_apply_self, neg_eq_iff_add_eq_zero, add_smul, one_smul] at hk₁ ⊢ rw [← hk₁] module rcases n.eq_zero_or_pos with rfl | hn · apply h rw [zero_add, one_smul, EmbeddingLike.apply_eq_iff_eq] at hk₁ simp [← hk₁, -indexNeg_neg] · have _i : (n + 1).AtLeastTwo := ⟨by cutsat⟩ exact P.nsmul_notMem_range_root (n := n + 1) (i := i) ⟨-j, hk₁⟩ by_cases hij : P.root j + (n + 1) • P.root i ∈ range P.root · obtain ⟨l, hl⟩ := hij right refine ⟨l, x * (P.chainBotCoeff i k + 1), hl, ?_⟩ ext (m | m) · simp [e, -indexNeg_neg, hki] · rcases eq_or_ne m l with rfl | hml · replace hl : P.root m = P.root i + P.root k := by rw [hl, hk₁]; module simp [e, -indexNeg_neg, hl, mul_add] · replace hl : P.root m ≠ P.root i + P.root k := fun contra ↦ hml (P.root.injective <| by rw [hl, contra, hk₁]; module) simp [e, -indexNeg_neg, hml, hl] · left ext (l | l) · simp [e, -indexNeg_neg, hki] · replace hij : P.root l ≠ P.root i + P.root k := fun contra ↦ hij ⟨l, by rw [contra, hk₁]; module⟩ simp [e, -indexNeg_neg, hij] lemma isNilpotent_e : IsNilpotent (e i) := by classical have : Module.IsReflexive R M := .of_isPerfPair P.toLinearMap have : IsAddTorsionFree M := .of_noZeroSMulDivisors R M letI := P.indexNeg rw [Matrix.isNilpotent_iff_forall_col] have case_inl (j : b.support) : (e i ^ 2).col (Sum.inl j) = 0 := by ext (k | k) · simp [e, sq, ne_neg P i, -indexNeg_neg] · have aux : ∀ x : ι, x ∈ Finset.univ → ¬ (x = i ∧ P.root k = P.root i + P.root x) := by suffices P.root k ≠ (2 : ℕ) • P.root i by simpa [two_smul] exact fun contra ↦ P.nsmul_notMem_range_root (n := 2) (i := i) ⟨k, contra⟩ simp [e, sq, -indexNeg_neg, ← ite_and, Finset.sum_ite_of_false aux] rintro (j | j) · exact ⟨2, case_inl j⟩ · by_cases hij : j = -i · use 2 + 1 replace hij : (e i).col (Sum.inr j) = u i := by ext (k | k) · simp [e, -indexNeg_neg, Pi.single_apply, hij] · have hk : P.root k ≠ P.root i + P.root j := by simp [hij, P.ne_zero k] simp [e, -indexNeg_neg, hk] rw [pow_succ, ← Matrix.mulVec_single_one, ← Matrix.mulVec_mulVec] simp [hij, case_inl i] use P.chainTopCoeff i j + 1 rcases isNilpotent_e_aux i (P.chainTopCoeff i j + 1) hij with this | ⟨k, x, hk₁, -⟩ · assumption exfalso replace hk₁ : P.root j + (P.chainTopCoeff i j + 1) • P.root i ∈ range P.root := ⟨k, hk₁⟩ have hij' : LinearIndependent R ![P.root i, P.root j] := by apply IsReduced.linearIndependent P ?_ ?_ · rintro rfl apply P.nsmul_notMem_range_root (n := P.chainTopCoeff i i + 2) (i := i) convert hk₁ using 1 module · contrapose! hij rw [root_eq_neg_iff] at hij rw [hij, ← indexNeg_neg, neg_neg] rw [root_add_nsmul_mem_range_iff_le_chainTopCoeff hij'] at hk₁ cutsat lemma isNilpotent_f : IsNilpotent (f i) := by obtain ⟨n, hn⟩ := isNilpotent_e i suffices (ω b) * (f i ^ n) = 0 from ⟨n, by simpa [← mul_assoc] using congr_arg (ω b * ·) this⟩ suffices (ω b) * (f i ^ n) = (e i ^ n) * (ω b) by simp [this, hn] clear hn induction n with | zero => simp | succ n ih => rw [pow_succ, pow_succ, ← mul_assoc, ih, mul_assoc, ω_mul_f, ← mul_assoc] omit [P.IsReduced] [IsDomain R] in @[simp] lemma trace_h_eq_zero : (h i).trace = 0 := by letI _i := P.indexNeg suffices ∑ j, P.pairingIn ℤ j i = 0 by simp only [h_eq_diagonal, Matrix.trace_diagonal, Fintype.sum_sum_type, Finset.univ_eq_attach, Sum.elim_inl, Pi.zero_apply, Finset.sum_const_zero, Sum.elim_inr, zero_add] norm_cast suffices ∑ j, P.pairingIn ℤ (-j) i = ∑ j, P.pairingIn ℤ j i from eq_zero_of_neg_eq <| by simpa using this let σ : ι ≃ ι := Function.Involutive.toPerm _ neg_involutive exact σ.sum_comp (P.pairingIn ℤ · i) open LinearMap LieModule in /-- This is the main result of lemma 4.1 from [Geck](Geck2017). -/ lemma trace_toEnd_eq_zero (x : lieAlgebra b) : trace R _ (toEnd R _ (b.support ⊕ ι → R) x) = 0 := by obtain ⟨x, hx⟩ := x suffices trace R _ x.toLin' = 0 by simpa refine LieAlgebra.trace_toEnd_eq_zero ?_ hx rintro - ((⟨i, rfl⟩ | ⟨i, rfl⟩) | ⟨i, rfl⟩) · simp · simpa using Matrix.isNilpotent_trace_of_isNilpotent (isNilpotent_e i) · simpa using Matrix.isNilpotent_trace_of_isNilpotent (isNilpotent_f i) end IsDomain section Field variable {ι K M N : Type*} [Field K] [CharZero K] [DecidableEq ι] [Fintype ι] [AddCommGroup M] [Module K M] [AddCommGroup N] [Module K N] {P : RootSystem ι K M N} [P.IsCrystallographic] {b : P.Base} open LieModule Matrix local notation "H" => cartanSubalgebra' b private lemma instIsIrreducible_aux₀ {U : LieSubmodule K H (b.support ⊕ ι → K)} (χ : H → K) (hχ : χ ≠ 0) (hχ' : genWeightSpace U χ ≠ ⊥) : ∃ i, v b i ∈ (genWeightSpace U χ).map U.incl := by suffices ∀ {w : b.support ⊕ ι → K} (hw₀ : w ≠ 0) (hw : w ∈ genWeightSpace (b.support ⊕ ι → K) χ), ∃ (i : ι) (t : K), t • w = v b i by obtain ⟨w, hw, hw₀⟩ : ∃ w ∈ genWeightSpace U χ, w ≠ 0 := by simpa only [ne_eq, LieSubmodule.eq_bot_iff, not_forall, exists_prop] using hχ' replace hw : U.incl w ∈ genWeightSpace (b.support ⊕ ι → K) χ := map_genWeightSpace_le (f := U.incl) <| by simpa obtain ⟨i, t, hi : t • w = v b i⟩ := this (by simpa) hw use i rw [map_genWeightSpace_eq_of_injective U.injective_incl, LieSubmodule.range_incl, ← hi, LieSubmodule.mem_inf] exact ⟨SMulMemClass.smul_mem _ hw, SMulMemClass.smul_mem _ w.property⟩ clear! U intro w hw₀ hw have aux (d : b.support ⊕ ι → K) (x : H) (hdx : x = diagonal d) : w ∈ genWeightSpaceOf (b.support ⊕ ι → K) (χ x) x ↔ ∃ k, diagonal ((d - χ x • 1) ^ k) *ᵥ w = 0 := by set μ := χ x obtain ⟨⟨x, hx⟩, hx'⟩ := x replace hdx : x = diagonal d := by simpa using hdx have this (d : b.support ⊕ ι → K) (μ : K) : (diagonal d).toLin' - μ • 1 = (diagonal (d - μ • 1)).toLin' := by aesop (add simp Pi.single_apply) simp [mem_genWeightSpaceOf, hdx, this, ← toLin'_pow, diagonal_pow] obtain ⟨i, hi⟩ : ∃ i, w (Sum.inr i) ≠ 0 := by obtain ⟨l, hl⟩ : ∃ l, χ (h' l) ≠ 0 := by replace hw₀ : genWeightSpace (b.support ⊕ ι → K) χ ≠ ⊥ := by contrapose! hw₀; rw [LieSubmodule.eq_bot_iff] at hw₀; exact hw₀ _ hw let χ' : H →ₗ[K] K := (Weight.mk χ hw₀).toLinear replace hχ : χ' ≠ 0 := by contrapose! hχ; ext x; simpa using LinearMap.congr_fun hχ x contrapose! hχ apply LinearMap.ext_on (span_range_h'_eq_top b) rintro - ⟨l, rfl⟩ simp [χ', hχ l] contrapose! hw₀ suffices ∀ i : b.support, w (Sum.inl i) = 0 by ext (k | k) <;> simp [hw₀, this] intro i replace hw := genWeightSpace_le_genWeightSpaceOf (b.support ⊕ ι → K) (h' l) χ hw rw [aux (Sum.elim 0 (P.pairingIn ℤ · l)) (h' l) (h_eq_diagonal l)] at hw obtain ⟨k, hk⟩ := hw simpa [mulVec_eq_sum, diagonal_apply, hl] using congr_fun hk (Sum.inl i) refine ⟨i, (w (Sum.inr i))⁻¹, ?_⟩ suffices ∃ d : ι → K, (∀ i, d i ≠ 0) ∧ Pairwise ((· ≠ ·) on d) ∧ diagonal (Sum.elim 0 d) ∈ cartanSubalgebra b by obtain ⟨d, hd₀, hd₁, hd₂⟩ := this let x : H := ⟨⟨diagonal (Sum.elim 0 d), cartanSubalgebra_le_lieAlgebra hd₂⟩, hd₂⟩ replace hw := genWeightSpace_le_genWeightSpaceOf (b.support ⊕ ι → K) x χ hw rw [aux (Sum.elim 0 d) x rfl] at hw obtain ⟨k, hk⟩ := hw obtain ⟨hχx, hk₀⟩ : d i = χ x ∧ k ≠ 0 := by simpa [hi, mulVec_eq_sum, diagonal_apply, sub_eq_zero] using congr_fun hk (Sum.inr i) ext (j | j) · have : χ x ≠ 0 := hχx ▸ hd₀ i simpa [hi, mulVec_eq_sum, diagonal_apply, hk₀, this] using congr_fun hk (Sum.inl j) · rcases eq_or_ne i j with rfl | hij · simp [hi] · suffices d j ≠ χ x by simpa [mulVec_eq_sum, diagonal_apply, sub_eq_zero, this, hij, hi] using congr_fun hk (Sum.inr j) rw [← hχx] exact hd₁ <| by simp [hij.symm] simp_rw [cartanSubalgebra, LieSubalgebra.mem_mk_iff', diagonal_elim_mem_span_h_iff] exact (exists_congr fun d ↦ by tauto).mp b.exists_mem_span_pairingIn_ne_zero_and_pairwise_ne private lemma instIsIrreducible_aux₁ (U : LieSubmodule K H (b.support ⊕ ι → K)) (hU : ¬ U ≤ genWeightSpace (b.support ⊕ ι → K) 0) : ∃ i, v b i ∈ U := by suffices ∃ χ : H → K, χ ≠ 0 ∧ genWeightSpace U χ ≠ ⊥ by obtain ⟨χ, hχ₀, hχ⟩ := this obtain ⟨i, hi⟩ := instIsIrreducible_aux₀ χ hχ₀ hχ exact ⟨i, LieSubmodule.map_incl_le hi⟩ contrapose! hU refine le_trans ?_ (map_genWeightSpace_le (f := U.incl)) suffices genWeightSpace U (0 : H → K) = ⊤ by simp [this] have : ⨆ (χ : H → K), ⨆ (_ : χ ≠ 0), (⊥ : LieSubmodule K H U) = ⊥ := biSup_const ⟨1, one_ne_zero⟩ rw [← iSup_genWeightSpace_eq_top K H U, iSup_split_single _ 0, biSup_congr hU, this, sup_bot_eq] private lemma instIsIrreducible_aux₂ [P.IsReduced] [P.IsIrreducible] {U : LieSubmodule K (lieAlgebra b) (b.support ⊕ ι → K)} {i : ι} (hi : v b i ∈ U) : U = ⊤ := by letI _i := P.indexNeg have hωu (i : b.support) : ω b *ᵥ (u i) = u i := by ext (j | j) <;> simp [ω, u, Pi.single_apply, one_apply] have hωv (i : ι) : ω b *ᵥ (v b i) = v b (-i) := by ext (j | j) <;> simp [ω, v, Pi.single_apply] obtain ⟨j, hj⟩ : ∃ j : b.support, u j ∈ U := by revert U apply b.induction_add i · intro i h U hi replace hi : v b i ∈ ωConjLieSubmodule U := by simpa [hωv] obtain ⟨j, hj⟩ := h hi exact ⟨j, by simpa [hωu] using hj⟩ · intro j hj U hj' let f' : lieAlgebra b := ⟨f ⟨j, hj⟩, f_mem_lieAlgebra _⟩ have : ⁅f', v b j⁆ = u ⟨j, hj⟩ := f_lie_v_same ⟨j, hj⟩ replace this : u ⟨j, hj⟩ ∈ U := by rw [← this] exact U.lie_mem (x := f') hj' exact ⟨⟨j, hj⟩, this⟩ · intro j k l h₁ h₂ hk U hl have : ⁅f ⟨k, hk⟩, v b l⁆ = (P.chainTopCoeff k l + 1 : K) • v b j := f_lie_v_ne h₁ replace this : (P.chainTopCoeff k l + 1 : K) • v b j ∈ U := by rw [← this] let f' : lieAlgebra b := ⟨f ⟨k, hk⟩, f_mem_lieAlgebra _⟩ change ⁅f', v b l⁆ ∈ U exact U.lie_mem hl exact h₂ <| (U.smul_mem_iff (by norm_cast)).mp this have aux (k : b.support) : u k ∈ U := by refine b.induction_on_cartanMatrix (fun k : b.support ↦ u k ∈ U) hj (fun l l' hl₁ hl₂ ↦ ?_) suffices (↑|b.cartanMatrix l' l| : K) • u l' ∈ U from (U.smul_mem_iff (by simpa)).mp this rw [Int.cast_smul_eq_zsmul, ← lie_e_lie_f_apply l' l] let e' : lieAlgebra b := ⟨e l', e_mem_lieAlgebra l'⟩ let f' : lieAlgebra b := ⟨f l', f_mem_lieAlgebra l'⟩ change ⁅e', ⁅f', u l⁆⁆ ∈ U exact U.lie_mem <| U.lie_mem hl₁ clear! j i suffices ∀ j, v b j ∈ U by simp_rw [← LieSubmodule.toSubmodule_eq_top, eq_top_iff, ← (Pi.basisFun K (b.support ⊕ ι)).span_eq, Submodule.span_le, range_subset_iff, Pi.basisFun_apply] aesop intro j revert U apply b.induction_add j · intro j h U hU suffices v b j ∈ ωConjLieSubmodule U by simpa [hωv] using this exact h fun k ↦ by simp [hωu, hU] · intro k hk U aux have : ⁅e ⟨k, hk⟩, u ⟨k, hk⟩⁆ = (2 : K) • v b k := by simpa [-lie_apply] using e_lie_u ⟨k, hk⟩ ⟨k, hk⟩ let e' : lieAlgebra b := ⟨e ⟨k, hk⟩, e_mem_lieAlgebra ⟨k, hk⟩⟩ change ⁅e', u ⟨k, hk⟩⁆ = _ at this replace aux := U.lie_mem (x := e') <| aux ⟨k, hk⟩ rw [this] at aux exact (U.smul_mem_iff two_ne_zero).mp aux · intro k l m hm hk hl U aux rw [add_comm] at hm let e' : lieAlgebra b := ⟨e ⟨l, hl⟩, e_mem_lieAlgebra _⟩ have : ⁅e', v b k⁆ = (P.chainBotCoeff l k + 1 : K) • v b m := e_lie_v_ne hm replace this : (P.chainBotCoeff l k + 1 : K) • v b m ∈ U := by rw [← this] exact U.lie_mem (hk aux) exact (U.smul_mem_iff (by norm_cast)).mp this lemma coe_genWeightSpace_zero_eq_span_range_u : genWeightSpace (b.support ⊕ ι → K) (0 : H → K) = span K (range <| u (b := b)) := by refine le_antisymm (fun w hw ↦ Pi.mem_span_range_single_inl_iff.mpr fun i ↦ ?_) ?_ · replace hw : ∀ (x) (hx : x ∈ lieAlgebra b), ⟨x, hx⟩ ∈ H → ∃ k, (x.toLin' ^ k) w = 0 := by simpa [mem_genWeightSpace] using hw obtain ⟨j, hj⟩ : ∃ j : b.support, P.pairingIn ℤ i j ≠ 0 := by obtain ⟨j, hj, hj₀⟩ := b.exists_mem_support_pos_pairingIn_ne_zero i rw [ne_eq, P.pairingIn_eq_zero_iff] at hj₀ exact ⟨⟨j, hj⟩, hj₀⟩ obtain ⟨k, hk⟩ := hw (h j) (h_mem_lieAlgebra j) (h_mem_cartanSubalgebra' j _) simpa [h_eq_diagonal, ← toLin'_pow, fromBlocks_diagonal_pow, diagonal_pow, mulVec_eq_sum, diagonal_apply, hj] using congr_fun hk (Sum.inr i) · rw [span_le] rintro - ⟨i, rfl⟩ simp only [SetLike.mem_coe, LieSubmodule.mem_toSubmodule, mem_genWeightSpace] rintro ⟨⟨x, -⟩, hx⟩ exact ⟨1, funext fun j ↦ by simpa using apply_sum_inl_eq_zero_of_mem_span_h i j hx⟩ -- TODO Turn this `Fact` into a lemma: it is always true and may be proved via Perron-Frobenius -- See https://leanprover.zulipchat.com/#narrow/channel/116395-maths/topic/Eigenvalues.20of.20Cartan.20matrices/near/516844801 variable [Fact ((4 - b.cartanMatrix).det ≠ 0)] [P.IsReduced] [P.IsIrreducible] /-- Lemma 4.2 from [Geck](Geck2017). -/ instance instIsIrreducible [Nonempty ι] : LieModule.IsIrreducible K (lieAlgebra b) (b.support ⊕ ι → K) := by refine LieModule.IsIrreducible.mk fun U hU ↦ ?_ suffices ∃ i, v b i ∈ U by obtain ⟨i, hi⟩ := this; exact instIsIrreducible_aux₂ hi let U' : LieSubmodule K H (b.support ⊕ ι → K) := {U with lie_mem := U.lie_mem} apply instIsIrreducible_aux₁ U' contrapose! hU replace hU : U ≤ span K (range (u (b := b))) := by rwa [← coe_genWeightSpace_zero_eq_span_range_u] refine (LieSubmodule.eq_bot_iff _).mpr fun x hx ↦ ?_ obtain ⟨c, hc⟩ : ∃ c : b.support → K, ∑ i, c i • u i = x := (mem_span_range_iff_exists_fun K).mp <| hU hx suffices c = 0 by simp [this, ← hc] have hCM : (4 - b.cartanMatrix).det ≠ 0 := Fact.out contrapose! hCM suffices ((Int.castRingHom K).mapMatrix (4 - b.cartanMatrix)).det = 0 by simpa only [← RingHom.map_det, eq_intCast, Int.cast_eq_zero] using this rw [← exists_mulVec_eq_zero_iff] suffices (b.cartanMatrix.map abs).map (↑) *ᵥ c = 0 from ⟨c, hCM, by simpa using this⟩ ext j suffices ∑ k, c k * |b.cartanMatrix j k| = 0 by simpa [mulVec_eq_sum, -Base.cartanMatrix_map_abs] by_contra contra have key : v b j ∈ U := by have : ⁅e j, x⁆ ∈ U := U.lie_mem (x := ⟨e j, e_mem_lieAlgebra j⟩) hx have aux (k : b.support) : ⁅e j, u k⁆ = |b.cartanMatrix j k| • v b j := e_lie_u j k simp_rw [← hc, lie_sum, lie_smul, aux, smul_comm (M := K), ← smul_assoc, ← Finset.sum_smul, zsmul_eq_mul, mul_comm, ← LieSubmodule.mem_toSubmodule, U.smul_mem_iff contra] at this assumption have : v b j ∉ U := fun hj ↦ by simpa [v] using apply_inr_eq_zero_of_mem_span_range_u b j (hU hj) contradiction /-- Lemma 4.3 from [Geck](Geck2017). -/ instance instHasTrivialRadical [IsAlgClosed K] : LieAlgebra.HasTrivialRadical K (lieAlgebra b) := by cases isEmpty_or_nonempty ι · infer_instance · exact LieAlgebra.hasTrivialRadical_of_isIrreducible_of_isFaithful K _ _ trace_toEnd_eq_zero end Field end RootPairing.GeckConstruction
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorPower/Basic.lean
import Mathlib.LinearAlgebra.PiTensorProduct import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Algebra.DirectSum.Algebra /-! # Tensor power of a semimodule over a commutative semiring We define the `n`th tensor power of `M` as the n-ary tensor product indexed by `Fin n` of `M`, `⨂[R] (i : Fin n), M`. This is a special case of `PiTensorProduct`. This file introduces the notation `⨂[R]^n M` for `TensorPower R n M`, which in turn is an abbreviation for `⨂[R] i : Fin n, M`. ## Main definitions: * `TensorPower.gsemiring`: the tensor powers form a graded semiring. * `TensorPower.galgebra`: the tensor powers form a graded algebra. ## Implementation notes In this file we use `ₜ1` and `ₜ*` as local notation for the graded multiplicative structure on tensor powers. Elsewhere, using `1` and `*` on `GradedMonoid` should be preferred. -/ open scoped TensorProduct /-- Homogeneous tensor powers $M^{\otimes n}$. `⨂[R]^n M` is a shorthand for `⨂[R] (i : Fin n), M`. -/ abbrev TensorPower (R : Type*) (n : ℕ) (M : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] : Type _ := ⨂[R] _ : Fin n, M variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] @[inherit_doc] scoped[TensorProduct] notation:max "⨂[" R "]^" n:arg => TensorPower R n namespace PiTensorProduct /-- Two dependent pairs of tensor products are equal if their index is equal and the contents are equal after a canonical reindexing. -/ @[ext (iff := false)] theorem gradedMonoid_eq_of_reindex_cast {ιι : Type*} {ι : ιι → Type*} : ∀ {a b : GradedMonoid fun ii => ⨂[R] _ : ι ii, M} (h : a.fst = b.fst), reindex R (fun _ ↦ M) (Equiv.cast <| congr_arg ι h) a.snd = b.snd → a = b | ⟨ai, a⟩, ⟨bi, b⟩ => fun (hi : ai = bi) (h : reindex R (fun _ ↦ M) _ a = b) => by subst hi simp_all end PiTensorProduct namespace TensorPower open scoped TensorProduct DirectSum open PiTensorProduct /-- As a graded monoid, `⨂[R]^i M` has a `1 : ⨂[R]^0 M`. -/ instance gOne : GradedMonoid.GOne fun i => ⨂[R]^i M where one := tprod R <| @Fin.elim0 M local notation "ₜ1" => @GradedMonoid.GOne.one ℕ (fun i => ⨂[R]^i M) _ _ theorem gOne_def : ₜ1 = tprod R (@Fin.elim0 M) := rfl /-- A variant of `PiTensorProduct.tmulEquiv` with the result indexed by `Fin (n + m)`. -/ def mulEquiv {n m : ℕ} : ⨂[R]^n M ⊗[R] (⨂[R]^m) M ≃ₗ[R] (⨂[R]^(n + m)) M := (tmulEquiv R M).trans (reindex R (fun _ ↦ M) finSumFinEquiv) /-- As a graded monoid, `⨂[R]^i M` has a `(*) : ⨂[R]^i M → ⨂[R]^j M → ⨂[R]^(i + j) M`. -/ instance gMul : GradedMonoid.GMul fun i => ⨂[R]^i M where mul {i j} a b := (TensorProduct.mk R _ _).compr₂ (↑(mulEquiv : _ ≃ₗ[R] (⨂[R]^(i + j)) M)) a b local infixl:70 " ₜ* " => @GradedMonoid.GMul.mul ℕ (fun i => ⨂[R]^i M) _ _ _ _ theorem gMul_def {i j} (a : ⨂[R]^i M) (b : (⨂[R]^j) M) : a ₜ* b = @mulEquiv R M _ _ _ i j (a ⊗ₜ b) := rfl theorem gMul_eq_coe_linearMap {i j} (a : ⨂[R]^i M) (b : (⨂[R]^j) M) : a ₜ* b = ((TensorProduct.mk R _ _).compr₂ ↑(mulEquiv : _ ≃ₗ[R] (⨂[R]^(i + j)) M) : ⨂[R]^i M →ₗ[R] (⨂[R]^j) M →ₗ[R] (⨂[R]^(i + j)) M) a b := rfl variable (R M) /-- Cast between "equal" tensor powers. -/ def cast {i j} (h : i = j) : ⨂[R]^i M ≃ₗ[R] (⨂[R]^j) M := reindex R (fun _ ↦ M) (finCongr h) theorem cast_tprod {i j} (h : i = j) (a : Fin i → M) : cast R M h (tprod R a) = tprod R (a ∘ Fin.cast h.symm) := reindex_tprod _ _ @[simp] theorem cast_refl {i} (h : i = i) : cast R M h = LinearEquiv.refl _ _ := (congr_arg (reindex R fun _ ↦ M) <| finCongr_refl h).trans reindex_refl @[simp] theorem cast_symm {i j} (h : i = j) : (cast R M h).symm = cast R M h.symm := reindex_symm _ @[simp] theorem cast_trans {i j k} (h : i = j) (h' : j = k) : (cast R M h).trans (cast R M h') = cast R M (h.trans h') := reindex_trans _ _ variable {R M} @[simp] theorem cast_cast {i j k} (h : i = j) (h' : j = k) (a : ⨂[R]^i M) : cast R M h' (cast R M h a) = cast R M (h.trans h') a := reindex_reindex _ _ _ @[ext (iff := false)] theorem gradedMonoid_eq_of_cast {a b : GradedMonoid fun n => ⨂[R] _ : Fin n, M} (h : a.fst = b.fst) (h2 : cast R M h a.snd = b.snd) : a = b := by refine gradedMonoid_eq_of_reindex_cast h ?_ rw [cast] at h2 rw [← finCongr_eq_equivCast, ← h2] theorem cast_eq_cast {i j} (h : i = j) : ⇑(cast R M h) = _root_.cast (congrArg (fun i => ⨂[R]^i M) h) := by subst h rw [cast_refl] rfl variable (R) in theorem tprod_mul_tprod {na nb} (a : Fin na → M) (b : Fin nb → M) : tprod R a ₜ* tprod R b = tprod R (Fin.append a b) := by dsimp [gMul_def, mulEquiv] rw [tmulEquiv_apply R M a b] refine (reindex_tprod _ _).trans ?_ congr 1 dsimp only [Fin.append, finSumFinEquiv, Equiv.coe_fn_symm_mk] apply funext apply Fin.addCases <;> simp theorem one_mul {n} (a : ⨂[R]^n M) : cast R M (zero_add n) (ₜ1 ₜ* a) = a := by rw [gMul_def, gOne_def] induction a using PiTensorProduct.induction_on with | smul_tprod r a => rw [TensorProduct.tmul_smul, LinearEquiv.map_smul, LinearEquiv.map_smul, ← gMul_def, tprod_mul_tprod, cast_tprod] congr 2 with i rw [Fin.elim0_append] refine congr_arg a (Fin.ext ?_) simp | add x y hx hy => rw [TensorProduct.tmul_add, map_add, map_add, hx, hy] theorem mul_one {n} (a : ⨂[R]^n M) : cast R M (add_zero _) (a ₜ* ₜ1) = a := by rw [gMul_def, gOne_def] induction a using PiTensorProduct.induction_on with | smul_tprod r a => rw [← TensorProduct.smul_tmul', LinearEquiv.map_smul, LinearEquiv.map_smul, ← gMul_def, tprod_mul_tprod R a _, cast_tprod] congr 2 with i rw [Fin.append_elim0] refine congr_arg a (Fin.ext ?_) simp | add x y hx hy => rw [TensorProduct.add_tmul, map_add, map_add, hx, hy] theorem mul_assoc {na nb nc} (a : (⨂[R]^na) M) (b : (⨂[R]^nb) M) (c : (⨂[R]^nc) M) : cast R M (add_assoc _ _ _) (a ₜ* b ₜ* c) = a ₜ* (b ₜ* c) := by let mul : ∀ n m : ℕ, ⨂[R]^n M →ₗ[R] (⨂[R]^m) M →ₗ[R] (⨂[R]^(n + m)) M := fun n m => (TensorProduct.mk R _ _).compr₂ ↑(mulEquiv : _ ≃ₗ[R] (⨂[R]^(n + m)) M) -- replace `a`, `b`, `c` with `tprod R a`, `tprod R b`, `tprod R c` let e : (⨂[R]^(na + nb + nc)) M ≃ₗ[R] (⨂[R]^(na + (nb + nc))) M := cast R M (add_assoc _ _ _) let lhs : (⨂[R]^na) M →ₗ[R] (⨂[R]^nb) M →ₗ[R] (⨂[R]^nc) M →ₗ[R] (⨂[R]^(na + (nb + nc))) M := (LinearMap.llcomp R _ _ _ ((mul _ nc).compr₂ e.toLinearMap)).comp (mul na nb) have lhs_eq : ∀ a b c, lhs a b c = e (a ₜ* b ₜ* c) := fun _ _ _ => rfl let rhs : (⨂[R]^na) M →ₗ[R] (⨂[R]^nb) M →ₗ[R] (⨂[R]^nc) M →ₗ[R] (⨂[R]^(na + (nb + nc))) M := (LinearMap.llcomp R _ _ _ (LinearMap.lflip (R := R)).toLinearMap <| (LinearMap.llcomp R _ _ _ (mul na _).flip).comp (mul nb nc)).flip have rhs_eq : ∀ a b c, rhs a b c = a ₜ* (b ₜ* c) := fun _ _ _ => rfl suffices lhs = rhs from LinearMap.congr_fun (LinearMap.congr_fun (LinearMap.congr_fun this a) b) c ext a b c -- clean up simp only [e, LinearMap.compMultilinearMap_apply, lhs_eq, rhs_eq, tprod_mul_tprod, cast_tprod] congr 1 with j rw [Fin.append_assoc] refine congr_arg (Fin.append a (Fin.append b c)) (Fin.ext ?_) rw [Fin.coe_cast, Fin.coe_cast] -- for now we just use the default for the `gnpow` field as it's easier. instance gmonoid : GradedMonoid.GMonoid fun i => ⨂[R]^i M := { TensorPower.gMul, TensorPower.gOne with one_mul := fun _ => gradedMonoid_eq_of_cast (zero_add _) (one_mul _) mul_one := fun _ => gradedMonoid_eq_of_cast (add_zero _) (mul_one _) mul_assoc := fun _ _ _ => gradedMonoid_eq_of_cast (add_assoc _ _ _) (mul_assoc _ _ _) } /-- The canonical map from `R` to `⨂[R]^0 M` corresponding to the `algebraMap` of the tensor algebra. -/ def algebraMap₀ : R ≃ₗ[R] (⨂[R]^0) M := LinearEquiv.symm <| isEmptyEquiv (Fin 0) theorem algebraMap₀_eq_smul_one (r : R) : (algebraMap₀ r : (⨂[R]^0) M) = r • ₜ1 := by simp [algebraMap₀]; congr theorem algebraMap₀_one : (algebraMap₀ 1 : (⨂[R]^0) M) = ₜ1 := (algebraMap₀_eq_smul_one 1).trans (one_smul _ _) theorem algebraMap₀_mul {n} (r : R) (a : ⨂[R]^n M) : cast R M (zero_add _) (algebraMap₀ r ₜ* a) = r • a := by rw [gMul_eq_coe_linearMap, algebraMap₀_eq_smul_one, LinearMap.map_smul₂, LinearEquiv.map_smul, ← gMul_eq_coe_linearMap, one_mul] theorem mul_algebraMap₀ {n} (r : R) (a : ⨂[R]^n M) : cast R M (add_zero _) (a ₜ* algebraMap₀ r) = r • a := by rw [gMul_eq_coe_linearMap, algebraMap₀_eq_smul_one, LinearMap.map_smul, LinearEquiv.map_smul, ← gMul_eq_coe_linearMap, mul_one] theorem algebraMap₀_mul_algebraMap₀ (r s : R) : cast R M (add_zero _) (algebraMap₀ r ₜ* algebraMap₀ s) = algebraMap₀ (r * s) := by rw [← smul_eq_mul, LinearEquiv.map_smul] exact algebraMap₀_mul r (@algebraMap₀ R M _ _ _ s) instance gsemiring : DirectSum.GSemiring fun i => ⨂[R]^i M := { TensorPower.gmonoid with mul_zero := fun _ => LinearMap.map_zero _ zero_mul := fun _ => LinearMap.map_zero₂ _ _ mul_add := fun _ _ _ => LinearMap.map_add _ _ _ add_mul := fun _ _ _ => LinearMap.map_add₂ _ _ _ _ natCast := fun n => algebraMap₀ (n : R) natCast_zero := by simp only [Nat.cast_zero, map_zero] natCast_succ := fun n => by simp only [Nat.cast_succ, map_add, algebraMap₀_one] } example : Semiring (⨁ n : ℕ, ⨂[R]^n M) := by infer_instance /-- The tensor powers form a graded algebra. Note that this instance implies `Algebra R (⨁ n : ℕ, ⨂[R]^n M)` via `DirectSum.Algebra`. -/ instance galgebra : DirectSum.GAlgebra R fun i => ⨂[R]^i M where toFun := (algebraMap₀ : R ≃ₗ[R] (⨂[R]^0) M).toLinearMap.toAddMonoidHom map_one := algebraMap₀_one map_mul r s := gradedMonoid_eq_of_cast rfl (by rw [← LinearEquiv.eq_symm_apply] have := algebraMap₀_mul_algebraMap₀ (M := M) r s exact this.symm) commutes r x := gradedMonoid_eq_of_cast (add_comm _ _) (by have := (algebraMap₀_mul r x.snd).trans (mul_algebraMap₀ r x.snd).symm rw [← LinearEquiv.eq_symm_apply, cast_symm] rw [← LinearEquiv.eq_symm_apply, cast_symm, cast_cast] at this exact this) smul_def r x := gradedMonoid_eq_of_cast (zero_add x.fst).symm (by rw [← LinearEquiv.eq_symm_apply, cast_symm] exact (algebraMap₀_mul r x.snd).symm) theorem galgebra_toFun_def (r : R) : DirectSum.GAlgebra.toFun (A := fun i ↦ ⨂[R]^i M) r = algebraMap₀ r := rfl example : Algebra R (⨁ n : ℕ, ⨂[R]^n M) := by infer_instance end TensorPower
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorPower/Symmetric.lean
import Mathlib.LinearAlgebra.PiTensorProduct /-! # Symmetric tensor power of a semimodule over a commutative semiring We define the `ι`-indexed symmetric tensor power of `M` as the `PiTensorProduct` quotiented by the relation that the `tprod` of `ι` elements is equal to the `tprod` of the same elements permuted by a permutation of `ι`. We denote this space by `Sym[R] ι M`, and the canonical multilinear map from `ι → M` to `Sym[R] ι M` by `⨂ₛ[R] i, f i`. We also reserve the notation `Sym[R]^n M` for the `n`th symmetric tensor power of `M`, which is the symmetric tensor power indexed by `Fin n`. ## Main definitions: * `SymmetricPower.module`: the symmetric tensor power is a module over `R`. ## TODO: * Grading: show that there is a map `Sym[R]^i M × Sym[R]^j M → Sym[R]^(i + j) M` that is associative and commutative, and that `n ↦ Sym[R]^n M` is a graded (semi)ring and algebra. * Universal property: linear maps from `Sym[R]^n M` to `N` correspond to symmetric multilinear maps `M ^ n` to `N`. * Relate to homogneous (multivariate) polynomials of degree `n`. -/ suppress_compilation universe u v open TensorProduct Equiv variable (R ι : Type u) [CommSemiring R] (M : Type v) [AddCommMonoid M] [Module R M] (s : ι → M) /-- The relation on the `ι`-indexed tensor power of `M` where two tensors are equal if they are related by a permutation of `ι`. -/ inductive SymmetricPower.Rel : (⨂[R] _, M) → (⨂[R] _, M) → Prop | perm : (e : Perm ι) → (f : ι → M) → Rel (⨂ₜ[R] i, f i) (⨂ₜ[R] i, f (e i)) /-- The `ι`-indexed symmetric tensor power of a semimodule `M` over a commutative semiring `R` is the quotient of the `ι`-indexed tensor power of `M` by the relation that two tensors are equal if they are related by a permutation of `ι`. -/ def SymmetricPower : Type max u v := (addConGen (SymmetricPower.Rel R ι M)).Quotient @[inherit_doc] scoped[TensorProduct] notation:max "Sym[" R "] " ι:arg M:arg => SymmetricPower R ι M /-- The `n`th symmetric tensor power of a semimodule `M` over a commutative semiring `R` -/ scoped[TensorProduct] notation:max "Sym[" R "]^" n:arg M:arg => Sym[R] (Fin n) M namespace SymmetricPower instance : AddCommMonoid (Sym[R] ι M) := AddCon.addCommMonoid _ instance (R : Type u) [CommRing R] (M : Type v) [AddCommGroup M] [Module R M] : AddCommGroup (Sym[R] ι M) := AddCon.addCommGroup _ variable {R ι M} in lemma smul (r : R) (x y : ⨂[R] _, M) (h : addConGen (Rel R ι M) x y) : addConGen (Rel R ι M) (r • x) (r • y) := by induction h with | of x y h => cases h with | perm e f => apply isEmpty_or_nonempty ι |>.elim <;> intro h · convert addConGen (Rel R ι M) |>.refl _ · let i := Nonempty.some h classical convert AddConGen.Rel.of _ _ <| SymmetricPower.Rel.perm (R := R) (ι := ι) e <| Function.update f i (r • f i) · rw [MultilinearMap.map_update_smul, Function.update_eq_self] · simp_rw [Function.update_apply_equiv_apply, MultilinearMap.map_update_smul, ← Function.update_comp_equiv, Function.update_eq_self]; rfl | refl => exact AddCon.refl _ _ | symm => apply AddCon.symm; assumption | trans => apply AddCon.trans <;> assumption | add => rw [smul_add, smul_add]; apply AddCon.add <;> assumption variable {R} in /-- Scalar multiplication by `r : R`. Use `•` instead. -/ def smul' (r : R) : Sym[R] ι M →+ Sym[R] ι M := AddCon.lift _ (AddMonoidHom.comp (AddCon.mk' _) { toFun := (r • ·) map_zero' := smul_zero r map_add' := smul_add r }) (fun x y h ↦ Quotient.sound (smul r x y h)) instance module : Module R (Sym[R] ι M) where smul r x := smul' ι M r x one_smul x := AddCon.induction_on x <| fun x ↦ congr_arg _ <| one_smul R x mul_smul r s x := AddCon.induction_on x <| fun x ↦ congr_arg _ <| mul_smul r s x smul_zero r := congr_arg _ <| smul_zero r smul_add r x y := AddCon.induction_on₂ x y <| fun x y ↦ congr_arg _ <| smul_add r x y add_smul r s x := AddCon.induction_on x <| fun x ↦ congr_arg _ <| add_smul r s x zero_smul x := AddCon.induction_on x <| fun x ↦ congr_arg _ <| zero_smul R x /-- The canonical map from the `ι`-indexed tensor power to the symmetric tensor power. -/ def mk : (⨂[R] (_ : ι), M) →ₗ[R] Sym[R] ι M where map_smul' _ _ := rfl __ := AddCon.mk' _ variable {M ι} in /-- The multilinear map that takes `ι`-indexed elements of `M` and returns their symmetric tensor power. Denoted `⨂ₛ[R] i, f i`. -/ def tprod : MultilinearMap R (fun _ : ι ↦ M) Sym[R] ι M := (mk R ι M).compMultilinearMap (PiTensorProduct.tprod R) unsuppress_compilation in @[inherit_doc tprod] notation3:100 "⨂ₛ["R"] "(...)", "r:(scoped f => tprod R f) => r variable {R ι M} in @[simp] lemma tprod_equiv (e : Perm ι) (f : ι → M) : (⨂ₛ[R] i, f (e i)) = ⨂ₛ[R] i, f i := Eq.symm <| Quot.sound <| AddConGen.Rel.of _ _ <| Rel.perm e f variable {R M n} in @[simp] lemma domDomCongr_tprod (e : Perm ι) : (tprod R (ι := ι) (M := M)).domDomCongr e = tprod R := MultilinearMap.ext <| tprod_equiv e theorem range_mk : LinearMap.range (mk R ι M) = ⊤ := LinearMap.range_eq_top_of_surjective _ AddCon.mk'_surjective /-- The pure tensors (i.e. the elements of the image of `SymmetricPower.tprod`) span the symmetric tensor power. -/ theorem span_tprod_eq_top : Submodule.span R (Set.range (tprod R (ι := ι) (M := M))) = ⊤ := by rw [tprod, LinearMap.coe_compMultilinearMap, Set.range_comp, Submodule.span_image, PiTensorProduct.span_tprod_eq_top, Submodule.map_top, range_mk] end SymmetricPower
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorPower/Pairing.lean
import Mathlib.GroupTheory.MonoidLocalization.Basic import Mathlib.LinearAlgebra.Dual.Defs import Mathlib.LinearAlgebra.TensorPower.Basic /-! # The pairing between the tensor power of the dual and the tensor power We construct the pairing `TensorPower.pairingDual : ⨂[R]^n (Module.Dual R M) →ₗ[R] (Module.Dual R (⨂[R]^n M))`. -/ open TensorProduct PiTensorProduct namespace TensorPower variable (R : Type*) (M : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] (n : ℕ) open BigOperators /-- The canonical multilinear map from `n` copies of the dual of the module `M` to the dual of `⨂[R]^n M`. -/ noncomputable def multilinearMapToDual : MultilinearMap R (fun (_ : Fin n) ↦ Module.Dual R M) (Module.Dual R (⨂[R]^n M)) := have : ∀ (_ : DecidableEq (Fin n)) (f : Fin n → Module.Dual R M) (φ : Module.Dual R M) (i j : Fin n) (v : Fin n → M), (Function.update f i φ) j (v j) = Function.update (fun j ↦ f j (v j)) i (φ (v i)) j := fun _ f φ i j v ↦ by by_cases h : j = i · subst h simp only [Function.update_self] · simp only [Function.update_of_ne h] { toFun := fun f ↦ PiTensorProduct.lift (MultilinearMap.compLinearMap (MultilinearMap.mkPiRing R (Fin n) 1) f) map_update_add' := fun f i φ₁ φ₂ ↦ by ext v dsimp simp only [lift.tprod, MultilinearMap.compLinearMap_apply, this, LinearMap.add_apply, MultilinearMap.map_update_add] map_update_smul' := fun f i a φ ↦ by ext v dsimp simp only [lift.tprod, MultilinearMap.compLinearMap_apply, this, LinearMap.smul_apply, MultilinearMap.map_update_smul] dsimp } variable {R M n} in @[simp] theorem multilinearMapToDual_apply_tprod (f : (_ : Fin n) → Module.Dual R M) (v : Fin n → M) : multilinearMapToDual R M n f (tprod _ v) = ∏ i, (f i (v i)) := by simp [multilinearMapToDual] /-- The linear map from the tensor power of the dual to the dual of the tensor power. -/ noncomputable def pairingDual : ⨂[R]^n (Module.Dual R M) →ₗ[R] (Module.Dual R (⨂[R]^n M)) := PiTensorProduct.lift (multilinearMapToDual R M n) variable {R M n} in @[simp] lemma pairingDual_tprod_tprod (f : (_ : Fin n) → Module.Dual R M) (v : Fin n → M) : pairingDual R M n (tprod _ f) (tprod _ v) = ∏ i, (f i (v i)) := by simp [pairingDual] end TensorPower
.lake/packages/mathlib/Mathlib/LinearAlgebra/Span/Basic.lean
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic import Mathlib.Algebra.Module.Prod import Mathlib.Algebra.Module.Submodule.EqLocus import Mathlib.Algebra.Module.Submodule.Equiv import Mathlib.Algebra.Module.Submodule.RestrictScalars import Mathlib.Algebra.NoZeroSMulDivisors.Basic import Mathlib.LinearAlgebra.Span.Defs import Mathlib.Order.CompactlyGenerated.Basic import Mathlib.Order.OmegaCompletePartialOrder /-! # The span of a set of vectors, as a submodule * `Submodule.span s` is defined to be the smallest submodule containing the set `s`. ## Notation * We introduce the notation `R ∙ v` for the span of a singleton, `Submodule.span R {v}`. This is `\span`, not the same as the scalar multiplication `•`/`\bub`. -/ variable {R R₂ K M M₂ V S : Type*} namespace Submodule open Function Set open Pointwise section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [Module R M] variable {x : M} (p p' : Submodule R M) variable [Semiring R₂] {σ₁₂ : R →+* R₂} variable [AddCommMonoid M₂] [Module R₂ M₂] variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] variable {s t : Set M} lemma _root_.AddSubmonoid.toNatSubmodule_closure (s : Set M) : (AddSubmonoid.closure s).toNatSubmodule = .span ℕ s := (Submodule.span_le.mpr AddSubmonoid.subset_closure).antisymm' ((Submodule.span ℕ s).toAddSubmonoid.closure_le.mpr Submodule.subset_span) /-- A version of `Submodule.span_eq` for when the span is by a smaller ring. -/ @[simp] theorem span_coe_eq_restrictScalars [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] : span S (p : Set M) = p.restrictScalars S := span_eq (p.restrictScalars S) include σ₁₂ in /-- A version of `Submodule.map_span_le` that does not require the `RingHomSurjective` assumption. -/ theorem image_span_subset (f : F) (s : Set M) (N : Submodule R₂ M₂) : f '' span R s ⊆ N ↔ ∀ m ∈ s, f m ∈ N := image_subset_iff.trans <| span_le (p := N.comap f) include σ₁₂ in theorem image_span_subset_span (f : F) (s : Set M) : f '' span R s ⊆ span R₂ (f '' s) := (image_span_subset f s _).2 fun x hx ↦ subset_span ⟨x, hx, rfl⟩ theorem map_span [RingHomSurjective σ₁₂] (f : F) (s : Set M) : (span R s).map f = span R₂ (f '' s) := Eq.symm <| span_eq_of_le _ (Set.image_mono subset_span) (image_span_subset_span f s) alias _root_.LinearMap.map_span := Submodule.map_span theorem map_span_le [RingHomSurjective σ₁₂] (f : F) (s : Set M) (N : Submodule R₂ M₂) : map f (span R s) ≤ N ↔ ∀ m ∈ s, f m ∈ N := image_span_subset f s N alias _root_.LinearMap.map_span_le := Submodule.map_span_le /-- See also `Submodule.span_preimage_eq`. -/ theorem span_preimage_le (f : F) (s : Set M₂) : span R (f ⁻¹' s) ≤ (span R₂ s).comap f := by rw [span_le, comap_coe] exact preimage_mono subset_span alias _root_.LinearMap.span_preimage_le := Submodule.span_preimage_le include σ₁₂ in theorem mapsTo_span {f : F} {s : Set M} {t : Set M₂} (h : MapsTo f s t) : MapsTo f (span R s) (span R₂ t) := (span_mono h).trans (span_preimage_le (σ₁₂ := σ₁₂) f t) alias _root_.Set.MapsTo.submoduleSpan := mapsTo_span section variable {N : Type*} [AddCommMonoid N] [Module R N] lemma linearMap_eq_iff_of_eq_span {V : Submodule R M} (f g : V →ₗ[R] N) {S : Set M} (hV : V = span R S) : f = g ↔ ∀ (s : S), f ⟨s, by simpa only [hV] using subset_span (by simp)⟩ = g ⟨s, by simpa only [hV] using subset_span (by simp)⟩ := by constructor · rintro rfl _ rfl · intro h subst hV suffices ∀ (x : M) (hx : x ∈ span R S), f ⟨x, hx⟩ = g ⟨x, hx⟩ by ext ⟨x, hx⟩ exact this x hx intro x hx induction hx using span_induction with | mem x hx => exact h ⟨x, hx⟩ | zero => erw [map_zero, map_zero] | add x y hx hy hx' hy' => erw [f.map_add ⟨x, hx⟩ ⟨y, hy⟩, g.map_add ⟨x, hx⟩ ⟨y, hy⟩] rw [hx', hy'] | smul a x hx hx' => erw [f.map_smul a ⟨x, hx⟩, g.map_smul a ⟨x, hx⟩] rw [hx'] lemma linearMap_eq_iff_of_span_eq_top (f g : M →ₗ[R] N) {S : Set M} (hM : span R S = ⊤) : f = g ↔ ∀ (s : S), f s = g s := by convert linearMap_eq_iff_of_eq_span (f.comp (Submodule.subtype _)) (g.comp (Submodule.subtype _)) hM.symm constructor · rintro rfl rfl · intro h ext x exact DFunLike.congr_fun h ⟨x, by simp⟩ lemma linearMap_eq_zero_iff_of_span_eq_top (f : M →ₗ[R] N) {S : Set M} (hM : span R S = ⊤) : f = 0 ↔ ∀ (s : S), f s = 0 := linearMap_eq_iff_of_span_eq_top f 0 hM lemma linearMap_eq_zero_iff_of_eq_span {V : Submodule R M} (f : V →ₗ[R] N) {S : Set M} (hV : V = span R S) : f = 0 ↔ ∀ (s : S), f ⟨s, by simpa only [hV] using subset_span (by simp)⟩ = 0 := linearMap_eq_iff_of_eq_span f 0 hV end /-- See `Submodule.span_smul_eq` (in `RingTheory.Ideal.Operations`) for `span R (r • s) = r • span R s` that holds for arbitrary `r` in a `CommSemiring`. -/ theorem span_smul_eq_of_isUnit (s : Set M) (r : R) (hr : IsUnit r) : span R (r • s) = span R s := by apply le_antisymm · apply span_smul_le · convert span_smul_le (r • s) ((hr.unit⁻¹ :) : R) simp [smul_smul] /-- We can regard `coe_iSup_of_chain` as the statement that `(↑) : (Submodule R M) → Set M` is Scott continuous for the ω-complete partial order induced by the complete lattice structures. -/ theorem coe_scott_continuous : OmegaCompletePartialOrder.ωScottContinuous ((↑) : Submodule R M → Set M) := OmegaCompletePartialOrder.ωScottContinuous.of_monotone_map_ωSup ⟨SetLike.coe_mono, coe_iSup_of_chain⟩ section IsScalarTower variable (S) variable [Semiring S] [SMul R S] [Module S M] [IsScalarTower R S M] (p : Submodule R M) /-- The inclusion of an `R`-submodule into its `S`-span, as an `R`-linear map. -/ @[simps] def inclusionSpan : p →ₗ[R] span S (p : Set M) where toFun x := ⟨x, subset_span x.property⟩ map_add' x y := by simp map_smul' t x := by simp lemma injective_inclusionSpan : Injective (p.inclusionSpan S) := by intro x y hxy rw [Subtype.ext_iff] at hxy simpa using hxy lemma span_range_inclusionSpan : span S (range <| p.inclusionSpan S) = ⊤ := by have : (span S (p : Set M)).subtype '' range (inclusionSpan S p) = p := by ext; simpa [Subtype.ext_iff] using fun h ↦ subset_span h apply map_injective_of_injective (span S (p : Set M)).injective_subtype rw [map_subtype_top, map_span, this] variable (R s) /-- If `R` is "smaller" ring than `S` then the span by `R` is smaller than the span by `S`. -/ theorem span_le_restrictScalars : span R s ≤ (span S s).restrictScalars R := Submodule.span_le.2 Submodule.subset_span /-- A version of `Submodule.span_le_restrictScalars` with coercions. -/ @[simp] theorem span_subset_span : ↑(span R s) ⊆ (span S s : Set M) := span_le_restrictScalars R S s /-- Taking the span by a large ring of the span by the small ring is the same as taking the span by just the large ring. -/ @[simp] theorem span_span_of_tower : span S (span R s : Set M) = span S s := le_antisymm (span_le.2 <| span_subset_span R S s) (span_mono subset_span) theorem span_eq_top_of_span_eq_top (s : Set M) (hs : span R s = ⊤) : span S s = ⊤ := le_top.antisymm (hs.ge.trans (span_le_restrictScalars R S s)) variable {R S} in lemma span_range_inclusion_eq_top (p : Submodule R M) (q : Submodule S M) (h₁ : p ≤ q.restrictScalars R) (h₂ : q ≤ span S p) : span S (range (inclusion h₁)) = ⊤ := by suffices (span S (range (inclusion h₁))).map q.subtype = q by apply map_injective_of_injective q.injective_subtype rw [this, q.map_subtype_top] rw [map_span] suffices q.subtype '' ((LinearMap.range (inclusion h₁)) : Set <| q.restrictScalars R) = p by refine this ▸ le_antisymm ?_ h₂ simpa using span_mono (R := S) h₁ ext x simpa [range_inclusion] using fun hx ↦ h₁ hx @[simp] theorem span_range_inclusion_restrictScalars_eq_top : span S (range (inclusion <| span_le_restrictScalars R S s)) = ⊤ := span_range_inclusion_eq_top _ _ _ <| by simp end IsScalarTower theorem span_singleton_eq_span_singleton {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] {x y : M} : ((R ∙ x) = R ∙ y) ↔ ∃ z : Rˣ, z • x = y := by constructor · simp only [le_antisymm_iff, span_singleton_le_iff_mem, mem_span_singleton] rintro ⟨⟨a, rfl⟩, b, hb⟩ rcases eq_or_ne y 0 with rfl | hy; · simp refine ⟨⟨b, a, ?_, ?_⟩, hb⟩ · apply smul_left_injective R hy simpa only [mul_smul, one_smul] · rw [← hb] at hy apply smul_left_injective R (smul_ne_zero_iff.1 hy).2 simp only [mul_smul, one_smul, hb] · rintro ⟨u, rfl⟩ exact (span_singleton_group_smul_eq _ _ _).symm -- Should be `@[simp]` but doesn't fire due to https://github.com/leanprover/lean4/pull/3701. theorem span_image [RingHomSurjective σ₁₂] (f : F) : span R₂ (f '' s) = map f (span R s) := (map_span f s).symm @[simp] -- Should be replaced with `Submodule.span_image` when https://github.com/leanprover/lean4/pull/3701 is fixed. theorem span_image' [RingHomSurjective σ₁₂] (f : M →ₛₗ[σ₁₂] M₂) : span R₂ (f '' s) = map f (span R s) := span_image _ theorem apply_mem_span_image_of_mem_span [RingHomSurjective σ₁₂] (f : F) {x : M} {s : Set M} (h : x ∈ Submodule.span R s) : f x ∈ Submodule.span R₂ (f '' s) := by rw [Submodule.span_image] exact Submodule.mem_map_of_mem h theorem apply_mem_span_image_iff_mem_span [RingHomSurjective σ₁₂] {f : F} {x : M} {s : Set M} (hf : Function.Injective f) : f x ∈ Submodule.span R₂ (f '' s) ↔ x ∈ Submodule.span R s := by rw [← Submodule.mem_comap, ← Submodule.map_span, Submodule.comap_map_eq_of_injective hf] @[simp] theorem map_subtype_span_singleton {p : Submodule R M} (x : p) : map p.subtype (R ∙ x) = R ∙ (x : M) := by simp [← span_image] /-- `f` is an explicit argument so we can `apply` this theorem and obtain `h` as a new goal. -/ theorem notMem_span_of_apply_notMem_span_image [RingHomSurjective σ₁₂] (f : F) {x : M} {s : Set M} (h : f x ∉ Submodule.span R₂ (f '' s)) : x ∉ Submodule.span R s := h.imp (apply_mem_span_image_of_mem_span f) @[deprecated (since := "2025-05-23")] alias not_mem_span_of_apply_not_mem_span_image := notMem_span_of_apply_notMem_span_image theorem iSup_toAddSubmonoid {ι : Sort*} (p : ι → Submodule R M) : (⨆ i, p i).toAddSubmonoid = ⨆ i, (p i).toAddSubmonoid := by refine le_antisymm (fun x => ?_) (iSup_le fun i => toAddSubmonoid_mono <| le_iSup _ i) simp_rw [iSup_eq_span, AddSubmonoid.iSup_eq_closure, mem_toAddSubmonoid, coe_toAddSubmonoid] intro hx refine Submodule.span_induction (fun x hx => ?_) ?_ (fun x y _ _ hx hy => ?_) (fun r x _ hx => ?_) hx · exact AddSubmonoid.subset_closure hx · exact AddSubmonoid.zero_mem _ · exact AddSubmonoid.add_mem _ hx hy · refine AddSubmonoid.closure_induction ?_ ?_ ?_ hx · rintro x ⟨_, ⟨i, rfl⟩, hix : x ∈ p i⟩ apply AddSubmonoid.subset_closure (Set.mem_iUnion.mpr ⟨i, _⟩) exact smul_mem _ r hix · rw [smul_zero] exact AddSubmonoid.zero_mem _ · intro x y _ _ hx hy rw [smul_add] exact AddSubmonoid.add_mem _ hx hy /-- An induction principle for elements of `⨆ i, p i`. If `C` holds for `0` and all elements of `p i` for all `i`, and is preserved under addition, then it holds for all elements of the supremum of `p`. -/ @[elab_as_elim] theorem iSup_induction {ι : Sort*} (p : ι → Submodule R M) {motive : M → Prop} {x : M} (hx : x ∈ ⨆ i, p i) (mem : ∀ (i), ∀ x ∈ p i, motive x) (zero : motive 0) (add : ∀ x y, motive x → motive y → motive (x + y)) : motive x := by rw [← mem_toAddSubmonoid, iSup_toAddSubmonoid] at hx exact AddSubmonoid.iSup_induction (x := x) _ hx mem zero add /-- A dependent version of `submodule.iSup_induction`. -/ @[elab_as_elim] theorem iSup_induction' {ι : Sort*} (p : ι → Submodule R M) {motive : ∀ x, (x ∈ ⨆ i, p i) → Prop} (mem : ∀ (i) (x) (hx : x ∈ p i), motive x (mem_iSup_of_mem i hx)) (zero : motive 0 (zero_mem _)) (add : ∀ x y hx hy, motive x hx → motive y hy → motive (x + y) (add_mem ‹_› ‹_›)) {x : M} (hx : x ∈ ⨆ i, p i) : motive x hx := by refine Exists.elim ?_ fun (hx : x ∈ ⨆ i, p i) (hc : motive x hx) => hc refine iSup_induction p (motive := fun x : M ↦ ∃ (hx : x ∈ ⨆ i, p i), motive x hx) hx (fun i x hx => ?_) ?_ fun x y => ?_ · exact ⟨_, mem _ _ hx⟩ · exact ⟨_, zero⟩ · rintro ⟨_, Cx⟩ ⟨_, Cy⟩ exact ⟨_, add _ _ _ _ Cx Cy⟩ theorem singleton_span_isCompactElement (x : M) : CompleteLattice.IsCompactElement (span R {x} : Submodule R M) := by rw [CompleteLattice.isCompactElement_iff_le_of_directed_sSup_le] intro d hemp hdir hsup have : x ∈ (sSup d) := (SetLike.le_def.mp hsup) (mem_span_singleton_self x) obtain ⟨y, ⟨hyd, hxy⟩⟩ := (mem_sSup_of_directed hemp hdir).mp this exact ⟨y, ⟨hyd, by simpa only [span_le, singleton_subset_iff] ⟩⟩ /-- The span of a finite subset is compact in the lattice of submodules. -/ theorem finset_span_isCompactElement (S : Finset M) : CompleteLattice.IsCompactElement (span R S : Submodule R M) := by rw [span_eq_iSup_of_singleton_spans] simp only [Finset.mem_coe] rw [← Finset.sup_eq_iSup] exact CompleteLattice.isCompactElement_finsetSup S fun x _ => singleton_span_isCompactElement x /-- The span of a finite subset is compact in the lattice of submodules. -/ theorem finite_span_isCompactElement (S : Set M) (h : S.Finite) : CompleteLattice.IsCompactElement (span R S : Submodule R M) := Finite.coe_toFinset h ▸ finset_span_isCompactElement h.toFinset instance : IsCompactlyGenerated (Submodule R M) := ⟨fun s => ⟨(fun x => span R {x}) '' s, ⟨fun t ht => by rcases (Set.mem_image _ _ _).1 ht with ⟨x, _, rfl⟩ apply singleton_span_isCompactElement, by rw [sSup_eq_iSup, iSup_image, ← span_eq_iSup_of_singleton_spans, span_eq]⟩⟩⟩ variable {M' : Type*} [AddCommMonoid M'] [Module R M'] (q₁ q₁' : Submodule R M') /-- The product of two submodules is a submodule. -/ def prod : Submodule R (M × M') := { p.toAddSubmonoid.prod q₁.toAddSubmonoid with carrier := p ×ˢ q₁ smul_mem' := by rintro a ⟨x, y⟩ ⟨hx, hy⟩; exact ⟨smul_mem _ a hx, smul_mem _ a hy⟩ } @[simp] theorem prod_coe : (prod p q₁ : Set (M × M')) = (p : Set M) ×ˢ (q₁ : Set M') := rfl @[simp] theorem mem_prod {p : Submodule R M} {q : Submodule R M'} {x : M × M'} : x ∈ prod p q ↔ x.1 ∈ p ∧ x.2 ∈ q := Set.mem_prod theorem span_prod_le (s : Set M) (t : Set M') : span R (s ×ˢ t) ≤ prod (span R s) (span R t) := span_le.2 <| Set.prod_mono subset_span subset_span @[simp] theorem prod_top : (prod ⊤ ⊤ : Submodule R (M × M')) = ⊤ := by ext; simp @[simp] theorem prod_bot : (prod ⊥ ⊥ : Submodule R (M × M')) = ⊥ := by ext ⟨x, y⟩; simp theorem prod_mono {p p' : Submodule R M} {q q' : Submodule R M'} : p ≤ p' → q ≤ q' → prod p q ≤ prod p' q' := Set.prod_mono @[simp] theorem prod_inf_prod : prod p q₁ ⊓ prod p' q₁' = prod (p ⊓ p') (q₁ ⊓ q₁') := SetLike.coe_injective Set.prod_inter_prod @[simp] theorem prod_sup_prod : prod p q₁ ⊔ prod p' q₁' = prod (p ⊔ p') (q₁ ⊔ q₁') := by refine le_antisymm (sup_le (prod_mono le_sup_left le_sup_left) (prod_mono le_sup_right le_sup_right)) ?_ simp only [SetLike.le_def, mem_prod, and_imp, Prod.forall]; intro xx yy hxx hyy rcases mem_sup.1 hxx with ⟨x, hx, x', hx', rfl⟩ rcases mem_sup.1 hyy with ⟨y, hy, y', hy', rfl⟩ exact mem_sup.2 ⟨(x, y), ⟨hx, hy⟩, (x', y'), ⟨hx', hy'⟩, rfl⟩ /-- If a bilinear map takes values in a submodule along two sets, then the same is true along the span of these sets. -/ lemma _root_.LinearMap.BilinMap.apply_apply_mem_of_mem_span {R M N P : Type*} [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [Module R M] [Module R N] [Module R P] (P' : Submodule R P) (s : Set M) (t : Set N) (B : M →ₗ[R] N →ₗ[R] P) (hB : ∀ x ∈ s, ∀ y ∈ t, B x y ∈ P') (x : M) (y : N) (hx : x ∈ span R s) (hy : y ∈ span R t) : B x y ∈ P' := by induction hx, hy using span_induction₂ with | mem_mem u v hu hv => exact hB u hu v hv | zero_left v hv => simp | zero_right u hu => simp | add_left u₁ u₂ v hu₁ hu₂ hv huv₁ huv₂ => simpa using add_mem huv₁ huv₂ | add_right u v₁ v₂ hu hv₁ hv₂ huv₁ huv₂ => simpa using add_mem huv₁ huv₂ | smul_left t u v hu hv huv => simpa using Submodule.smul_mem _ _ huv | smul_right t u v hu hv huv => simpa using Submodule.smul_mem _ _ huv @[simp] lemma biSup_comap_subtype_eq_top {ι : Type*} (s : Set ι) (p : ι → Submodule R M) : ⨆ i ∈ s, (p i).comap (⨆ i ∈ s, p i).subtype = ⊤ := by refine eq_top_iff.mpr fun ⟨x, hx⟩ _ ↦ ?_ suffices x ∈ (⨆ i ∈ s, (p i).comap (⨆ i ∈ s, p i).subtype).map (⨆ i ∈ s, (p i)).subtype by obtain ⟨y, hy, rfl⟩ := Submodule.mem_map.mp this exact hy suffices ∀ i ∈ s, (comap (⨆ i ∈ s, p i).subtype (p i)).map (⨆ i ∈ s, p i).subtype = p i by simpa only [map_iSup, biSup_congr this] intro i hi rw [map_comap_eq, range_subtype, inf_eq_right] exact le_biSup p hi theorem _root_.LinearMap.exists_ne_zero_of_sSup_eq {N : Submodule R M} {f : N →ₛₗ[σ₁₂] M₂} (h : f ≠ 0) (s : Set (Submodule R M)) (hs : sSup s = N): ∃ m, ∃ h : m ∈ s, f ∘ₛₗ inclusion ((le_sSup h).trans_eq hs) ≠ 0 := have ⟨_, ⟨m, hm, rfl⟩, ne⟩ := LinearMap.exists_ne_zero_of_sSup_eq_top h (comap N.subtype '' s) <| by rw [sSup_eq_iSup] at hs; rw [sSup_image, ← hs, biSup_comap_subtype_eq_top] ⟨m, hm, fun eq ↦ ne (LinearMap.ext fun x ↦ congr($eq ⟨x, x.2⟩))⟩ end AddCommMonoid section AddCommGroup variable [Ring R] [AddCommGroup M] [Module R M] lemma _root_.AddSubgroup.toIntSubmodule_closure (s : Set M) : (AddSubgroup.closure s).toIntSubmodule = .span ℤ s := (Submodule.span_le.mpr AddSubgroup.subset_closure).antisymm' ((Submodule.span ℤ s).toAddSubgroup.closure_le.mpr Submodule.subset_span) @[simp] theorem span_neg (s : Set M) : span R (-s) = span R s := calc span R (-s) = span R ((-LinearMap.id : M →ₗ[R] M) '' s) := by simp _ = map (-LinearMap.id) (span R s) := (map_span (-LinearMap.id) _).symm _ = span R s := by simp instance : IsModularLattice (Submodule R M) := ⟨fun y z xz a ha => by rw [mem_inf, mem_sup] at ha rcases ha with ⟨⟨b, hb, c, hc, rfl⟩, haz⟩ rw [mem_sup] refine ⟨b, hb, c, mem_inf.2 ⟨hc, ?_⟩, rfl⟩ rw [← add_sub_cancel_right c b, add_comm] apply z.sub_mem haz (xz hb)⟩ lemma isCompl_comap_subtype_of_isCompl_of_le {p q r : Submodule R M} (h₁ : IsCompl q r) (h₂ : q ≤ p) : IsCompl (q.comap p.subtype) (r.comap p.subtype) := by simpa [p.mapIic.isCompl_iff, Iic.isCompl_iff] using Iic.isCompl_inf_inf_of_isCompl_of_le h₁ h₂ end AddCommGroup section AddCommGroup variable [Semiring R] [Semiring R₂] variable [AddCommGroup M] [Module R M] [AddCommGroup M₂] [Module R₂ M₂] variable {τ₁₂ : R →+* R₂} [RingHomSurjective τ₁₂] variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] theorem comap_map_eq (f : F) (p : Submodule R M) : comap f (map f p) = p ⊔ LinearMap.ker f := by refine le_antisymm ?_ (sup_le (le_comap_map _ _) (comap_mono bot_le)) rintro x ⟨y, hy, e⟩ exact mem_sup.2 ⟨y, hy, x - y, by simpa using sub_eq_zero.2 e.symm, by simp⟩ theorem map_lt_map_of_le_of_sup_lt_sup {p p' : Submodule R M} {f : F} (hab : p ≤ p') (h : p ⊔ LinearMap.ker f < p' ⊔ LinearMap.ker f) : Submodule.map f p < Submodule.map f p' := by simp_rw [← comap_map_eq] at h exact lt_of_le_of_ne (map_mono hab) (ne_of_apply_ne _ h.ne) theorem comap_map_eq_self {f : F} {p : Submodule R M} (h : LinearMap.ker f ≤ p) : comap f (map f p) = p := by rw [Submodule.comap_map_eq, sup_of_le_left h] theorem comap_map_sup_of_comap_le {f : F} {p : Submodule R M} {q : Submodule R₂ M₂} (le : comap f q ≤ p) : comap f (map f p ⊔ q) = p := by refine le_antisymm (fun x h ↦ ?_) (map_le_iff_le_comap.mp le_sup_left) obtain ⟨_, ⟨y, hy, rfl⟩, z, hz, eq⟩ := mem_sup.mp h rw [add_comm, ← eq_sub_iff_add_eq, ← map_sub] at eq; subst eq simpa using p.add_mem (le hz) hy theorem isCoatom_comap_or_eq_top (f : F) {p : Submodule R₂ M₂} (hp : IsCoatom p) : IsCoatom (comap f p) ∨ comap f p = ⊤ := or_iff_not_imp_right.mpr fun h ↦ ⟨h, fun q lt ↦ by rw [← comap_map_sup_of_comap_le lt.le, hp.2 (map f q ⊔ p), comap_top] simpa only [right_lt_sup, map_le_iff_le_comap] using lt.not_ge⟩ theorem isCoatom_comap_iff {f : F} (hf : Surjective f) {p : Submodule R₂ M₂} : IsCoatom (comap f p) ↔ IsCoatom p := by have := comap_injective_of_surjective hf rw [IsCoatom, IsCoatom, ← comap_top f, this.ne_iff] refine and_congr_right fun _ ↦ ⟨fun h m hm ↦ this (h _ <| comap_strictMono_of_surjective hf hm), fun h m hm ↦ ?_⟩ rw [← h _ (lt_map_of_comap_lt_of_surjective hf hm), comap_map_eq_self ((comap_mono bot_le).trans hm.le)] theorem isCoatom_map_of_ker_le {f : F} (hf : Surjective f) {p : Submodule R M} (le : LinearMap.ker f ≤ p) (hp : IsCoatom p) : IsCoatom (map f p) := (isCoatom_comap_iff hf).mp <| by rwa [comap_map_eq_self le] theorem map_iInf_of_ker_le {f : F} (hf : Surjective f) {ι} {p : ι → Submodule R M} (h : LinearMap.ker f ≤ ⨅ i, p i) : map f (⨅ i, p i) = ⨅ i, map f (p i) := by conv_rhs => rw [← map_comap_eq_of_surjective hf (⨅ _, _), comap_iInf] simp_rw [fun i ↦ comap_map_eq_self (le_iInf_iff.mp h i)] lemma comap_covBy_of_surjective {f : F} (hf : Surjective f) {p q : Submodule R₂ M₂} (h : p ⋖ q) : p.comap f ⋖ q.comap f := by refine ⟨lt_of_le_of_ne (comap_mono h.1.le) ((comap_injective_of_surjective hf).ne h.1.ne), ?_⟩ intro N h₁ h₂ refine h.2 (lt_map_of_comap_lt_of_surjective hf h₁) ?_ rwa [← comap_lt_comap_iff_of_surjective hf, comap_map_eq, sup_eq_left.mpr] refine (LinearMap.ker_le_comap (f : M →ₛₗ[τ₁₂] M₂)).trans h₁.le lemma _root_.LinearMap.range_domRestrict_eq_range_iff {f : M →ₛₗ[τ₁₂] M₂} {S : Submodule R M} : LinearMap.range (f.domRestrict S) = LinearMap.range f ↔ S ⊔ (LinearMap.ker f) = ⊤ := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [eq_top_iff] intro x _ have : f x ∈ LinearMap.range f := LinearMap.mem_range_self f x rw [← h] at this obtain ⟨y, hy⟩ : ∃ y : S, f.domRestrict S y = f x := this have : (y : M) + (x - y) ∈ S ⊔ (LinearMap.ker f) := Submodule.add_mem_sup y.2 (by simp [← hy]) simpa using this · refine le_antisymm (LinearMap.range_domRestrict_le_range f S) ?_ rintro x ⟨y, rfl⟩ obtain ⟨s, hs, t, ht, rfl⟩ : ∃ s, s ∈ S ∧ ∃ t, t ∈ LinearMap.ker f ∧ s + t = y := Submodule.mem_sup.1 (by simp [h]) exact ⟨⟨s, hs⟩, by simp [LinearMap.mem_ker.1 ht]⟩ @[simp] lemma _root_.LinearMap.surjective_domRestrict_iff {f : M →ₛₗ[τ₁₂] M₂} {S : Submodule R M} (hf : Surjective f) : Surjective (f.domRestrict S) ↔ S ⊔ LinearMap.ker f = ⊤ := by rw [← LinearMap.range_eq_top] at hf ⊢ rw [← hf] exact LinearMap.range_domRestrict_eq_range_iff lemma biSup_comap_eq_top_of_surjective {ι : Type*} (s : Set ι) (hs : s.Nonempty) (p : ι → Submodule R₂ M₂) (hp : ⨆ i ∈ s, p i = ⊤) (f : M →ₛₗ[τ₁₂] M₂) (hf : Surjective f) : ⨆ i ∈ s, (p i).comap f = ⊤ := by obtain ⟨k, hk⟩ := hs suffices (⨆ i ∈ s, (p i).comap f) ⊔ LinearMap.ker f = ⊤ by rw [← this, left_eq_sup]; exact le_trans f.ker_le_comap (le_biSup (fun i ↦ (p i).comap f) hk) rw [iSup_subtype'] at hp ⊢ rw [← comap_map_eq, map_iSup_comap_of_surjective hf, hp, comap_top] lemma biSup_comap_eq_top_of_range_eq_biSup {R R₂ : Type*} [Semiring R] [Ring R₂] {τ₁₂ : R →+* R₂} [RingHomSurjective τ₁₂] [Module R M] [Module R₂ M₂] {ι : Type*} (s : Set ι) (hs : s.Nonempty) (p : ι → Submodule R₂ M₂) (f : M →ₛₗ[τ₁₂] M₂) (hf : LinearMap.range f = ⨆ i ∈ s, p i) : ⨆ i ∈ s, (p i).comap f = ⊤ := by suffices ⨆ i ∈ s, (p i).comap (LinearMap.range f).subtype = ⊤ by rw [← biSup_comap_eq_top_of_surjective s hs _ this _ f.surjective_rangeRestrict]; rfl exact hf ▸ biSup_comap_subtype_eq_top s p end AddCommGroup section Ring variable [Ring R] [Semiring R₂] variable [AddCommGroup M] [Module R M] [AddCommGroup M₂] [Module R₂ M₂] variable {τ₁₂ : R →+* R₂} [RingHomSurjective τ₁₂] variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] variable {p p' : Submodule R M} theorem map_strict_mono_or_ker_sup_lt_ker_sup (f : F) (hab : p < p') : Submodule.map f p < Submodule.map f p' ∨ LinearMap.ker f ⊓ p < LinearMap.ker f ⊓ p' := by obtain (⟨h, -⟩ | ⟨-, h⟩) := Prod.mk_lt_mk.mp <| strictMono_inf_prod_sup (z := LinearMap.ker f) hab · simpa [inf_comm] using Or.inr h · apply Or.inl <| map_lt_map_of_le_of_sup_lt_sup hab.le h theorem _root_.LinearMap.ker_inf_lt_ker_inf_of_map_eq_of_lt {f : F} (hab : p < p') (q : Submodule.map f p = Submodule.map f p') : LinearMap.ker f ⊓ p < LinearMap.ker f ⊓ p' := map_strict_mono_or_ker_sup_lt_ker_sup f hab |>.resolve_left q.not_lt theorem map_strict_mono_of_ker_inf_eq {f : F} (hab : p < p') (q : LinearMap.ker f ⊓ p = LinearMap.ker f ⊓ p') : Submodule.map f p < Submodule.map f p' := map_strict_mono_or_ker_sup_lt_ker_sup f hab |>.resolve_right q.not_lt /-- Version of `disjoint_span_singleton` that works when the scalars are not a field. -/ lemma disjoint_span_singleton'' {s : Submodule R M} {x : M} : Disjoint s (R ∙ x) ↔ ∀ r : R, r • x ∈ s → r • x = 0 := by rw [disjoint_comm]; simp +contextual [disjoint_def, mem_span_singleton] end Ring section DivisionRing variable [DivisionRing K] [AddCommGroup V] [Module K V] {s : Submodule K V} {x : V} /-- There is no vector subspace between `s` and `(K ∙ x) ⊔ s`, `WCovBy` version. -/ theorem wcovBy_span_singleton_sup (x : V) (s : Submodule K V) : WCovBy s ((K ∙ x) ⊔ s) := by refine ⟨le_sup_right, fun q hpq hqp ↦ hqp.not_ge ?_⟩ rcases SetLike.exists_of_lt hpq with ⟨y, hyq, hyp⟩ obtain ⟨c, z, hz, rfl⟩ : ∃ c : K, ∃ z ∈ s, c • x + z = y := by simpa [mem_sup, mem_span_singleton] using hqp.le hyq rcases eq_or_ne c 0 with rfl | hc · simp [hz] at hyp · have : x ∈ q := by rwa [q.add_mem_iff_left (hpq.le hz), q.smul_mem_iff hc] at hyq simp [hpq.le, this] /-- There is no vector subspace between `s` and `(K ∙ x) ⊔ s`, `CovBy` version. -/ theorem covBy_span_singleton_sup {x : V} {s : Submodule K V} (h : x ∉ s) : CovBy s ((K ∙ x) ⊔ s) := ⟨by simpa, (wcovBy_span_singleton_sup _ _).2⟩ theorem disjoint_span_singleton : Disjoint s (K ∙ x) ↔ x ∈ s → x = 0 := by simpa +contextual [disjoint_span_singleton'', or_iff_not_imp_left, forall_swap (β := ¬_), s.smul_mem_iff] using ⟨fun h ↦ h _ one_ne_zero, fun h _ _ ↦ h⟩ theorem disjoint_span_singleton' (hx : x ≠ 0) : Disjoint s (K ∙ x) ↔ x ∉ s := by simp [disjoint_span_singleton, hx] lemma disjoint_span_singleton_of_notMem (hx : x ∉ s) : Disjoint s (K ∙ x) := by simp [disjoint_span_singleton, hx] @[deprecated (since := "2025-05-23")] alias disjoint_span_singleton_of_not_mem := disjoint_span_singleton_of_notMem lemma isCompl_span_singleton_of_isCoatom_of_notMem (hs : IsCoatom s) (hx : x ∉ s) : IsCompl s (K ∙ x) := by refine ⟨disjoint_span_singleton_of_notMem hx, ?_⟩ rw [← covBy_top_iff] at hs simpa only [codisjoint_iff, sup_comm, not_lt_top_iff] using hs.2 (covBy_span_singleton_sup hx).1 @[deprecated (since := "2025-05-23")] alias isCompl_span_singleton_of_isCoatom_of_not_mem := isCompl_span_singleton_of_isCoatom_of_notMem end DivisionRing end Submodule namespace LinearMap open Submodule Function section AddCommGroup variable [Semiring R] [Semiring R₂] variable [AddCommGroup M] [AddCommGroup M₂] variable [Module R M] [Module R₂ M₂] variable {τ₁₂ : R →+* R₂} [RingHomSurjective τ₁₂] variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] protected theorem map_le_map_iff (f : F) {p p'} : map f p ≤ map f p' ↔ p ≤ p' ⊔ ker f := by rw [map_le_iff_le_comap, Submodule.comap_map_eq] theorem map_le_map_iff' {f : F} (hf : ker f = ⊥) {p p'} : map f p ≤ map f p' ↔ p ≤ p' := by rw [LinearMap.map_le_map_iff, hf, sup_bot_eq] theorem map_injective {f : F} (hf : ker f = ⊥) : Injective (map f) := fun _ _ h => le_antisymm ((map_le_map_iff' hf).1 (le_of_eq h)) ((map_le_map_iff' hf).1 (ge_of_eq h)) theorem map_eq_top_iff {f : F} (hf : range f = ⊤) {p : Submodule R M} : p.map f = ⊤ ↔ p ⊔ LinearMap.ker f = ⊤ := by simp_rw [← top_le_iff, ← hf, range_eq_map, LinearMap.map_le_map_iff] end AddCommGroup section variable (R) (M) [Semiring R] [AddCommMonoid M] [Module R M] /-- Given an element `x` of a module `M` over `R`, the natural map from `R` to scalar multiples of `x`. See also `LinearMap.ringLmapEquivSelf`. -/ @[simps!] def toSpanSingleton (x : M) : R →ₗ[R] M := LinearMap.id.smulRight x theorem toSpanSingleton_one (x : M) : toSpanSingleton R M x 1 = x := one_smul _ _ theorem toSpanSingleton_injective : Function.Injective (toSpanSingleton R M) := fun _ _ eq ↦ by simpa using congr($eq 1) @[simp] theorem toSpanSingleton_zero : toSpanSingleton R M 0 = 0 := by ext simp theorem toSpanSingleton_eq_zero_iff {x : M} : toSpanSingleton R M x = 0 ↔ x = 0 := by rw [← toSpanSingleton_zero, (toSpanSingleton_injective R M).eq_iff] variable {R M} lemma toSpanSingleton_add (x y : M) : toSpanSingleton R M (x + y) = toSpanSingleton R M x + toSpanSingleton R M y := by ext; simp theorem toSpanSingleton_smul {S : Type*} [Monoid S] [DistribMulAction S M] [SMulCommClass R S M] (r : S) (x : M) : toSpanSingleton R M (r • x) = r • toSpanSingleton R M x := by ext; simp theorem toSpanSingleton_isIdempotentElem_iff {e : R} : IsIdempotentElem (toSpanSingleton R R e) ↔ IsIdempotentElem e := by simp_rw [IsIdempotentElem, LinearMap.ext_iff, Module.End.mul_apply, toSpanSingleton_apply, smul_eq_mul, mul_assoc] exact ⟨fun h ↦ by conv_rhs => rw [← one_mul e, ← h, one_mul], fun h _ ↦ by rw [h]⟩ theorem isIdempotentElem_apply_one_iff {f : Module.End R R} : IsIdempotentElem (f 1) ↔ IsIdempotentElem f := by rw [IsIdempotentElem, ← smul_eq_mul, ← map_smul, smul_eq_mul, mul_one, IsIdempotentElem, LinearMap.ext_iff] simp_rw [Module.End.mul_apply] exact ⟨fun h r ↦ by rw [← mul_one r, ← smul_eq_mul, map_smul, map_smul, h], (· 1)⟩ /-- The range of `toSpanSingleton x` is the span of `x`. -/ theorem range_toSpanSingleton (x : M) : range (toSpanSingleton R M x) = .span R {x} := SetLike.coe_injective (Submodule.span_singleton_eq_range R x).symm variable (R M) in theorem span_singleton_eq_range (x : M) : (R ∙ x) = range (toSpanSingleton R M x) := range_toSpanSingleton x |>.symm theorem comp_toSpanSingleton [AddCommMonoid M₂] [Module R M₂] (f : M →ₗ[R] M₂) (x : M) : f ∘ₗ toSpanSingleton R M x = toSpanSingleton R M₂ (f x) := by ext; simp theorem submoduleOf_span_singleton_of_mem (N : Submodule R M) {x : M} (hx : x ∈ N) : (span R {x}).submoduleOf N = span R {⟨x, hx⟩} := by ext y simp_rw [submoduleOf, mem_comap, subtype_apply, mem_span_singleton] aesop end section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [Module R M] variable [Semiring R₂] [AddCommMonoid M₂] [Module R₂ M₂] variable {F : Type*} {σ₁₂ : R →+* R₂} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] include σ₁₂ /-- Two linear maps are equal on `Submodule.span s` iff they are equal on `s`. -/ theorem eqOn_span_iff {s : Set M} {f g : F} : Set.EqOn f g (span R s) ↔ Set.EqOn f g s := by rw [← le_eqLocus, span_le]; rfl /-- If two linear maps are equal on a set `s`, then they are equal on `Submodule.span s`. This version uses `Set.EqOn`, and the hidden argument will expand to `h : x ∈ (span R s : Set M)`. See `LinearMap.eqOn_span` for a version that takes `h : x ∈ span R s` as an argument. -/ theorem eqOn_span' {s : Set M} {f g : F} (H : Set.EqOn f g s) : Set.EqOn f g (span R s : Set M) := eqOn_span_iff.2 H /-- If two linear maps are equal on a set `s`, then they are equal on `Submodule.span s`. See also `LinearMap.eqOn_span'` for a version using `Set.EqOn`. -/ theorem eqOn_span {s : Set M} {f g : F} (H : Set.EqOn f g s) ⦃x⦄ (h : x ∈ span R s) : f x = g x := eqOn_span' H h /-- If `s` generates the whole module and linear maps `f`, `g` are equal on `s`, then they are equal. -/ theorem ext_on {s : Set M} {f g : F} (hv : span R s = ⊤) (h : Set.EqOn f g s) : f = g := DFunLike.ext _ _ fun _ => eqOn_span h (eq_top_iff'.1 hv _) /-- If the range of `v : ι → M` generates the whole module and linear maps `f`, `g` are equal at each `v i`, then they are equal. -/ theorem ext_on_range {ι : Sort*} {v : ι → M} {f g : F} (hv : span R (Set.range v) = ⊤) (h : ∀ i, f (v i) = g (v i)) : f = g := ext_on hv (Set.forall_mem_range.2 h) end AddCommMonoid section NoZeroDivisors variable (R M) variable [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] theorem ker_toSpanSingleton {x : M} (h : x ≠ 0) : LinearMap.ker (toSpanSingleton R M x) = ⊥ := SetLike.ext fun _ => smul_eq_zero.trans <| or_iff_left_of_imp fun h' => (h h').elim end NoZeroDivisors section Field variable [Field K] [AddCommGroup V] [Module K V] theorem span_singleton_sup_ker_eq_top (f : V →ₗ[K] K) {x : V} (hx : f x ≠ 0) : (K ∙ x) ⊔ ker f = ⊤ := top_unique fun y _ => Submodule.mem_sup.2 ⟨(f y * (f x)⁻¹) • x, Submodule.mem_span_singleton.2 ⟨f y * (f x)⁻¹, rfl⟩, ⟨y - (f y * (f x)⁻¹) • x, by simp [hx]⟩⟩ end Field end LinearMap open LinearMap namespace LinearEquiv variable (R M) variable [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] (x : M) (h : x ≠ 0) /-- Given a nonzero element `x` of a torsion-free module `M` over a ring `R`, the natural isomorphism from `R` to the span of `x` given by $r \mapsto r \cdot x$. -/ noncomputable def toSpanNonzeroSingleton : R ≃ₗ[R] R ∙ x := LinearEquiv.trans (LinearEquiv.ofInjective (LinearMap.toSpanSingleton R M x) (ker_eq_bot.1 <| ker_toSpanSingleton R M h)) (LinearEquiv.ofEq (range <| toSpanSingleton R M x) (R ∙ x) (range_toSpanSingleton x)) @[simp] theorem toSpanNonzeroSingleton_apply (t : R) : toSpanNonzeroSingleton R M x h t = (⟨t • x, Submodule.smul_mem _ _ (Submodule.mem_span_singleton_self x)⟩ : R ∙ x) := by rfl @[simp] lemma toSpanNonzeroSingleton_symm_apply_smul (m : R ∙ x) : (toSpanNonzeroSingleton R M x h).symm m • x = m := congrArg Subtype.val <| apply_symm_apply (toSpanNonzeroSingleton R M x h) m theorem toSpanNonzeroSingleton_one : LinearEquiv.toSpanNonzeroSingleton R M x h 1 = (⟨x, Submodule.mem_span_singleton_self x⟩ : R ∙ x) := by simp /-- Given a nonzero element `x` of a torsion-free module `M` over a ring `R`, the natural isomorphism from the span of `x` to `R` given by $r \cdot x \mapsto r$. -/ noncomputable abbrev coord : (R ∙ x) ≃ₗ[R] R := (toSpanNonzeroSingleton R M x h).symm theorem coord_self : (coord R M x h) (⟨x, Submodule.mem_span_singleton_self x⟩ : R ∙ x) = 1 := by rw [← toSpanNonzeroSingleton_one R M x h, LinearEquiv.symm_apply_apply] theorem coord_apply_smul (y : Submodule.span R ({x} : Set M)) : coord R M x h y • x = y := Subtype.ext_iff.1 <| (toSpanNonzeroSingleton R M x h).apply_symm_apply _ end LinearEquiv
.lake/packages/mathlib/Mathlib/LinearAlgebra/Span/Defs.lean
import Mathlib.Algebra.Module.Submodule.Lattice import Mathlib.Algebra.Group.Pointwise.Set.Basic /-! # The span of a set of vectors, as a submodule * `Submodule.span s` is defined to be the smallest submodule containing the set `s`. ## Notation * We introduce the notation `R ∙ v` for the span of a singleton, `Submodule.span R {v}`. This is `\span`, not the same as the scalar multiplication `•`/`\bub`. -/ assert_not_exists Field variable {R R₂ K M M₂ V S : Type*} namespace Submodule open Function Set open Pointwise section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [Module R M] variable {x : M} (p p' : Submodule R M) variable [Semiring R₂] {σ₁₂ : R →+* R₂} variable [AddCommMonoid M₂] [Module R₂ M₂] variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] section variable (R) in /-- The span of a set `s ⊆ M` is the smallest submodule of M that contains `s`. -/ def span (s : Set M) : Submodule R M := sInf { p | s ⊆ p } /-- An `R`-submodule of `M` is principal if it is generated by one element. -/ @[mk_iff] class IsPrincipal (S : Submodule R M) : Prop where principal (S) : ∃ a, S = span R {a} instance (x : R) : (span R {x}).IsPrincipal := ⟨x, rfl⟩ namespace IsPrincipal /-- `generator I`, if `I` is a principal submodule, is an `x ∈ M` such that `span R {x} = I` -/ noncomputable def generator (S : Submodule R M) [S.IsPrincipal] : M := Classical.choose (principal S) theorem span_singleton_generator (S : Submodule R M) [S.IsPrincipal] : span R {generator S} = S := (Classical.choose_spec (principal S)).symm end IsPrincipal end variable {s t : Set M} theorem mem_span : x ∈ span R s ↔ ∀ p : Submodule R M, s ⊆ p → x ∈ p := mem_iInter₂ @[simp, aesop safe 20 (rule_sets := [SetLike])] theorem subset_span : s ⊆ span R s := fun _ h => mem_span.2 fun _ hp => hp h @[aesop 80% (rule_sets := [SetLike])] theorem mem_span_of_mem {s : Set M} {x : M} (hx : x ∈ s) : x ∈ span R s := subset_span hx theorem span_le {p} : span R s ≤ p ↔ s ⊆ p := ⟨Subset.trans subset_span, fun ss _ h => mem_span.1 h _ ss⟩ @[gcongr] theorem span_mono (h : s ⊆ t) : span R s ≤ span R t := span_le.2 <| Subset.trans h subset_span theorem span_monotone : Monotone (span R : Set M → Submodule R M) := fun _ _ => span_mono theorem span_eq_of_le (h₁ : s ⊆ p) (h₂ : p ≤ span R s) : span R s = p := le_antisymm (span_le.2 h₁) h₂ theorem span_eq : span R (p : Set M) = p := span_eq_of_le _ (Subset.refl _) subset_span theorem span_eq_span (hs : s ⊆ span R t) (ht : t ⊆ span R s) : span R s = span R t := le_antisymm (span_le.2 hs) (span_le.2 ht) /-- A version of `Submodule.span_eq` for subobjects closed under addition and scalar multiplication and containing zero. In general, this should not be used directly, but can be used to quickly generate proofs for specific types of subobjects. -/ lemma coe_span_eq_self [SetLike S M] [AddSubmonoidClass S M] [SMulMemClass S R M] (s : S) : (span R (s : Set M) : Set M) = s := by refine le_antisymm ?_ subset_span let s' : Submodule R M := { carrier := s add_mem' := add_mem zero_mem' := zero_mem _ smul_mem' := SMulMemClass.smul_mem } exact span_le (p := s') |>.mpr le_rfl @[simp] theorem span_insert_zero : span R (insert (0 : M) s) = span R s := by refine le_antisymm ?_ (Submodule.span_mono (Set.subset_insert 0 s)) rw [span_le, Set.insert_subset_iff] exact ⟨by simp only [SetLike.mem_coe, Submodule.zero_mem], Submodule.subset_span⟩ @[simp] lemma span_sdiff_singleton_zero : span R (s \ {0}) = span R s := by by_cases h : 0 ∈ s · rw [← span_insert_zero, show insert 0 (s \ {0}) = s by simp [h]] · simp [h] theorem closure_subset_span {s : Set M} : (AddSubmonoid.closure s : Set M) ⊆ span R s := (@AddSubmonoid.closure_le _ _ _ (span R s).toAddSubmonoid).mpr subset_span theorem closure_le_toAddSubmonoid_span {s : Set M} : AddSubmonoid.closure s ≤ (span R s).toAddSubmonoid := closure_subset_span @[simp] theorem span_closure {s : Set M} : span R (AddSubmonoid.closure s : Set M) = span R s := le_antisymm (span_le.mpr closure_subset_span) (span_mono AddSubmonoid.subset_closure) /-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is preserved under addition and scalar multiplication, then `p` holds for all elements of the span of `s`. -/ @[elab_as_elim] theorem span_induction {p : (x : M) → x ∈ span R s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_span h)) (zero : p 0 (Submodule.zero_mem _)) (add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) (smul : ∀ (a : R) (x hx), p x hx → p (a • x) (Submodule.smul_mem _ _ ‹_›)) {x} (hx : x ∈ span R s) : p x hx := by let p : Submodule R M := { carrier := { x | ∃ hx, p x hx } add_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, add _ _ _ _ hpx hpy⟩ zero_mem' := ⟨_, zero⟩ smul_mem' := fun r ↦ fun ⟨_, hpx⟩ ↦ ⟨_, smul r _ _ hpx⟩ } exact span_le (p := p) |>.mpr (fun y hy ↦ ⟨subset_span hy, mem y hy⟩) hx |>.elim fun _ ↦ id /-- An induction principle for span membership. This is a version of `Submodule.span_induction` for binary predicates. -/ theorem span_induction₂ {N : Type*} [AddCommMonoid N] [Module R N] {t : Set N} {p : (x : M) → (y : N) → x ∈ span R s → y ∈ span R t → Prop} (mem_mem : ∀ (x) (y) (hx : x ∈ s) (hy : y ∈ t), p x y (subset_span hx) (subset_span hy)) (zero_left : ∀ y hy, p 0 y (zero_mem _) hy) (zero_right : ∀ x hx, p x 0 hx (zero_mem _)) (add_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x + y) z (add_mem hx hy) hz) (add_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y + z) hx (add_mem hy hz)) (smul_left : ∀ (r : R) x y hx hy, p x y hx hy → p (r • x) y (smul_mem _ r hx) hy) (smul_right : ∀ (r : R) x y hx hy, p x y hx hy → p x (r • y) hx (smul_mem _ r hy)) {a : M} {b : N} (ha : a ∈ Submodule.span R s) (hb : b ∈ Submodule.span R t) : p a b ha hb := by induction hb using span_induction with | mem z hz => induction ha using span_induction with | mem _ h => exact mem_mem _ _ h hz | zero => exact zero_left _ _ | add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂ | smul _ _ _ h => exact smul_left _ _ _ _ _ h | zero => exact zero_right a ha | add _ _ _ _ h₁ h₂ => exact add_right _ _ _ _ _ _ h₁ h₂ | smul _ _ _ h => exact smul_right _ _ _ _ _ h open AddSubmonoid in theorem span_eq_closure {s : Set M} : (span R s).toAddSubmonoid = closure (@univ R • s) := by refine le_antisymm (fun x (hx : x ∈ span R s) ↦ ?of_mem_span) (fun x hx ↦ ?of_mem_closure) case of_mem_span => induction hx using span_induction with | mem x hx => exact subset_closure ⟨1, trivial, x, hx, one_smul R x⟩ | zero => exact zero_mem _ | add _ _ _ _ h₁ h₂ => exact add_mem h₁ h₂ | smul r₁ y _h hy => clear _h induction hy using closure_induction with | mem _ h => obtain ⟨r₂, -, x, hx, rfl⟩ := h exact subset_closure ⟨r₁ * r₂, trivial, x, hx, mul_smul ..⟩ | zero => simp only [smul_zero, zero_mem] | add _ _ _ _ h₁ h₂ => simpa only [smul_add] using add_mem h₁ h₂ case of_mem_closure => refine closure_le.2 ?_ hx rintro - ⟨r, -, x, hx, rfl⟩ exact smul_mem _ _ (subset_span hx) open AddSubmonoid in /-- A variant of `span_induction` that combines `∀ x ∈ s, p x` and `∀ r x, p x → p (r • x)` into a single condition `∀ r, ∀ x ∈ s, p (r • x)`, which can be easier to verify. -/ @[elab_as_elim] theorem closure_induction {p : (x : M) → x ∈ span R s → Prop} (zero : p 0 (Submodule.zero_mem _)) (add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) (smul_mem : ∀ (r x) (h : x ∈ s), p (r • x) (Submodule.smul_mem _ _ <| subset_span h)) {x} (hx : x ∈ span R s) : p x hx := by have key {v} : v ∈ span R s ↔ v ∈ closure (@univ R • s) := by simp [← span_eq_closure] refine AddSubmonoid.closure_induction (motive := fun x hx ↦ p x (key.mpr hx)) ?_ zero (by simpa only [key] using add) (key.mp hx) rintro - ⟨r, -, x, hx, rfl⟩ exact smul_mem r x hx @[simp] theorem span_span_coe_preimage : span R (((↑) : span R s → M) ⁻¹' s) = ⊤ := eq_top_iff.2 fun x _ ↦ Subtype.recOn x fun _ hx' ↦ span_induction (fun _ h ↦ subset_span h) (zero_mem _) (fun _ _ _ _ ↦ add_mem) (fun _ _ _ ↦ smul_mem _ _) hx' @[simp] lemma span_setOf_mem_eq_top : span R {x : span R s | (x : M) ∈ s} = ⊤ := span_span_coe_preimage theorem span_nat_eq_addSubmonoidClosure (s : Set M) : (span ℕ s).toAddSubmonoid = AddSubmonoid.closure s := by refine Eq.symm (AddSubmonoid.closure_eq_of_le subset_span ?_) apply (OrderIso.to_galoisConnection (AddSubmonoid.toNatSubmodule (M := M)).symm).l_le (a := span ℕ s) (b := AddSubmonoid.closure s) rw [span_le] exact AddSubmonoid.subset_closure @[deprecated (since := "2025-08-20")] alias span_nat_eq_addSubmonoid_closure := span_nat_eq_addSubmonoidClosure @[simp] theorem span_nat_eq (s : AddSubmonoid M) : (span ℕ (s : Set M)).toAddSubmonoid = s := by rw [span_nat_eq_addSubmonoidClosure, s.closure_eq] theorem span_int_eq_addSubgroupClosure {M : Type*} [AddCommGroup M] (s : Set M) : (span ℤ s).toAddSubgroup = AddSubgroup.closure s := Eq.symm <| AddSubgroup.closure_eq_of_le _ subset_span fun _ hx => span_induction (fun _ hx => AddSubgroup.subset_closure hx) (AddSubgroup.zero_mem _) (fun _ _ _ _ => AddSubgroup.add_mem _) (fun _ _ _ _ => AddSubgroup.zsmul_mem _ ‹_› _) hx @[deprecated (since := "2025-08-20")] alias span_int_eq_addSubgroup_closure := span_int_eq_addSubgroupClosure @[simp] theorem span_int_eq {M : Type*} [AddCommGroup M] (s : AddSubgroup M) : (span ℤ (s : Set M)).toAddSubgroup = s := by rw [span_int_eq_addSubgroupClosure, s.closure_eq] theorem _root_.Disjoint.of_span (hst : Disjoint (span R s) (span R t)) : Disjoint (s \ {0}) t := by rw [disjoint_iff_forall_ne] rintro v ⟨hvs, hv0 : v ≠ 0⟩ _ hvt rfl exact hv0 <| (disjoint_def.1 hst) v (subset_span hvs) (subset_span hvt) theorem _root_.Disjoint.of_span₀ (hst : Disjoint (span R s) (span R t)) (h0s : 0 ∉ s) : Disjoint s t := by rw [← diff_singleton_eq_self h0s] exact hst.of_span section variable (R M) /-- `span` forms a Galois insertion with the coercion from submodule to set. -/ protected def gi : GaloisInsertion (@span R M _ _ _) (↑) where choice s _ := span R s gc _ _ := span_le le_l_u _ := subset_span choice_eq _ _ := rfl end @[simp] theorem span_empty : span R (∅ : Set M) = ⊥ := (Submodule.gi R M).gc.l_bot @[simp] theorem span_univ : span R (univ : Set M) = ⊤ := eq_top_iff.2 <| SetLike.le_def.2 <| subset_span theorem span_union (s t : Set M) : span R (s ∪ t) = span R s ⊔ span R t := (Submodule.gi R M).gc.l_sup theorem span_iUnion {ι} (s : ι → Set M) : span R (⋃ i, s i) = ⨆ i, span R (s i) := (Submodule.gi R M).gc.l_iSup theorem span_iUnion₂ {ι} {κ : ι → Sort*} (s : ∀ i, κ i → Set M) : span R (⋃ (i) (j), s i j) = ⨆ (i) (j), span R (s i j) := (Submodule.gi R M).gc.l_iSup₂ theorem span_attach_biUnion [DecidableEq M] {α : Type*} (s : Finset α) (f : s → Finset M) : span R (s.attach.biUnion f : Set M) = ⨆ x, span R (f x) := by simp [span_iUnion] theorem sup_span : p ⊔ span R s = span R (p ∪ s) := by rw [Submodule.span_union, p.span_eq] theorem span_sup : span R s ⊔ p = span R (s ∪ p) := by rw [Submodule.span_union, p.span_eq] notation:1000 /- Note that the character `∙` U+2219 used below is different from the scalar multiplication character `•` U+2022. -/ R " ∙ " x => span R (singleton x) theorem span_eq_iSup_of_singleton_spans (s : Set M) : span R s = ⨆ x ∈ s, R ∙ x := by simp only [← span_iUnion, Set.biUnion_of_singleton s] theorem span_range_eq_iSup {ι : Sort*} {v : ι → M} : span R (range v) = ⨆ i, R ∙ v i := by rw [span_eq_iSup_of_singleton_spans, iSup_range] theorem span_smul_le (s : Set M) (r : R) : span R (r • s) ≤ span R s := by rw [span_le] rintro _ ⟨x, hx, rfl⟩ exact smul_mem (span R s) r (subset_span hx) theorem subset_span_trans {U V W : Set M} (hUV : U ⊆ Submodule.span R V) (hVW : V ⊆ Submodule.span R W) : U ⊆ Submodule.span R W := (Submodule.gi R M).gc.le_u_l_trans hUV hVW @[simp] theorem coe_iSup_of_directed {ι} [Nonempty ι] (S : ι → Submodule R M) (H : Directed (· ≤ ·) S) : ((iSup S : Submodule R M) : Set M) = ⋃ i, S i := let s : Submodule R M := { __ := AddSubmonoid.copy _ _ (AddSubmonoid.coe_iSup_of_directed H).symm smul_mem' := fun r _ hx ↦ have ⟨i, hi⟩ := Set.mem_iUnion.mp hx Set.mem_iUnion.mpr ⟨i, (S i).smul_mem' r hi⟩ } have : iSup S = s := le_antisymm (iSup_le fun i ↦ le_iSup (fun i ↦ (S i : Set M)) i) (Set.iUnion_subset fun _ ↦ le_iSup S _) this.symm ▸ rfl @[simp] theorem mem_iSup_of_directed {ι} [Nonempty ι] (S : ι → Submodule R M) (H : Directed (· ≤ ·) S) {x} : x ∈ iSup S ↔ ∃ i, x ∈ S i := by rw [← SetLike.mem_coe, coe_iSup_of_directed S H, mem_iUnion] rfl theorem mem_sSup_of_directed {s : Set (Submodule R M)} {z} (hs : s.Nonempty) (hdir : DirectedOn (· ≤ ·) s) : z ∈ sSup s ↔ ∃ y ∈ s, z ∈ y := by have : Nonempty s := hs.to_subtype simp only [sSup_eq_iSup', mem_iSup_of_directed _ hdir.directed_val, SetCoe.exists, exists_prop] @[norm_cast, simp] theorem coe_iSup_of_chain (a : ℕ →o Submodule R M) : (↑(⨆ k, a k) : Set M) = ⋃ k, (a k : Set M) := coe_iSup_of_directed a a.monotone.directed_le @[simp] theorem mem_iSup_of_chain (a : ℕ →o Submodule R M) (m : M) : (m ∈ ⨆ k, a k) ↔ ∃ k, m ∈ a k := mem_iSup_of_directed a a.monotone.directed_le section variable {p p'} theorem mem_sup : x ∈ p ⊔ p' ↔ ∃ y ∈ p, ∃ z ∈ p', y + z = x := ⟨fun h => by rw [← span_eq p, ← span_eq p', ← span_union] at h refine span_induction ?_ ?_ ?_ ?_ h · rintro y (h | h) · exact ⟨y, h, 0, by simp, by simp⟩ · exact ⟨0, by simp, y, h, by simp⟩ · exact ⟨0, by simp, 0, by simp⟩ · rintro _ _ - - ⟨y₁, hy₁, z₁, hz₁, rfl⟩ ⟨y₂, hy₂, z₂, hz₂, rfl⟩ exact ⟨_, add_mem hy₁ hy₂, _, add_mem hz₁ hz₂, by rw [add_assoc, add_assoc, ← add_assoc y₂, ← add_assoc z₁, add_comm y₂]⟩ · rintro a - _ ⟨y, hy, z, hz, rfl⟩ exact ⟨_, smul_mem _ a hy, _, smul_mem _ a hz, by simp [smul_add]⟩, by rintro ⟨y, hy, z, hz, rfl⟩ exact add_mem ((le_sup_left : p ≤ p ⊔ p') hy) ((le_sup_right : p' ≤ p ⊔ p') hz)⟩ theorem mem_sup' : x ∈ p ⊔ p' ↔ ∃ (y : p) (z : p'), (y : M) + z = x := mem_sup.trans <| by simp only [Subtype.exists, exists_prop] theorem codisjoint_iff_exists_add_eq : Codisjoint p p' ↔ ∀ z, ∃ x y, x ∈ p ∧ y ∈ p' ∧ x + y = z := by rw [codisjoint_iff, eq_top_iff'] exact forall_congr' (fun z => mem_sup.trans <| by simp) @[deprecated (since := "2025-07-05")] alias ⟨exists_add_eq_of_codisjoint, _⟩ := codisjoint_iff_exists_add_eq variable (p p') theorem coe_sup : ↑(p ⊔ p') = (p + p' : Set M) := by ext rw [SetLike.mem_coe, mem_sup, Set.mem_add] simp theorem sup_toAddSubmonoid : (p ⊔ p').toAddSubmonoid = p.toAddSubmonoid ⊔ p'.toAddSubmonoid := by ext x rw [mem_toAddSubmonoid, mem_sup, AddSubmonoid.mem_sup] rfl theorem sup_eq_top_iff : p ⊔ p' = ⊤ ↔ ∀ m : M, ∃ u ∈ p, ∃ v ∈ p', m = u + v := by rw [eq_top_iff'] refine forall_congr' fun m ↦ ?_ rw [mem_sup] tauto end @[simp] theorem mem_span_singleton_self (x : M) : x ∈ R ∙ x := subset_span rfl theorem nontrivial_span_singleton {x : M} (h : x ≠ 0) : Nontrivial (R ∙ x) := ⟨by use 0, ⟨x, Submodule.mem_span_singleton_self x⟩ intro H rw [eq_comm, Submodule.mk_eq_zero] at H exact h H⟩ theorem mem_span_singleton {y : M} : (x ∈ R ∙ y) ↔ ∃ a : R, a • y = x := ⟨fun h => by refine span_induction ?_ ?_ ?_ ?_ h · rintro y (rfl | ⟨⟨_⟩⟩) exact ⟨1, by simp⟩ · exact ⟨0, by simp⟩ · rintro _ _ - - ⟨a, rfl⟩ ⟨b, rfl⟩ exact ⟨a + b, by simp [add_smul]⟩ · rintro a _ - ⟨b, rfl⟩ exact ⟨a * b, by simp [smul_smul]⟩, by rintro ⟨a, y, rfl⟩; exact smul_mem _ _ (subset_span <| by simp)⟩ theorem le_span_singleton_iff {s : Submodule R M} {v₀ : M} : (s ≤ R ∙ v₀) ↔ ∀ v ∈ s, ∃ r : R, r • v₀ = v := by simp_rw [SetLike.le_def, mem_span_singleton] variable (R) theorem span_singleton_eq_top_iff (x : M) : (R ∙ x) = ⊤ ↔ ∀ v, ∃ r : R, r • x = v := by rw [eq_top_iff, le_span_singleton_iff] tauto @[simp] theorem span_zero_singleton : (R ∙ (0 : M)) = ⊥ := by ext simp [mem_span_singleton, eq_comm] theorem span_singleton_eq_range (y : M) : ↑(R ∙ y) = range ((· • y) : R → M) := Set.ext fun _ => mem_span_singleton theorem span_singleton_smul_le {S} [SMul S R] [SMul S M] [IsScalarTower S R M] (r : S) (x : M) : (R ∙ r • x) ≤ R ∙ x := by rw [span_le, Set.singleton_subset_iff, SetLike.mem_coe] exact smul_of_tower_mem _ _ (mem_span_singleton_self _) theorem span_singleton_group_smul_eq {G} [Group G] [SMul G R] [MulAction G M] [IsScalarTower G R M] (g : G) (x : M) : (R ∙ g • x) = R ∙ x := by refine le_antisymm (span_singleton_smul_le R g x) ?_ convert span_singleton_smul_le R g⁻¹ (g • x) exact (inv_smul_smul g x).symm variable {R} theorem span_singleton_smul_eq {r : R} (hr : IsUnit r) (x : M) : (R ∙ r • x) = R ∙ x := by lift r to Rˣ using hr rw [← Units.smul_def] exact span_singleton_group_smul_eq R r x theorem mem_span_singleton_trans {x y z : M} (hxy : x ∈ R ∙ y) (hyz : y ∈ R ∙ z) : x ∈ R ∙ z := by rw [← SetLike.mem_coe, ← singleton_subset_iff] at * exact Submodule.subset_span_trans hxy hyz theorem span_insert (x) (s : Set M) : span R (insert x s) = (R ∙ x) ⊔ span R s := by rw [insert_eq, span_union] theorem span_insert_eq_span (h : x ∈ span R s) : span R (insert x s) = span R s := span_eq_of_le _ (Set.insert_subset_iff.mpr ⟨h, subset_span⟩) (span_mono <| subset_insert _ _) theorem span_span : span R (span R s : Set M) = span R s := span_eq _ theorem mem_span_insert {y} : x ∈ span R (insert y s) ↔ ∃ a : R, ∃ z ∈ span R s, x = a • y + z := by simp [span_insert, mem_sup, mem_span_singleton, eq_comm (a := x)] theorem mem_span_pair {x y z : M} : z ∈ span R ({x, y} : Set M) ↔ ∃ a b : R, a • x + b • y = z := by simp_rw [mem_span_insert, mem_span_singleton, exists_exists_eq_and, eq_comm] theorem mem_span_triple {w x y z : M} : w ∈ span R ({x, y, z} : Set M) ↔ ∃ a b c : R, a • x + b • y + c • z = w := by rw [mem_span_insert] simp_rw [mem_span_pair] refine exists_congr fun a ↦ ⟨?_, ?_⟩ · rintro ⟨u, ⟨b, c, rfl⟩, rfl⟩ exact ⟨b, c, by rw [add_assoc]⟩ · rintro ⟨b, c, rfl⟩ exact ⟨b • y + c • z, ⟨b, c, rfl⟩, by rw [add_assoc]⟩ @[simp] theorem span_eq_bot : span R (s : Set M) = ⊥ ↔ ∀ x ∈ s, (x : M) = 0 := eq_bot_iff.trans ⟨fun H _ h => (mem_bot R).1 <| H <| subset_span h, fun H => span_le.2 fun x h => (mem_bot R).2 <| H x h⟩ theorem span_singleton_eq_bot : (R ∙ x) = ⊥ ↔ x = 0 := by simp @[simp] theorem span_zero : span R (0 : Set M) = ⊥ := by rw [← singleton_zero, span_singleton_eq_bot] @[simp] theorem span_singleton_le_iff_mem (m : M) (p : Submodule R M) : (R ∙ m) ≤ p ↔ m ∈ p := by rw [span_le, singleton_subset_iff, SetLike.mem_coe] theorem iSup_span {ι : Sort*} (p : ι → Set M) : ⨆ i, span R (p i) = span R (⋃ i, p i) := le_antisymm (iSup_le fun i => span_mono <| subset_iUnion _ i) <| span_le.mpr <| iUnion_subset fun i _ hm => mem_iSup_of_mem i <| subset_span hm theorem iSup_eq_span {ι : Sort*} (p : ι → Submodule R M) : ⨆ i, p i = span R (⋃ i, ↑(p i)) := by simp_rw [← iSup_span, span_eq] theorem iSup_eq_span' {ι : Sort*} (p : ι → Submodule R M) (h : ι → Prop) : (⨆ (i : ι) (_ : h i), p i) = Submodule.span R (⋃ (i : ι) (_ : h i), ↑(p i)) := by simp_rw [← Submodule.iSup_span, Submodule.span_eq] /-- A submodule is equal to the supremum of the spans of the submodule's nonzero elements. -/ theorem submodule_eq_sSup_le_nonzero_spans (p : Submodule R M) : p = sSup { T : Submodule R M | ∃ m ∈ p, m ≠ 0 ∧ T = span R {m} } := by let S := { T : Submodule R M | ∃ m ∈ p, m ≠ 0 ∧ T = span R {m} } apply le_antisymm · intro m hm by_cases h : m = 0 · rw [h] simp · exact @le_sSup _ _ S _ ⟨m, ⟨hm, ⟨h, rfl⟩⟩⟩ m (mem_span_singleton_self m) · rw [sSup_le_iff] rintro S ⟨_, ⟨_, ⟨_, rfl⟩⟩⟩ rwa [span_singleton_le_iff_mem] theorem lt_sup_iff_notMem {I : Submodule R M} {a : M} : (I < I ⊔ R ∙ a) ↔ a ∉ I := by simp @[deprecated (since := "2025-05-23")] alias lt_sup_iff_not_mem := lt_sup_iff_notMem theorem mem_iSup {ι : Sort*} (p : ι → Submodule R M) {m : M} : (m ∈ ⨆ i, p i) ↔ ∀ N, (∀ i, p i ≤ N) → m ∈ N := by rw [← span_singleton_le_iff_mem, le_iSup_iff] simp only [span_singleton_le_iff_mem] theorem mem_sSup {s : Set (Submodule R M)} {m : M} : (m ∈ sSup s) ↔ ∀ N, (∀ p ∈ s, p ≤ N) → m ∈ N := by simp_rw [sSup_eq_iSup, Submodule.mem_iSup, iSup_le_iff] section /-- For every element in the span of a set, there exists a finite subset of the set such that the element is contained in the span of the subset. -/ theorem mem_span_finite_of_mem_span {S : Set M} {x : M} (hx : x ∈ span R S) : ∃ T : Finset M, ↑T ⊆ S ∧ x ∈ span R (T : Set M) := by classical refine span_induction (fun x hx => ?_) ?_ ?_ ?_ hx · refine ⟨{x}, ?_, ?_⟩ · rwa [Finset.coe_singleton, Set.singleton_subset_iff] · rw [Finset.coe_singleton] exact Submodule.mem_span_singleton_self x · use ∅ simp · rintro x y - - ⟨X, hX, hxX⟩ ⟨Y, hY, hyY⟩ refine ⟨X ∪ Y, ?_, ?_⟩ · rw [Finset.coe_union] exact Set.union_subset hX hY rw [Finset.coe_union, span_union, mem_sup] exact ⟨x, hxX, y, hyY, rfl⟩ · rintro a x - ⟨T, hT, h2⟩ exact ⟨T, hT, smul_mem _ _ h2⟩ theorem subset_span_finite_of_subset_span {s : Set M} {t : Finset M} (ht : (t : Set M) ⊆ span R s) : ∃ T : Finset M, ↑T ⊆ s ∧ (t : Set M) ⊆ span R (T : Set M) := by classical induction t using Finset.induction_on with | empty => exact ⟨∅, by simp⟩ | insert a t hat IH => obtain ⟨T, hTs, htT⟩ := IH (by simp_all [Set.insert_subset_iff]) obtain ⟨T', hT's, haT'⟩ := mem_span_finite_of_mem_span (ht (Finset.mem_insert_self _ _)) refine ⟨T ∪ T', by simp_all, ?_⟩ simp only [Finset.coe_insert, Finset.coe_union, span_union, insert_subset_iff, SetLike.mem_coe] exact ⟨mem_sup_right haT', htT.trans (le_sup_left (a := span R _))⟩ end end AddCommMonoid section AddCommGroup variable [Ring R] [AddCommGroup M] [Module R M] {ι : Type*} [DecidableEq ι] {i j : ι} lemma sup_toAddSubgroup (p p' : Submodule R M) : (p ⊔ p').toAddSubgroup = p.toAddSubgroup ⊔ p'.toAddSubgroup := by ext x rw [mem_toAddSubgroup, mem_sup, AddSubgroup.mem_sup] rfl theorem mem_span_insert' {x y} {s : Set M} : x ∈ span R (insert y s) ↔ ∃ a : R, x + a • y ∈ span R s := by rw [mem_span_insert]; constructor · rintro ⟨a, z, hz, rfl⟩ exact ⟨-a, by simp [hz, add_assoc]⟩ · rintro ⟨a, h⟩ exact ⟨-a, _, h, by simp [add_comm]⟩ lemma span_range_update_add_smul (hij : i ≠ j) (v : ι → M) (r : R) : span R (Set.range (Function.update v j (v j + r • v i))) = span R (Set.range v) := by refine le_antisymm ?_ ?_ <;> simp only [span_le, Set.range_subset_iff, SetLike.mem_coe] <;> intro k <;> obtain rfl | hjk := eq_or_ne j k · rw [update_self] exact add_mem (subset_span ⟨j, rfl⟩) <| smul_mem _ _ <| subset_span ⟨i, rfl⟩ · exact subset_span ⟨k, (update_of_ne hjk.symm ..).symm⟩ · nth_rw 2 [← add_sub_cancel_right (v j) (r • v i)] exact sub_mem (subset_span ⟨j, update_self ..⟩) (smul_mem _ _ (subset_span ⟨i, update_of_ne hij ..⟩)) · exact subset_span ⟨k, update_of_ne hjk.symm ..⟩ lemma span_range_update_sub_smul (hij : i ≠ j) (v : ι → M) (r : R) : span R (Set.range (Function.update v j (v j - r • v i))) = span R (Set.range v) := by rw [sub_eq_add_neg, ← neg_smul, span_range_update_add_smul hij] end AddCommGroup end Submodule
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/QuadraticModuleCat.lean
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 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. -/ abbrev of {X : Type v} [AddCommGroup X] [Module R X] (Q : QuadraticForm R X) : QuadraticModuleCat R := { ModuleCat.of R X with 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) where /-- The underlying isometry -/ toIsometry' : V.form →qᵢ W.form 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'⟩ instance concreteCategory : ConcreteCategory (QuadraticModuleCat.{v} R) fun V W => V.form →qᵢ W.form where hom f := f.toIsometry' ofHom f := ⟨f⟩ /-- Turn a morphism in `QuadraticModuleCat` back into a `Isometry`. -/ abbrev Hom.toIsometry {X Y : QuadraticModuleCat R} (f : Hom X Y) := ConcreteCategory.hom (C := QuadraticModuleCat R) f /-- Typecheck a `QuadraticForm.Isometry` as a morphism in `Module R`. -/ abbrev ofHom {X Y : Type v} [AddCommGroup X] [Module R X] [AddCommGroup Y] [Module R Y] {Q₁ : QuadraticForm R X} {Q₂ : QuadraticForm R Y} (f : Q₁ →qᵢ Q₂) : of Q₁ ⟶ of Q₂ := ConcreteCategory.ofHom f lemma Hom.toIsometry_injective (V W : QuadraticModuleCat.{v} R) : Function.Injective (Hom.toIsometry : Hom V W → _) := fun ⟨f⟩ ⟨g⟩ _ => by congr @[ext] lemma hom_ext {M N : QuadraticModuleCat.{v} R} (f g : M ⟶ N) (h : f.toIsometry = g.toIsometry) : f = g := Hom.ext h @[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 hasForgetToModule : HasForget₂ (QuadraticModuleCat R) (ModuleCat R) where forget₂ := { obj := fun M => ModuleCat.of R M map := fun f => ModuleCat.ofHom 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 = ModuleCat.ofHom 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 := ofHom e.toIsometry inv := ofHom 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
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/TensorProduct.lean
import Mathlib.LinearAlgebra.BilinearForm.TensorProduct import Mathlib.LinearAlgebra.QuadraticForm.Basic /-! # The quadratic form on a tensor product ## Main definitions * `QuadraticForm.tensorDistrib (Q₁ ⊗ₜ Q₂)`: the quadratic form on `M₁ ⊗ M₂` constructed by applying `Q₁` on `M₁` and `Q₂` on `M₂`. This construction is not available in characteristic two. -/ universe uR uA uM₁ uM₂ uN₁ uN₂ variable {R : Type uR} {A : Type uA} {M₁ : Type uM₁} {M₂ : Type uM₂} {N₁ : Type uN₁} {N₂ : Type uN₂} open LinearMap (BilinMap BilinForm) open TensorProduct QuadraticMap section CommRing variable [CommRing R] [CommRing A] variable [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup N₁] [AddCommGroup N₂] variable [Algebra R A] [Module R M₁] [Module A M₁] [Module R N₁] [Module A N₁] variable [SMulCommClass R A M₁] [IsScalarTower R A M₁] [IsScalarTower R A N₁] variable [Module R M₂] [Module R N₂] section InvertibleTwo variable [Invertible (2 : R)] namespace QuadraticMap variable (R A) in /-- The tensor product of two quadratic maps injects into quadratic maps on tensor products. Note this is heterobasic; the quadratic map on the left can take values in a module over a larger ring than the one on the right. -/ def tensorDistrib : QuadraticMap A M₁ N₁ ⊗[R] QuadraticMap R M₂ N₂ →ₗ[A] QuadraticMap A (M₁ ⊗[R] M₂) (N₁ ⊗[R] N₂) := letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm -- while `letI`s would produce a better term than `let`, they would make this already-slow -- definition even slower. let toQ := BilinMap.toQuadraticMapLinearMap A A (M₁ ⊗[R] M₂) let tmulB := BilinMap.tensorDistrib R A (M₁ := M₁) (M₂ := M₂) let toB := AlgebraTensorModule.map (QuadraticMap.associated : QuadraticMap A M₁ N₁ →ₗ[A] BilinMap A M₁ N₁) (QuadraticMap.associated : QuadraticMap R M₂ N₂ →ₗ[R] BilinMap R M₂ N₂) toQ ∘ₗ tmulB ∘ₗ toB @[simp] theorem tensorDistrib_tmul (Q₁ : QuadraticMap A M₁ N₁) (Q₂ : QuadraticMap R M₂ N₂) (m₁ : M₁) (m₂ : M₂) : tensorDistrib R A (Q₁ ⊗ₜ Q₂) (m₁ ⊗ₜ m₂) = Q₁ m₁ ⊗ₜ Q₂ m₂ := letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm (BilinMap.tensorDistrib_tmul _ _ _ _ _ _).trans <| congr_arg₂ _ (associated_eq_self_apply _ _ _) (associated_eq_self_apply _ _ _) /-- The tensor product of two quadratic maps, a shorthand for dot notation. -/ protected abbrev tmul (Q₁ : QuadraticMap A M₁ N₁) (Q₂ : QuadraticMap R M₂ N₂) : QuadraticMap A (M₁ ⊗[R] M₂) (N₁ ⊗[R] N₂) := tensorDistrib R A (Q₁ ⊗ₜ[R] Q₂) theorem associated_tmul [Invertible (2 : A)] (Q₁ : QuadraticMap A M₁ N₁) (Q₂ : QuadraticMap R M₂ N₂) : (Q₁.tmul Q₂).associated = Q₁.associated.tmul Q₂.associated := by letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm rw [QuadraticMap.tmul, BilinMap.tmul] have : Subsingleton (Invertible (2 : A)) := inferInstance convert associated_left_inverse A (LinearMap.BilinMap.tmul_isSymm (QuadraticMap.associated_isSymm A Q₁) (QuadraticMap.associated_isSymm R Q₂)) end QuadraticMap namespace QuadraticForm variable (R A) in /-- The tensor product of two quadratic forms injects into quadratic forms on tensor products. Note this is heterobasic; the quadratic form on the left can take values in a larger ring than the one on the right. -/ def tensorDistrib : QuadraticForm A M₁ ⊗[R] QuadraticForm R M₂ →ₗ[A] QuadraticForm A (M₁ ⊗[R] M₂) := (AlgebraTensorModule.rid R A A).congrQuadraticMap.toLinearMap ∘ₗ QuadraticMap.tensorDistrib R A -- TODO: make the RHS `MulOpposite.op (Q₂ m₂) • Q₁ m₁` so that this has a nicer defeq for -- `R = A` of `Q₁ m₁ * Q₂ m₂`. @[simp] theorem tensorDistrib_tmul (Q₁ : QuadraticForm A M₁) (Q₂ : QuadraticForm R M₂) (m₁ : M₁) (m₂ : M₂) : tensorDistrib R A (Q₁ ⊗ₜ Q₂) (m₁ ⊗ₜ m₂) = Q₂ m₂ • Q₁ m₁ := letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm (LinearMap.BilinForm.tensorDistrib_tmul _ _ _ _ _ _ _ _).trans <| congr_arg₂ _ (associated_eq_self_apply _ _ _) (associated_eq_self_apply _ _ _) /-- The tensor product of two quadratic forms, a shorthand for dot notation. -/ protected abbrev tmul (Q₁ : QuadraticForm A M₁) (Q₂ : QuadraticForm R M₂) : QuadraticForm A (M₁ ⊗[R] M₂) := tensorDistrib R A (Q₁ ⊗ₜ[R] Q₂) theorem associated_tmul [Invertible (2 : A)] (Q₁ : QuadraticForm A M₁) (Q₂ : QuadraticForm R M₂) : (Q₁.tmul Q₂).associated = BilinForm.tmul Q₁.associated Q₂.associated := by rw [BilinForm.tmul, BilinForm.tensorDistrib, LinearMap.comp_apply, ← BilinMap.tmul, ← QuadraticMap.associated_tmul Q₁ Q₂] aesop theorem polarBilin_tmul [Invertible (2 : A)] (Q₁ : QuadraticForm A M₁) (Q₂ : QuadraticForm R M₂) : polarBilin (Q₁.tmul Q₂) = ⅟(2 : A) • BilinForm.tmul (polarBilin Q₁) (polarBilin Q₂) := by simp_rw [← two_nsmul_associated A, ← two_nsmul_associated R, BilinForm.tmul, tmul_smul, ← smul_tmul', map_nsmul, associated_tmul] rw [smul_comm (_ : A) (_ : ℕ), ← smul_assoc, two_smul _ (_ : A), invOf_two_add_invOf_two, one_smul] variable (A) in /-- The base change of a quadratic form. -/ protected def baseChange (Q : QuadraticForm R M₂) : QuadraticForm A (A ⊗[R] M₂) := QuadraticForm.tmul (R := R) (A := A) (M₁ := A) (M₂ := M₂) (QuadraticMap.sq (R := A)) Q @[simp] theorem baseChange_tmul (Q : QuadraticForm R M₂) (a : A) (m₂ : M₂) : Q.baseChange A (a ⊗ₜ m₂) = Q m₂ • (a * a) := tensorDistrib_tmul _ _ _ _ theorem associated_baseChange [Invertible (2 : A)] (Q : QuadraticForm R M₂) : associated (R := A) (Q.baseChange A) = BilinForm.baseChange A (associated (R := R) Q) := by dsimp only [QuadraticForm.baseChange, LinearMap.baseChange] rw [associated_tmul (QuadraticMap.sq (R := A)) Q, associated_sq] exact rfl theorem polarBilin_baseChange [Invertible (2 : A)] (Q : QuadraticForm R M₂) : polarBilin (Q.baseChange A) = BilinForm.baseChange A (polarBilin Q) := by rw [QuadraticForm.baseChange, BilinForm.baseChange, polarBilin_tmul, BilinForm.tmul, ← LinearMap.map_smul, smul_tmul', ← two_nsmul_associated R, coe_associatedHom, associated_sq, smul_comm, ← smul_assoc, two_smul, invOf_two_add_invOf_two, one_smul] end QuadraticForm end InvertibleTwo /-- If two quadratic maps from `A ⊗[R] M₂` agree on elements of the form `1 ⊗ m`, they are equal. In other words, if a base change exists for a quadratic map, it is unique. Note that unlike `QuadraticForm.baseChange`, this does not need `Invertible (2 : R)`. -/ @[ext] theorem baseChange_ext ⦃Q₁ Q₂ : QuadraticMap A (A ⊗[R] M₂) N₁⦄ (h : ∀ m, Q₁ (1 ⊗ₜ m) = Q₂ (1 ⊗ₜ m)) : Q₁ = Q₂ := by replace h (a m) : Q₁ (a ⊗ₜ m) = Q₂ (a ⊗ₜ m) := by rw [← mul_one a, ← smul_eq_mul, ← smul_tmul', QuadraticMap.map_smul, QuadraticMap.map_smul, h] ext x induction x with | tmul => simp [h] | zero => simp | add x y hx hy => have : Q₁.polarBilin = Q₂.polarBilin := by ext dsimp [polar] rw [← TensorProduct.tmul_add, h, h, h] replace := congr($this x y) dsimp [polar] at this linear_combination (norm := module) this + hx + hy end CommRing
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/Isometry.lean
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
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/Prod.lean
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 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.prodCongr 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] [AddLeftMono 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] [AddLeftMono 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_of_nonneg (hle₁ x₁) (hle₂ x₂), ha₁.eq_zero_iff, ha₂.eq_zero_iff] at hx rwa [Prod.mk_eq_zero] theorem PosDef.prod [PartialOrder P] [AddLeftMono 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, 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] 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, 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 ι] [AddCommMonoid P] [PartialOrder P] [IsOrderedAddMonoid 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 ι] [AddCommMonoid P] [PartialOrder P] [IsOrderedAddMonoid 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)] [AddCommGroup P] [∀ i, Module R (Mᵢ i)] [Module R P] [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
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/Basic.lean
import Mathlib.Data.Finset.Sym import Mathlib.LinearAlgebra.BilinearMap import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.SesquilinearForm import Mathlib.LinearAlgebra.Matrix.Symmetric /-! # 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 discussion. ## 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 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*} [AddCommGroup 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, Function.comp_apply, map_sub] /-- `QuadraticMap.polar` as a function from `Sym2`. -/ def polarSym2 (f : M → N) : Sym2 M → N := Sym2.lift ⟨polar f, polar_comm _⟩ @[simp] lemma polarSym2_sym2Mk (f : M → N) (xy : M × M) : polarSym2 f (.mk xy) = polar f xy.1 xy.2 := rfl 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 /-- The underlying function. Do NOT use directly. Use the coercion instead. -/ 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] /-- 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 variable (Q) /-- The `simp` normal form for a quadratic map is `DFunLike.coe`, not `toFun`. -/ @[simp] theorem toFun_eq_coe : Q.toFun = ⇑Q := rfl @[simp] theorem coe_mk (toFun : M → N) (toFun_smul exists_companion') : ⇑({toFun, toFun_smul, exists_companion'} : QuadraticMap R M N) = toFun := rfl -- this must come after the instFunLike 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) protected 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, Q.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), Q.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] [SMul 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, Q.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] protected theorem map_neg (x : M) : Q (-x) = Q x := by rw [← @neg_one_smul R _ _ _ _ x, Q.map_smul, neg_one_mul, neg_neg, one_smul] protected theorem map_sub (x y : M) : Q (x - y) = Q (y - x) := by rw [← neg_sub, Q.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] simp /-- `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) lemma polarSym2_map_smul {ι} (Q : QuadraticMap R M N) (g : ι → M) (l : ι → R) (p : Sym2 ι) : polarSym2 Q (p.map (l • g)) = (p.map l).mul • polarSym2 Q (p.map g) := by obtain ⟨_, _⟩ := p; simp [← smul_assoc, mul_comm] 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 ∈ s.sym2 with ¬ ij.IsDiag, polarSym2 Q (ij.map f) := 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.map_pair_eq, polarSym2_sym2Mk, ← 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 ∈ s.sym2, polarSym2 Q (ij.map f) - ∑ 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.map_pair_eq, polarSym2_sym2Mk, ← 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, Q.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, norm_cast] 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, norm_cast] 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, QuadraticMap.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, norm_cast] 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, norm_cast] 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, Q.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, norm_cast] 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, norm_cast] 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 `Q : M → N` is a quadratic map of `R`-modules and `R` is an `S`-algebra, then the restriction of scalars is a quadratic map of `S`-modules. -/ @[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 [Q.map_smul, 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 +simpRhs] 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 [Q.map_smul, 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! +simpRhs] 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 /-- When `N` and `P` are equivalent, quadratic maps on `M` into `N` are equivalent to quadratic maps on `M` into `P`. See `LinearMap.BilinMap.congr₂` for the bilinear map version. -/ @[simps] def _root_.LinearEquiv.congrQuadraticMap (e : N ≃ₗ[R] P) : QuadraticMap R M N ≃ₗ[R] QuadraticMap R M P where toFun Q := e.compQuadraticMap Q invFun Q := e.symm.compQuadraticMap Q left_inv _ := ext fun _ => e.symm_apply_apply _ right_inv _ := ext fun _ => e.apply_symm_apply _ map_add' _ _ := ext fun _ => map_add e _ _ map_smul' _ _ := ext fun _ => e.map_smul _ _ @[simp] theorem _root_.LinearEquiv.congrQuadraticMap_refl : LinearEquiv.congrQuadraticMap (.refl R N) = .refl R (QuadraticMap R M N) := rfl @[simp] theorem _root_.LinearEquiv.congrQuadraticMap_symm (e : N ≃ₗ[R] P) : (LinearEquiv.congrQuadraticMap e (M := M)).symm = e.symm.congrQuadraticMap := rfl 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 maps into an `R`-algebra is a quadratic map. -/ 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] 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 map sending 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 map sending 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 If multiplication by 2 is invertible on the target module `N` of `QuadraticMap R M N`, then there is a linear bijection `QuadraticMap.associated` between quadratic maps `Q` over `R` from `M` to `N` and symmetric bilinear maps `B : M →ₗ[R] M →ₗ[R] → N` such that `BilinMap.toQuadraticMap B = Q` (see `QuadraticMap.associated_rightInverse`). The associated bilinear map is half `Q.polarBilin` (see `QuadraticMap.two_nsmul_associated`); this is where the invertibility condition comes from. We spell the condition as `[Invertible (2 : Module.End R N)]`. Note that this makes the bijection available in more cases than the simpler condition `Invertible (2 : R)`, e.g., when `R = ℤ` and `N = ℝ`. -/ 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 [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.BilinMap.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.BilinMap.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'] 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 variable [Semiring R] [AddCommMonoid M] [Module R M] instance : SMulCommClass R (Submonoid.center R) M where smul_comm r r' m := by simp_rw [Submonoid.smul_def, smul_smul, ((Set.mem_center_iff.1 r'.prop).1 _).eq] /-- If `2` is invertible in `R`, then it is also invertible in `End R M`. -/ instance [Invertible (2 : R)] : Invertible (2 : Module.End R M) where invOf := (⟨⅟2, Set.invOf_mem_center (Set.ofNat_mem_center _ _)⟩ : Submonoid.center R) • (1 : Module.End R M) invOf_mul_self := by ext m dsimp [Submonoid.smul_def] rw [← ofNat_smul_eq_nsmul R, invOf_smul_smul (2 : R) m] mul_invOf_self := by ext m dsimp [Submonoid.smul_def] rw [← ofNat_smul_eq_nsmul R, smul_invOf_smul (2 : R) m] /-- If `2` is invertible in `R`, then applying the inverse of `2` in `End R M` to an element of `M` is the same as multiplying by the inverse of `2` in `R`. -/ @[simp] lemma half_moduleEnd_apply_eq_half_smul [Invertible (2 : R)] (x : M) : ⅟(2 : Module.End R M) x = ⅟(2 : R) • x := rfl end section AssociatedHom variable [CommRing R] [AddCommGroup M] [Module R M] variable [AddCommGroup N] [Module R N] variable (S) [CommSemiring S] [Algebra S R] [Module S N] [IsScalarTower S R N] -- the requirement that multiplication by `2` is invertible on the target module `N` variable [Invertible (2 : Module.End R N)] /-- `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 ring and `R` is an `S`-algebra. 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) where toFun Q := ⅟(2 : Module.End R N) • polarBilin Q map_add' _ _ := LinearMap.ext₂ fun _ _ ↦ by simp [polar_add] map_smul' _ _ := LinearMap.ext₂ fun _ _ ↦ by simp [polar_smul] variable (Q : QuadraticMap R M N) @[simp] theorem associated_apply (x y : M) : associatedHom S Q x y = ⅟(2 : Module.End R N) • (Q (x + y) - Q x - Q y) := rfl /-- Twice the associated bilinear map of `Q` is the same as the polar of `Q`. -/ @[simp] theorem two_nsmul_associated : 2 • associatedHom S Q = Q.polarBilin := by ext dsimp rw [← LinearMap.smul_apply, nsmul_eq_mul, Nat.cast_ofNat, mul_invOf_self', Module.End.one_apply, polar] theorem associated_isSymm (Q : QuadraticMap R M N) (x y : M) : associatedHom S Q x y = associatedHom S Q y x := by simp only [associated_apply, sub_eq_add_neg, add_assoc, add_comm, add_left_comm] theorem _root_.QuadraticForm.associated_isSymm (Q : QuadraticForm R M) [Invertible (2 : R)] : (associatedHom S Q).IsSymm := ⟨QuadraticMap.associated_isSymm S Q⟩ /-- A version of `QuadraticMap.associated_isSymm` for general targets (using `flip` because `IsSymm` does not apply here). -/ lemma associated_flip : (associatedHom S Q).flip = associatedHom S Q := by ext simp only [LinearMap.flip_apply, associated_apply, add_comm, sub_eq_add_neg, add_left_comm, add_assoc] @[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 N) (x y : M) : associatedHom S B.toQuadraticMap x y = ⅟(2 : Module.End R N) • (B x y + B y x) := by simp only [associated_apply, BilinMap.toQuadraticMap_apply, map_add, LinearMap.add_apply, Module.End.smul_def, map_sub] abel_nf theorem associated_left_inverse {B₁ : BilinMap R M N} (h : ∀ x y, B₁ x y = B₁ y x) : associatedHom S B₁.toQuadraticMap = B₁ := LinearMap.ext₂ fun x y ↦ by rw [associated_toQuadraticMap, ← h x y, ← two_smul R, invOf_smul_eq_iff, two_smul, two_smul] /-- A version of `QuadraticMap.associated_left_inverse` for general targets. -/ lemma associated_left_inverse' {B₁ : BilinMap R M N} (hB₁ : B₁.flip = B₁) : associatedHom S B₁.toQuadraticMap = B₁ := by ext _ y rw [associated_toQuadraticMap, ← LinearMap.flip_apply _ y, hB₁, invOf_smul_eq_iff, two_smul] 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, invOf_smul_eq_iff, two_smul, two_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 N) := toQuadraticMap_associated S /-- `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 N →ₗ[ℤ] BilinMap R M N := associatedHom ℤ /-- Symmetric bilinear forms can be lifted to quadratic forms -/ instance canLift [Invertible (2 : R)] : CanLift (BilinMap R M R) (QuadraticForm R M) (associatedHom ℕ) LinearMap.IsSymm where prf B := fun ⟨hB⟩ ↦ ⟨B.toQuadraticMap, associated_left_inverse _ hB⟩ /-- Symmetric bilinear maps can be lifted to quadratic maps -/ instance canLift' : CanLift (BilinMap R M N) (QuadraticMap R M N) (associatedHom ℕ) fun B ↦ B.flip = B 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_quadraticMap_ne_zero {Q : QuadraticMap R M N} -- Porting note: added implicit argument (hB₁ : associated' (N := N) 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 : Module.End R N)] -- 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 [Invertible (2 : R)] (f g : M →ₗ[R] R) : associated (R := R) (N := 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, invOf_smul_eq_iff] simp only [Module.End.smul_def, Module.End.ofNat_apply, nsmul_eq_mul, Nat.cast_ofNat, mul_invOf_cancel_left'] ring_nf open LinearMap in @[simp] lemma associated_sq [Invertible (2 : R)] : 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_eq_left (a := B x x + B y y), ← h.eq, 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' (N := 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} [CommSemiring R] [PartialOrder 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 [AddLeftStrictMono 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} [CommSemiring R] [Module R M] [Semiring A] [LinearOrder A] [IsStrictOrderedRing 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 : QuadraticForm R (n → R)) : Q.toMatrix'.IsSymm := by ext i j rw [toMatrix', Matrix.transpose_apply, LinearMap.toMatrix₂'_apply, LinearMap.toMatrix₂'_apply, ← associated_isSymm] 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 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 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_quadraticMap_ne_zero hB₁ exact ⟨x, fun h => hx (Q.associated_eq_self_apply ℕ x ▸ h)⟩ open Module 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 suffices ∀ d, finrank K V = d → ∃ v : Basis (Fin d) K V, B.IsOrthoᵢ v by exact this _ rfl intro d hd induction d generalizing V with | zero => exact ⟨basisOfFinrankZero hd, fun _ _ _ => map_zero _⟩ | succ d ih => 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 := Module.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_cancel, 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₂.eq] 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 Module 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 ι] 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 : QuadraticForm R M) (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, Module.End.smul_def, half_moduleEnd_apply_eq_half_smul] ring_nf · intro i _ hij rw [LinearMap.map_smul, LinearMap.map_smul₂, hv₂ hij] module end QuadraticMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/Complex.lean
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 rw [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, Pi.smul_apply, Pi.smul_apply, Pi.single_eq_same, smul_eq_mul, smul_eq_mul, smul_eq_mul, mul_one] · intro i _ hij rw [Pi.basisFun_apply, Pi.smul_apply, Pi.smul_apply, Pi.single_eq_of_ne hij.symm, smul_eq_mul, smul_eq_mul, mul_zero, mul_zero] intro hj'; exact False.elim (hj' hj) simp_rw [Module.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 -zeta only [one_mul, 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 (Module.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
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/Dual.lean
import Mathlib.LinearAlgebra.Dual.Lemmas import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv import Mathlib.LinearAlgebra.QuadraticForm.Prod /-! # 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 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 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.prodCongr 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.prodCongr (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 only [polar_sub_right, polar_self, nsmul_eq_mul, Nat.cast_ofNat, polar_comm _ x.1 x.2, smul_sub, Module.End.smul_def, sub_add_sub_cancel, ← sub_eq_add_neg (Q x.1) (Q x.2)] rw [← LinearMap.map_sub (⅟2 : Module.End R R), ← mul_sub, ← Module.End.smul_def] simp only [Module.End.smul_def, half_moduleEnd_apply_eq_half_smul, smul_eq_mul, invOf_mul_cancel_left'] /-! TODO: show that `QuadraticForm.toDualProd` is an `QuadraticForm.IsometryEquiv` -/ end Ring end QuadraticForm
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/Basis.lean
import Mathlib.Algebra.BigOperators.Sym import Mathlib.Data.Finsupp.Pointwise import Mathlib.Data.Sym.Sym2.Finsupp 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. -/ open LinearMap (BilinMap) open Module namespace QuadraticMap variable {ι R M N : Type*} section Finsupp variable [CommRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] open Finsupp theorem map_finsuppSum' (Q : QuadraticMap R M N) (f : ι →₀ R) (g : ι → R → M) : Q (f.sum g) = ∑ p ∈ f.support.sym2, polarSym2 Q (p.map fun i ↦ g i (f i)) - f.sum fun i a ↦ Q (g i a) := Q.map_sum' .. theorem apply_linearCombination' (Q : QuadraticMap R M N) {g : ι → M} (l : ι →₀ R) : Q (linearCombination R g l) = linearCombination R (polarSym2 Q ∘ Sym2.map g) l.sym2Mul - linearCombination R (Q ∘ g) (l * l) := by simp_rw [linearCombination_apply, map_finsuppSum', Q.map_smul, mul_smul] rw [(l * l).sum_of_support_subset support_mul_subset_left _ <| by simp, l.sym2Mul.sum_of_support_subset support_sym2Mul_subset _ <| by simp] simp [Finsupp.sum, ← polarSym2_map_smul, mul_smul] theorem sum_polar_sub_repr_sq (Q : QuadraticMap R M N) (bm : Basis ι R M) (x : M) : linearCombination R (polarSym2 Q ∘ Sym2.map bm) (bm.repr x).sym2Mul - linearCombination R (Q ∘ bm) (bm.repr x * bm.repr x) = Q x := by rw [← apply_linearCombination', Basis.linearCombination_repr] variable [DecidableEq ι] /-- The quadratic version of `_root_.map_finsupp_sum`. -/ theorem map_finsuppSum (Q : QuadraticMap R M N) (f : ι →₀ R) (g : ι → R → M) : Q (f.sum g) = f.sum (fun i r ↦ Q (g i r)) + ∑ p ∈ f.support.sym2 with ¬ p.IsDiag, polarSym2 Q (p.map fun i ↦ g i (f i)) := Q.map_sum _ _ /-- The quadratic version of `Finsupp.apply_linearCombination`. -/ theorem apply_linearCombination (Q : QuadraticMap R M N) {g : ι → M} (l : ι →₀ R) : Q (linearCombination R g l) = linearCombination R (Q ∘ g) (l * l) + ∑ p ∈ l.support.sym2 with ¬ p.IsDiag, (p.map l).mul • polarSym2 Q (p.map g) := by simp_rw [linearCombination_apply, map_finsuppSum, Q.map_smul, mul_smul] rw [(l * l).sum_of_support_subset support_mul_subset_left _ <| by simp] simp [Finsupp.sum, ← polarSym2_map_smul, mul_smul] /-- The quadratic version of `LinearMap.sum_repr_mul_repr_mul`. -/ theorem sum_repr_sq_add_sum_repr_mul_polar (Q : QuadraticMap R M N) (bm : Basis ι R M) (x : M) : linearCombination R (Q ∘ bm) (bm.repr x * bm.repr x) + ∑ p ∈ (bm.repr x).support.sym2 with ¬ p.IsDiag, Sym2.mul (p.map (bm.repr x)) • polarSym2 Q (p.map bm) = Q x := by rw [← apply_linearCombination, Basis.linearCombination_repr] end Finsupp variable [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.linearCombination_repr x, LinearMap.BilinMap.toQuadraticMap_apply, Finsupp.linearCombination_apply, Finsupp.sum] simp_rw [LinearMap.map_sum₂, map_sum, LinearMap.map_smul₂, 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⟩ @[simp] lemma add_toBilin (bm : Basis ι R M) (Q₁ Q₂ : QuadraticMap R M N) : (Q₁ + Q₂).toBilin bm = Q₁.toBilin bm + Q₂.toBilin bm := by refine bm.ext fun i => bm.ext fun j => ?_ obtain h | rfl | h := lt_trichotomy i j · simp [h.ne, h, toBilin_apply, polar_add] · simp [toBilin_apply] · simp [h.ne', h.not_gt, toBilin_apply] variable (S) [CommSemiring S] [Algebra S R] variable [Module S N] [IsScalarTower S R N] @[simp] lemma smul_toBilin (bm : Basis ι R M) (s : S) (Q : QuadraticMap R M N) : (s • Q).toBilin bm = s • Q.toBilin bm := by refine bm.ext fun i => bm.ext fun j => ?_ obtain h | rfl | h := lt_trichotomy i j · simp [h.ne, h, toBilin_apply, polar_smul] · simp [toBilin_apply] · simp [h.ne', h.not_gt, toBilin_apply] /-- `QuadraticMap.toBilin` as an S-linear map -/ @[simps] noncomputable def toBilinHom (bm : Basis ι R M) : QuadraticMap R M N →ₗ[S] BilinMap R M N where toFun Q := Q.toBilin bm map_add' := add_toBilin bm map_smul' := smul_toBilin S bm end QuadraticMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/IsometryEquiv.lean
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`. -/ open Module QuadraticMap variable {ι R K M M₁ M₂ M₃ V N : Type*} 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. -/ 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 +contextual instance : LinearEquivClass (Q₁.IsometryEquiv Q₂) R M₁ M₂ where map_add f := map_add f.toLinearEquiv map_smulₛₗ f := map_smulₛₗ f.toLinearEquiv instance : CoeOut (Q₁.IsometryEquiv Q₂) (M₁ ≃ₗ[R] M₂) := ⟨IsometryEquiv.toLinearEquiv⟩ @[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, 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 (Module.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 (Module.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 (Module.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
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/Real.lean
import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv import Mathlib.Data.Sign.Basic import Mathlib.Algebra.CharP.Invertible import Mathlib.Analysis.RCLike.Basic /-! # 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 `QuadraticForm.equivalent_one_zero_neg_one_weighted_sum_squared`. -/ open Finset Module QuadraticMap SignType namespace QuadraticForm 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 · simp [hi] · simp only [hi, ↓reduceDIte, Units.val_mk0, u]; field_simp; simp 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, Pi.single_apply] 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 (Module.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 (Module.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 (Module.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 (Module.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
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/TensorProduct/Isometries.lean
import Mathlib.LinearAlgebra.QuadraticForm.TensorProduct import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv /-! # Linear equivalences of tensor products as isometries These results are separate from the definition of `QuadraticForm.tmul` as that file is very slow. ## Main definitions * `QuadraticForm.Isometry.tmul`: `TensorProduct.map` as a `QuadraticForm.Isometry` * `QuadraticForm.tensorComm`: `TensorProduct.comm` as a `QuadraticForm.IsometryEquiv` * `QuadraticForm.tensorAssoc`: `TensorProduct.assoc` as a `QuadraticForm.IsometryEquiv` * `QuadraticForm.tensorRId`: `TensorProduct.rid` as a `QuadraticForm.IsometryEquiv` * `QuadraticForm.tensorLId`: `TensorProduct.lid` as a `QuadraticForm.IsometryEquiv` -/ universe uR uM₁ uM₂ uM₃ uM₄ variable {R : Type uR} {M₁ : Type uM₁} {M₂ : Type uM₂} {M₃ : Type uM₃} {M₄ : Type uM₄} open scoped TensorProduct open QuadraticMap namespace QuadraticForm variable [CommRing R] variable [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup M₃] [AddCommGroup M₄] variable [Module R M₁] [Module R M₂] [Module R M₃] [Module R M₄] [Invertible (2 : R)] @[simp] theorem tmul_comp_tensorMap {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} {Q₃ : QuadraticForm R M₃} {Q₄ : QuadraticForm R M₄} (f : Q₁ →qᵢ Q₂) (g : Q₃ →qᵢ Q₄) : (Q₂.tmul Q₄).comp (TensorProduct.map f.toLinearMap g.toLinearMap) = Q₁.tmul Q₃ := by have h₁ : Q₁ = Q₂.comp f.toLinearMap := QuadraticMap.ext fun x => (f.map_app x).symm have h₃ : Q₃ = Q₄.comp g.toLinearMap := QuadraticMap.ext fun x => (g.map_app x).symm refine (QuadraticMap.associated_rightInverse R).injective ?_ ext m₁ m₃ m₁' m₃' simp [-associated_apply, h₁, h₃, associated_tmul] @[simp] theorem tmul_tensorMap_apply {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} {Q₃ : QuadraticForm R M₃} {Q₄ : QuadraticForm R M₄} (f : Q₁ →qᵢ Q₂) (g : Q₃ →qᵢ Q₄) (x : M₁ ⊗[R] M₃) : Q₂.tmul Q₄ (TensorProduct.map f.toLinearMap g.toLinearMap x) = Q₁.tmul Q₃ x := DFunLike.congr_fun (tmul_comp_tensorMap f g) x namespace Isometry /-- `TensorProduct.map` for `QuadraticForm.Isometry`s -/ def _root_.QuadraticMap.Isometry.tmul {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} {Q₃ : QuadraticForm R M₃} {Q₄ : QuadraticForm R M₄} (f : Q₁ →qᵢ Q₂) (g : Q₃ →qᵢ Q₄) : (Q₁.tmul Q₃) →qᵢ (Q₂.tmul Q₄) where toLinearMap := TensorProduct.map f.toLinearMap g.toLinearMap map_app' := tmul_tensorMap_apply f g @[simp] theorem _root_.QuadraticMap.Isometry.tmul_apply {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} {Q₃ : QuadraticForm R M₃} {Q₄ : QuadraticForm R M₄} (f : Q₁ →qᵢ Q₂) (g : Q₃ →qᵢ Q₄) (x : M₁ ⊗[R] M₃) : f.tmul g x = TensorProduct.map f.toLinearMap g.toLinearMap x := rfl end Isometry section tensorComm @[simp] theorem tmul_comp_tensorComm (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) : (Q₂.tmul Q₁).comp (TensorProduct.comm R M₁ M₂) = Q₁.tmul Q₂ := by refine (QuadraticMap.associated_rightInverse R).injective ?_ ext m₁ m₂ m₁' m₂' dsimp [-associated_apply] simp only [associated_tmul, QuadraticMap.associated_comp] exact mul_comm _ _ @[simp] theorem tmul_tensorComm_apply (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (x : M₁ ⊗[R] M₂) : Q₂.tmul Q₁ (TensorProduct.comm R M₁ M₂ x) = Q₁.tmul Q₂ x := DFunLike.congr_fun (tmul_comp_tensorComm Q₁ Q₂) x /-- `TensorProduct.comm` preserves tensor products of quadratic forms. -/ @[simps toLinearEquiv] def tensorComm (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) : (Q₁.tmul Q₂).IsometryEquiv (Q₂.tmul Q₁) where toLinearEquiv := TensorProduct.comm R M₁ M₂ map_app' := tmul_tensorComm_apply Q₁ Q₂ @[simp] lemma tensorComm_apply (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (x : M₁ ⊗[R] M₂) : tensorComm Q₁ Q₂ x = TensorProduct.comm R M₁ M₂ x := rfl @[simp] lemma tensorComm_symm (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) : (tensorComm Q₁ Q₂).symm = tensorComm Q₂ Q₁ := rfl end tensorComm section tensorAssoc @[simp] theorem tmul_comp_tensorAssoc (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (Q₃ : QuadraticForm R M₃) : (Q₁.tmul (Q₂.tmul Q₃)).comp (TensorProduct.assoc R M₁ M₂ M₃) = (Q₁.tmul Q₂).tmul Q₃ := by refine (QuadraticMap.associated_rightInverse R).injective ?_ ext m₁ m₂ m₁' m₂' m₁'' m₂'' dsimp [-associated_apply] simp only [associated_tmul, QuadraticMap.associated_comp] exact mul_assoc _ _ _ @[simp] theorem tmul_tensorAssoc_apply (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (Q₃ : QuadraticForm R M₃) (x : (M₁ ⊗[R] M₂) ⊗[R] M₃) : Q₁.tmul (Q₂.tmul Q₃) (TensorProduct.assoc R M₁ M₂ M₃ x) = (Q₁.tmul Q₂).tmul Q₃ x := DFunLike.congr_fun (tmul_comp_tensorAssoc Q₁ Q₂ Q₃) x /-- `TensorProduct.assoc` preserves tensor products of quadratic forms. -/ @[simps toLinearEquiv] def tensorAssoc (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (Q₃ : QuadraticForm R M₃) : ((Q₁.tmul Q₂).tmul Q₃).IsometryEquiv (Q₁.tmul (Q₂.tmul Q₃)) where toLinearEquiv := TensorProduct.assoc R M₁ M₂ M₃ map_app' := tmul_tensorAssoc_apply Q₁ Q₂ Q₃ @[simp] lemma tensorAssoc_apply (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (Q₃ : QuadraticForm R M₃) (x : (M₁ ⊗[R] M₂) ⊗[R] M₃) : tensorAssoc Q₁ Q₂ Q₃ x = TensorProduct.assoc R M₁ M₂ M₃ x := rfl @[simp] lemma tensorAssoc_symm_apply (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (Q₃ : QuadraticForm R M₃) (x : M₁ ⊗[R] (M₂ ⊗[R] M₃)) : (tensorAssoc Q₁ Q₂ Q₃).symm x = (TensorProduct.assoc R M₁ M₂ M₃).symm x := rfl end tensorAssoc section tensorRId theorem comp_tensorRId_eq (Q₁ : QuadraticForm R M₁) : Q₁.comp (TensorProduct.rid R M₁) = Q₁.tmul (sq (R := R)) := by refine (QuadraticMap.associated_rightInverse R).injective ?_ ext m₁ m₁' dsimp [-associated_apply] simp only [associated_tmul, QuadraticMap.associated_comp] simp [-associated_apply, one_mul] @[simp] theorem tmul_tensorRId_apply (Q₁ : QuadraticForm R M₁) (x : M₁ ⊗[R] R) : Q₁ (TensorProduct.rid R M₁ x) = Q₁.tmul (sq (R := R)) x := DFunLike.congr_fun (comp_tensorRId_eq Q₁) x /-- `TensorProduct.rid` preserves tensor products of quadratic forms. -/ @[simps toLinearEquiv] def tensorRId (Q₁ : QuadraticForm R M₁) : (Q₁.tmul (sq (R := R))).IsometryEquiv Q₁ where toLinearEquiv := TensorProduct.rid R M₁ map_app' := tmul_tensorRId_apply Q₁ @[simp] lemma tensorRId_apply (Q₁ : QuadraticForm R M₁) (x : M₁ ⊗[R] R) : tensorRId Q₁ x = TensorProduct.rid R M₁ x := rfl @[simp] lemma tensorRId_symm_apply (Q₁ : QuadraticForm R M₁) (x : M₁) : (tensorRId Q₁).symm x = (TensorProduct.rid R M₁).symm x := rfl end tensorRId section tensorLId theorem comp_tensorLId_eq (Q₂ : QuadraticForm R M₂) : Q₂.comp (TensorProduct.lid R M₂) = QuadraticForm.tmul (sq (R := R)) Q₂ := by ext simp @[simp] theorem tmul_tensorLId_apply (Q₂ : QuadraticForm R M₂) (x : R ⊗[R] M₂) : Q₂ (TensorProduct.lid R M₂ x) = QuadraticForm.tmul (sq (R := R)) Q₂ x := DFunLike.congr_fun (comp_tensorLId_eq Q₂) x /-- `TensorProduct.lid` preserves tensor products of quadratic forms. -/ @[simps toLinearEquiv] def tensorLId (Q₂ : QuadraticForm R M₂) : (QuadraticForm.tmul (sq (R := R)) Q₂).IsometryEquiv Q₂ where toLinearEquiv := TensorProduct.lid R M₂ map_app' := tmul_tensorLId_apply Q₂ @[simp] lemma tensorLId_apply (Q₂ : QuadraticForm R M₂) (x : R ⊗[R] M₂) : tensorLId Q₂ x = TensorProduct.lid R M₂ x := rfl @[simp] lemma tensorLId_symm_apply (Q₂ : QuadraticForm R M₂) (x : M₂) : (tensorLId Q₂).symm x = (TensorProduct.lid R M₂).symm x := rfl end tensorLId end QuadraticForm
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/QuadraticModuleCat/Monoidal.lean
import Mathlib.CategoryTheory.Monoidal.Transport import Mathlib.Algebra.Category.ModuleCat.Monoidal.Basic import Mathlib.LinearAlgebra.QuadraticForm.QuadraticModuleCat import Mathlib.LinearAlgebra.QuadraticForm.TensorProduct.Isometries /-! # The monoidal category structure on quadratic R-modules The monoidal structure is simply the structure on the underlying modules, where the tensor product of two modules is equipped with the form constructed via `QuadraticForm.tmul`. As with the monoidal structure on `ModuleCat`, the universe level of the modules must be at least the universe level of the ring, so that we have a monoidal unit. For now, we simplify by insisting both universe levels are the same. ## Implementation notes This file essentially mirrors `Mathlib/Algebra/Category/AlgCat/Monoidal.lean`. -/ open CategoryTheory open scoped MonoidalCategory universe v u variable {R : Type u} [CommRing R] [Invertible (2 : R)] namespace QuadraticModuleCat open QuadraticMap QuadraticForm namespace instMonoidalCategory /-- Auxiliary definition used to build `QuadraticModuleCat.instMonoidalCategory`. -/ @[simps! form] abbrev tensorObj (X Y : QuadraticModuleCat.{u} R) : QuadraticModuleCat.{u} R := of (X.form.tmul Y.form) /-- Auxiliary definition used to build `QuadraticModuleCat.instMonoidalCategory`. We want this up front so that we can re-use it to define `whiskerLeft` and `whiskerRight`. -/ abbrev tensorHom {W X Y Z : QuadraticModuleCat.{u} R} (f : W ⟶ X) (g : Y ⟶ Z) : tensorObj W Y ⟶ tensorObj X Z := ⟨f.toIsometry.tmul g.toIsometry⟩ open MonoidalCategory end instMonoidalCategory open instMonoidalCategory instance : MonoidalCategoryStruct (QuadraticModuleCat.{u} R) where tensorObj := instMonoidalCategory.tensorObj whiskerLeft X _ _ f := tensorHom (𝟙 X) f whiskerRight {X₁ X₂} (f : X₁ ⟶ X₂) Y := tensorHom f (𝟙 Y) tensorHom := tensorHom tensorUnit := of (sq (R := R)) associator X Y Z := ofIso (tensorAssoc X.form Y.form Z.form) leftUnitor X := ofIso (tensorLId X.form) rightUnitor X := ofIso (tensorRId X.form) theorem toIsometry_tensorHom {K L M N : QuadraticModuleCat.{u} R} (f : K ⟶ L) (g : M ⟶ N) : (f ⊗ₘ g).toIsometry = f.toIsometry.tmul g.toIsometry := rfl theorem toIsometry_whiskerLeft (L : QuadraticModuleCat.{u} R) {M N : QuadraticModuleCat.{u} R} (f : M ⟶ N) : (L ◁ f).toIsometry = .tmul (.id _) f.toIsometry := rfl theorem toIsometry_whiskerRight {L M : QuadraticModuleCat.{u} R} (f : L ⟶ M) (N : QuadraticModuleCat.{u} R) : (f ▷ N).toIsometry = .tmul f.toIsometry (.id _) := rfl theorem toIsometry_hom_leftUnitor {M : QuadraticModuleCat.{u} R} : (λ_ M).hom.toIsometry = (tensorLId _).toIsometry := rfl theorem toIsometry_inv_leftUnitor {M : QuadraticModuleCat.{u} R} : (λ_ M).inv.toIsometry = (tensorLId _).symm.toIsometry := rfl theorem toIsometry_hom_rightUnitor {M : QuadraticModuleCat.{u} R} : (ρ_ M).hom.toIsometry = (tensorRId _).toIsometry := rfl theorem toIsometry_inv_rightUnitor {M : QuadraticModuleCat.{u} R} : (ρ_ M).inv.toIsometry = (tensorRId _).symm.toIsometry := rfl theorem hom_hom_associator {M N K : QuadraticModuleCat.{u} R} : (α_ M N K).hom.toIsometry = (tensorAssoc _ _ _).toIsometry := rfl theorem hom_inv_associator {M N K : QuadraticModuleCat.{u} R} : (α_ M N K).inv.toIsometry = (tensorAssoc _ _ _).symm.toIsometry := rfl @[simp] theorem toModuleCat_tensor (X Y : QuadraticModuleCat.{u} R) : (X ⊗ Y).toModuleCat = X.toModuleCat ⊗ Y.toModuleCat := rfl theorem forget₂_map_associator_hom (X Y Z : QuadraticModuleCat.{u} R) : (forget₂ (QuadraticModuleCat R) (ModuleCat R)).map (α_ X Y Z).hom = (α_ X.toModuleCat Y.toModuleCat Z.toModuleCat).hom := rfl theorem forget₂_map_associator_inv (X Y Z : QuadraticModuleCat.{u} R) : (forget₂ (QuadraticModuleCat R) (ModuleCat R)).map (α_ X Y Z).inv = (α_ X.toModuleCat Y.toModuleCat Z.toModuleCat).inv := rfl instance instMonoidalCategory : MonoidalCategory (QuadraticModuleCat.{u} R) := Monoidal.induced (forget₂ (QuadraticModuleCat R) (ModuleCat R)) { μIso := fun _ _ => Iso.refl _ εIso := Iso.refl _ leftUnitor_eq := fun X => by simp only [forget₂_obj, forget₂_map, Iso.refl_symm, Iso.trans_assoc, Iso.trans_hom, Iso.refl_hom, MonoidalCategory.tensorIso_hom, MonoidalCategory.tensorHom_id] dsimp only [toModuleCat_tensor, ModuleCat.of_coe] erw [MonoidalCategory.id_whiskerRight] simp rfl rightUnitor_eq := fun X => by simp only [forget₂_obj, forget₂_map, Iso.refl_symm, Iso.trans_assoc, Iso.trans_hom, Iso.refl_hom, MonoidalCategory.tensorIso_hom, MonoidalCategory.id_tensorHom] dsimp only [toModuleCat_tensor, ModuleCat.of_coe] erw [MonoidalCategory.whiskerLeft_id] simp rfl associator_eq := fun X Y Z => by dsimp only [forget₂_obj, forget₂_map_associator_hom] simp only [Iso.refl_symm, Iso.trans_hom, MonoidalCategory.tensorIso_hom, Iso.refl_hom, MonoidalCategory.id_tensorHom_id] dsimp only [toModuleCat_tensor, ModuleCat.of_coe] rw [Category.id_comp, Category.id_comp, Category.comp_id, MonoidalCategory.id_tensorHom_id, Category.id_comp] } /-- `forget₂ (QuadraticModuleCat R) (ModuleCat R)` is a monoidal functor. -/ example : (forget₂ (QuadraticModuleCat R) (ModuleCat R)).Monoidal := inferInstance end QuadraticModuleCat
.lake/packages/mathlib/Mathlib/LinearAlgebra/QuadraticForm/QuadraticModuleCat/Symmetric.lean
import Mathlib.LinearAlgebra.QuadraticForm.QuadraticModuleCat.Monoidal import Mathlib.Algebra.Category.ModuleCat.Monoidal.Symmetric /-! # The monoidal structure on `QuadraticModuleCat` is symmetric. In this file we show: * `QuadraticModuleCat.instSymmetricCategory : SymmetricCategory (QuadraticModuleCat.{u} R)` ## Implementation notes This file essentially mirrors `Mathlib/Algebra/Category/AlgCat/Symmetric.lean`. -/ open CategoryTheory universe v u variable {R : Type u} [CommRing R] [Invertible (2 : R)] namespace QuadraticModuleCat open QuadraticForm instance : BraidedCategory (QuadraticModuleCat.{u} R) := .ofFaithful (forget₂ (QuadraticModuleCat R) (ModuleCat R)) fun X Y ↦ ofIso <| tensorComm X.form Y.form /-- `forget₂ (QuadraticModuleCat R) (ModuleCat R)` is a braided functor. -/ instance : (forget₂ (QuadraticModuleCat R) (ModuleCat R)).Braided where instance instSymmetricCategory : SymmetricCategory (QuadraticModuleCat.{u} R) := .ofFaithful (forget₂ (QuadraticModuleCat R) (ModuleCat R)) end QuadraticModuleCat
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/Star.lean
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
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/Prod.lean
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 algebras, 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₂) include hf /-- If `m₁` and `m₂` are both homogeneous, 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 -- 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.coe_subtype, 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.mk_zero_zero, LinearMap.map_zero, add_zero] · rw [ofProd_ι_mk, map_add, toProd_one_tmul_ι, toProd_ι_tmul_one, Prod.mk_zero_zero, LinearMap.map_zero, zero_add] lemma ofProd_comp_toProd : (ofProd Q₁ Q₂).comp (toProd Q₁ Q₂) = AlgHom.id _ _ := by ext <;> 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
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/SpinGroup.lean
import Mathlib.Algebra.Ring.Action.ConjAct import Mathlib.GroupTheory.GroupAction.ConjAct import Mathlib.Algebra.Star.Unitary import Mathlib.LinearAlgebra.CliffordAlgebra.Star import Mathlib.LinearAlgebra.CliffordAlgebra.Even import Mathlib.LinearAlgebra.CliffordAlgebra.Inversion /-! # The Pin group and the Spin group In this file we define `lipschitzGroup`, `pinGroup` and `spinGroup` and show they form a group. ## Main definitions * `lipschitzGroup`: the Lipschitz group with a quadratic form. * `pinGroup`: the Pin group defined as the infimum of `lipschitzGroup` and `unitary`. * `spinGroup`: the Spin group defined as the infimum of `pinGroup` and `CliffordAlgebra.even`. ## Implementation Notes The definition of the Lipschitz group $\{ x \in \mathop{\mathcal{C}\ell} | x \text{ is invertible and } x v x^{-1} ∈ V \}$ is given by: * [fulton2004][], Chapter 20 * https://en.wikipedia.org/wiki/Clifford_algebra#Lipschitz_group But they presumably form a group only in finite dimensions. So we define `lipschitzGroup` with closure of all the invertible elements in the form of `ι Q m`, and we show this definition is at least as large as the other definition (See `lipschitzGroup.conjAct_smul_range_ι` and `lipschitzGroup.involute_act_ι_mem_range_ι`). The reverse statement presumably is true only in finite dimensions. Here are some discussions about the latent ambiguity of definition : https://mathoverflow.net/q/427881/172242 and https://mathoverflow.net/q/251288/172242 ## TODO Try to show the reverse statement is true in finite dimensions. -/ variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable {Q : QuadraticForm R M} section Pin open CliffordAlgebra MulAction open scoped Pointwise /-- `lipschitzGroup` is the subgroup closure of all the invertible elements in the form of `ι Q m` where `ι` is the canonical linear map `M →ₗ[R] CliffordAlgebra Q`. -/ def lipschitzGroup (Q : QuadraticForm R M) : Subgroup (CliffordAlgebra Q)ˣ := Subgroup.closure ((↑) ⁻¹' Set.range (ι Q) : Set (CliffordAlgebra Q)ˣ) namespace lipschitzGroup /-- The conjugation action by elements of the Lipschitz group keeps vectors as vectors. -/ theorem conjAct_smul_ι_mem_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : x ∈ lipschitzGroup Q) [Invertible (2 : R)] (m : M) : ConjAct.toConjAct x • ι Q m ∈ LinearMap.range (ι Q) := by unfold lipschitzGroup at hx rw [ConjAct.units_smul_def, ConjAct.ofConjAct_toConjAct] induction hx using Subgroup.closure_induction'' generalizing m with | mem x hx => obtain ⟨a, ha⟩ := hx letI := x.invertible letI : Invertible (ι Q a) := by rwa [ha] letI : Invertible (Q a) := invertibleOfInvertibleι Q a simp_rw [← invOf_units x, ← ha, ι_mul_ι_mul_invOf_ι, LinearMap.mem_range_self] | inv_mem x hx => obtain ⟨a, ha⟩ := hx letI := x.invertible letI : Invertible (ι Q a) := by rwa [ha] letI : Invertible (Q a) := invertibleOfInvertibleι Q a letI := invertibleNeg (ι Q a) letI := Invertible.map involute (ι Q a) simp_rw [← invOf_units x, inv_inv, ← ha, invOf_ι_mul_ι_mul_ι, LinearMap.mem_range_self] | one => simp_rw [inv_one, Units.val_one, one_mul, mul_one, LinearMap.mem_range_self] | mul y z _ _ hy hz => simp_rw [mul_inv_rev, Units.val_mul] suffices ↑y * (↑z * ι Q m * ↑z⁻¹) * ↑y⁻¹ ∈ _ by simpa only [mul_assoc] using this obtain ⟨z', hz'⟩ := hz m obtain ⟨y', hy'⟩ := hy z' simp_rw [← hz', ← hy', LinearMap.mem_range_self] /-- This is another version of `lipschitzGroup.conjAct_smul_ι_mem_range_ι` which uses `involute`. -/ theorem involute_act_ι_mem_range_ι [Invertible (2 : R)] {x : (CliffordAlgebra Q)ˣ} (hx : x ∈ lipschitzGroup Q) (b : M) : involute (Q := Q) ↑x * ι Q b * ↑x⁻¹ ∈ LinearMap.range (ι Q) := by unfold lipschitzGroup at hx induction hx using Subgroup.closure_induction'' generalizing b with | mem x hx => obtain ⟨a, ha⟩ := hx letI := x.invertible letI : Invertible (ι Q a) := by rwa [ha] letI : Invertible (Q a) := invertibleOfInvertibleι Q a simp_rw [← invOf_units x, ← ha, involute_ι, neg_mul, ι_mul_ι_mul_invOf_ι Q a b, ← map_neg, LinearMap.mem_range_self] | inv_mem x hx => obtain ⟨a, ha⟩ := hx letI := x.invertible letI : Invertible (ι Q a) := by rwa [ha] letI : Invertible (Q a) := invertibleOfInvertibleι Q a letI := invertibleNeg (ι Q a) letI := Invertible.map involute (ι Q a) simp_rw [← invOf_units x, inv_inv, ← ha, map_invOf, involute_ι, invOf_neg, neg_mul, invOf_ι_mul_ι_mul_ι, ← map_neg, LinearMap.mem_range_self] | one => simp_rw [inv_one, Units.val_one, map_one, one_mul, mul_one, LinearMap.mem_range_self] | mul y z _ _ hy hz => simp_rw [mul_inv_rev, Units.val_mul, map_mul] suffices involute (Q := Q) ↑y * (involute (Q := Q) ↑z * ι Q b * ↑z⁻¹) * ↑y⁻¹ ∈ _ by simpa only [mul_assoc] using this obtain ⟨z', hz'⟩ := hz b obtain ⟨y', hy'⟩ := hy z' simp_rw [← hz', ← hy', LinearMap.mem_range_self] /-- If x is in `lipschitzGroup Q`, then `(ι Q).range` is closed under twisted conjugation. The reverse statement presumably is true only in finite dimensions. -/ theorem conjAct_smul_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : x ∈ lipschitzGroup Q) [Invertible (2 : R)] : ConjAct.toConjAct x • LinearMap.range (ι Q) = LinearMap.range (ι Q) := by suffices ∀ x ∈ lipschitzGroup Q, ConjAct.toConjAct x • LinearMap.range (ι Q) ≤ LinearMap.range (ι Q) by apply le_antisymm · exact this _ hx · have := smul_mono_right (ConjAct.toConjAct x) <| this _ (inv_mem hx) refine Eq.trans_le ?_ this simp only [map_inv, smul_inv_smul] intro x hx erw [Submodule.map_le_iff_le_comap] rintro _ ⟨m, rfl⟩ exact conjAct_smul_ι_mem_range_ι hx _ theorem coe_mem_iff_mem {x : (CliffordAlgebra Q)ˣ} : ↑x ∈ (lipschitzGroup Q).toSubmonoid.map (Units.coeHom <| CliffordAlgebra Q) ↔ x ∈ lipschitzGroup Q := by simp only [Submonoid.mem_map, Subgroup.mem_toSubmonoid, Units.coeHom_apply] norm_cast exact exists_eq_right end lipschitzGroup /-- `pinGroup Q` is defined as the infimum of `lipschitzGroup Q` and `unitary (CliffordAlgebra Q)`. See `mem_iff`. -/ def pinGroup (Q : QuadraticForm R M) : Submonoid (CliffordAlgebra Q) := (lipschitzGroup Q).toSubmonoid.map (Units.coeHom <| CliffordAlgebra Q) ⊓ unitary _ namespace pinGroup /-- An element is in `pinGroup Q` if and only if it is in `lipschitzGroup Q` and `unitary`. -/ theorem mem_iff {x : CliffordAlgebra Q} : x ∈ pinGroup Q ↔ x ∈ (lipschitzGroup Q).toSubmonoid.map (Units.coeHom <| CliffordAlgebra Q) ∧ x ∈ unitary (CliffordAlgebra Q) := Iff.rfl theorem mem_lipschitzGroup {x : CliffordAlgebra Q} (hx : x ∈ pinGroup Q) : x ∈ (lipschitzGroup Q).toSubmonoid.map (Units.coeHom <| CliffordAlgebra Q) := hx.1 theorem mem_unitary {x : CliffordAlgebra Q} (hx : x ∈ pinGroup Q) : x ∈ unitary (CliffordAlgebra Q) := hx.2 theorem units_mem_iff {x : (CliffordAlgebra Q)ˣ} : ↑x ∈ pinGroup Q ↔ x ∈ lipschitzGroup Q ∧ ↑x ∈ unitary (CliffordAlgebra Q) := by rw [mem_iff, lipschitzGroup.coe_mem_iff_mem] theorem units_mem_lipschitzGroup {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ pinGroup Q) : x ∈ lipschitzGroup Q := (units_mem_iff.1 hx).1 /-- The conjugation action by elements of the spin group keeps vectors as vectors. -/ theorem conjAct_smul_ι_mem_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ pinGroup Q) [Invertible (2 : R)] (y : M) : ConjAct.toConjAct x • ι Q y ∈ LinearMap.range (ι Q) := lipschitzGroup.conjAct_smul_ι_mem_range_ι (units_mem_lipschitzGroup hx) y /-- This is another version of `conjAct_smul_ι_mem_range_ι` which uses `involute`. -/ theorem involute_act_ι_mem_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ pinGroup Q) [Invertible (2 : R)] (y : M) : involute (Q := Q) ↑x * ι Q y * ↑x⁻¹ ∈ LinearMap.range (ι Q) := lipschitzGroup.involute_act_ι_mem_range_ι (units_mem_lipschitzGroup hx) y /-- If x is in `pinGroup Q`, then `(ι Q).range` is closed under twisted conjugation. The reverse statement presumably being true only in finite dimensions. -/ theorem conjAct_smul_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ pinGroup Q) [Invertible (2 : R)] : ConjAct.toConjAct x • LinearMap.range (ι Q) = LinearMap.range (ι Q) := lipschitzGroup.conjAct_smul_range_ι (units_mem_lipschitzGroup hx) @[simp] theorem star_mul_self_of_mem {x : CliffordAlgebra Q} (hx : x ∈ pinGroup Q) : star x * x = 1 := hx.2.1 @[simp] theorem mul_star_self_of_mem {x : CliffordAlgebra Q} (hx : x ∈ pinGroup Q) : x * star x = 1 := hx.2.2 /-- See `star_mem_iff` for both directions. -/ theorem star_mem {x : CliffordAlgebra Q} (hx : x ∈ pinGroup Q) : star x ∈ pinGroup Q := by rw [mem_iff] at hx ⊢ refine ⟨?_, Unitary.star_mem hx.2⟩ rcases hx with ⟨⟨y, hy₁, hy₂⟩, _hx₂, hx₃⟩ simp only [Subgroup.coe_toSubmonoid, SetLike.mem_coe] at hy₁ simp only [Units.coeHom_apply] at hy₂ simp only [Submonoid.mem_map, Subgroup.mem_toSubmonoid, Units.coeHom_apply] refine ⟨star y, ?_, by simp only [hy₂, Units.coe_star]⟩ rw [← hy₂] at hx₃ have hy₃ : y * star y = 1 := by rw [← Units.val_inj] simp only [hx₃, Units.val_mul, Units.coe_star, Units.val_one] apply_fun fun x => y⁻¹ * x at hy₃ simp only [inv_mul_cancel_left, mul_one] at hy₃ simp only [hy₃, hy₁, inv_mem_iff] /-- An element is in `pinGroup Q` if and only if `star x` is in `pinGroup Q`. See `star_mem` for only one direction. -/ @[simp] theorem star_mem_iff {x : CliffordAlgebra Q} : star x ∈ pinGroup Q ↔ x ∈ pinGroup Q := by refine ⟨?_, star_mem⟩ intro hx convert star_mem hx exact (star_star x).symm instance : Star (pinGroup Q) where star x := ⟨star x, star_mem x.prop⟩ @[simp, norm_cast] theorem coe_star {x : pinGroup Q} : ↑(star x) = (star x : CliffordAlgebra Q) := rfl theorem coe_star_mul_self (x : pinGroup Q) : (star x : CliffordAlgebra Q) * x = 1 := star_mul_self_of_mem x.prop theorem coe_mul_star_self (x : pinGroup Q) : (x : CliffordAlgebra Q) * star x = 1 := mul_star_self_of_mem x.prop @[simp] theorem star_mul_self (x : pinGroup Q) : star x * x = 1 := Subtype.ext <| coe_star_mul_self x @[simp] theorem mul_star_self (x : pinGroup Q) : x * star x = 1 := Subtype.ext <| coe_mul_star_self x /-- `pinGroup Q` forms a group where the inverse is `star`. -/ instance : Group (pinGroup Q) where inv := star inv_mul_cancel := star_mul_self instance : StarMul (pinGroup Q) where star_involutive _ := Subtype.ext <| star_involutive _ star_mul _ _ := Subtype.ext <| star_mul _ _ instance : Inhabited (pinGroup Q) := ⟨1⟩ theorem star_eq_inv (x : pinGroup Q) : star x = x⁻¹ := rfl theorem star_eq_inv' : (star : pinGroup Q → pinGroup Q) = Inv.inv := rfl /-- The elements in `pinGroup Q` embed into (CliffordAlgebra Q)ˣ. -/ @[simps] def toUnits : pinGroup Q →* (CliffordAlgebra Q)ˣ where toFun x := ⟨x, ↑x⁻¹, coe_mul_star_self x, coe_star_mul_self x⟩ map_one' := Units.ext rfl map_mul' _x _y := Units.ext rfl theorem toUnits_injective : Function.Injective (toUnits : pinGroup Q → (CliffordAlgebra Q)ˣ) := fun _x _y h => Subtype.ext <| Units.ext_iff.mp h end pinGroup end Pin section Spin open CliffordAlgebra MulAction open scoped Pointwise /-- `spinGroup Q` is defined as the infimum of `pinGroup Q` and `CliffordAlgebra.even Q`. See `mem_iff`. -/ def spinGroup (Q : QuadraticForm R M) : Submonoid (CliffordAlgebra Q) := pinGroup Q ⊓ (CliffordAlgebra.even Q).toSubring.toSubmonoid namespace spinGroup /-- An element is in `spinGroup Q` if and only if it is in `pinGroup Q` and `even Q`. -/ theorem mem_iff {x : CliffordAlgebra Q} : x ∈ spinGroup Q ↔ x ∈ pinGroup Q ∧ x ∈ even Q := Iff.rfl theorem mem_pin {x : CliffordAlgebra Q} (hx : x ∈ spinGroup Q) : x ∈ pinGroup Q := hx.1 theorem mem_even {x : CliffordAlgebra Q} (hx : x ∈ spinGroup Q) : x ∈ even Q := hx.2 theorem units_mem_lipschitzGroup {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ spinGroup Q) : x ∈ lipschitzGroup Q := pinGroup.units_mem_lipschitzGroup (mem_pin hx) /-- If x is in `spinGroup Q`, then `involute x` is equal to x. -/ theorem involute_eq {x : CliffordAlgebra Q} (hx : x ∈ spinGroup Q) : involute x = x := involute_eq_of_mem_even (mem_even hx) theorem units_involute_act_eq_conjAct {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ spinGroup Q) (y : M) : involute (Q := Q) ↑x * ι Q y * ↑x⁻¹ = ConjAct.toConjAct x • (ι Q y) := by rw [involute_eq hx, @ConjAct.units_smul_def, @ConjAct.ofConjAct_toConjAct] /-- The conjugation action by elements of the spin group keeps vectors as vectors. -/ theorem conjAct_smul_ι_mem_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ spinGroup Q) [Invertible (2 : R)] (y : M) : ConjAct.toConjAct x • ι Q y ∈ LinearMap.range (ι Q) := lipschitzGroup.conjAct_smul_ι_mem_range_ι (units_mem_lipschitzGroup hx) y /- This is another version of `conjAct_smul_ι_mem_range_ι` which uses `involute`. -/ theorem involute_act_ι_mem_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ spinGroup Q) [Invertible (2 : R)] (y : M) : involute (Q := Q) ↑x * ι Q y * ↑x⁻¹ ∈ LinearMap.range (ι Q) := lipschitzGroup.involute_act_ι_mem_range_ι (units_mem_lipschitzGroup hx) y /- If x is in `spinGroup Q`, then `(ι Q).range` is closed under twisted conjugation. The reverse statement presumably being true only in finite dimensions. -/ theorem conjAct_smul_range_ι {x : (CliffordAlgebra Q)ˣ} (hx : ↑x ∈ spinGroup Q) [Invertible (2 : R)] : ConjAct.toConjAct x • LinearMap.range (ι Q) = LinearMap.range (ι Q) := lipschitzGroup.conjAct_smul_range_ι (units_mem_lipschitzGroup hx) @[simp] theorem star_mul_self_of_mem {x : CliffordAlgebra Q} (hx : x ∈ spinGroup Q) : star x * x = 1 := hx.1.2.1 @[simp] theorem mul_star_self_of_mem {x : CliffordAlgebra Q} (hx : x ∈ spinGroup Q) : x * star x = 1 := hx.1.2.2 /-- See `star_mem_iff` for both directions. -/ theorem star_mem {x : CliffordAlgebra Q} (hx : x ∈ spinGroup Q) : star x ∈ spinGroup Q := by rw [mem_iff] at hx ⊢ obtain ⟨hx₁, hx₂⟩ := hx refine ⟨pinGroup.star_mem hx₁, ?_⟩ dsimp only [CliffordAlgebra.even] at hx₂ ⊢ simp only [Submodule.mem_toSubalgebra] at hx₂ ⊢ simp only [star_def, reverse_mem_evenOdd_iff, involute_mem_evenOdd_iff, hx₂] /-- An element is in `spinGroup Q` if and only if `star x` is in `spinGroup Q`. See `star_mem` for only one direction. -/ @[simp] theorem star_mem_iff {x : CliffordAlgebra Q} : star x ∈ spinGroup Q ↔ x ∈ spinGroup Q := by refine ⟨?_, star_mem⟩ intro hx convert star_mem hx exact (star_star x).symm instance : Star (spinGroup Q) where star x := ⟨star x, star_mem x.prop⟩ @[simp, norm_cast] theorem coe_star {x : spinGroup Q} : ↑(star x) = (star x : CliffordAlgebra Q) := rfl theorem coe_star_mul_self (x : spinGroup Q) : (star x : CliffordAlgebra Q) * x = 1 := star_mul_self_of_mem x.prop theorem coe_mul_star_self (x : spinGroup Q) : (x : CliffordAlgebra Q) * star x = 1 := mul_star_self_of_mem x.prop @[simp] theorem star_mul_self (x : spinGroup Q) : star x * x = 1 := Subtype.ext <| coe_star_mul_self x @[simp] theorem mul_star_self (x : spinGroup Q) : x * star x = 1 := Subtype.ext <| coe_mul_star_self x /-- `spinGroup Q` forms a group where the inverse is `star`. -/ instance : Group (spinGroup Q) where inv := star inv_mul_cancel := star_mul_self instance : StarMul (spinGroup Q) where star_involutive _ := Subtype.ext <| star_involutive _ star_mul _ _ := Subtype.ext <| star_mul _ _ instance : Inhabited (spinGroup Q) := ⟨1⟩ theorem star_eq_inv (x : spinGroup Q) : star x = x⁻¹ := rfl theorem star_eq_inv' : (star : spinGroup Q → spinGroup Q) = Inv.inv := rfl /-- The elements in `spinGroup Q` embed into (CliffordAlgebra Q)ˣ. -/ @[simps] def toUnits : spinGroup Q →* (CliffordAlgebra Q)ˣ where toFun x := ⟨x, ↑x⁻¹, coe_mul_star_self x, coe_star_mul_self x⟩ map_one' := Units.ext rfl map_mul' _x _y := Units.ext rfl theorem toUnits_injective : Function.Injective (toUnits : spinGroup Q → (CliffordAlgebra Q)ˣ) := fun _x _y h => Subtype.ext <| Units.ext_iff.mp h end spinGroup end Spin
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/Basic.lean
import Mathlib.Algebra.RingQuot import Mathlib.LinearAlgebra.TensorAlgebra.Basic import Mathlib.LinearAlgebra.QuadraticForm.Isometry import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv /-! # Clifford Algebras We construct the Clifford algebra of a module `M` over a commutative ring `R`, equipped with a quadratic form `Q`. ## Notation The Clifford algebra of the `R`-module `M` equipped with a quadratic form `Q` is an `R`-algebra denoted `CliffordAlgebra Q`. Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that `cond : ∀ m, f m * f m = algebraMap _ _ (Q m)`, there is a (unique) lift of `f` to an `R`-algebra morphism from `CliffordAlgebra Q` to `A`, which is denoted `CliffordAlgebra.lift Q f cond`. The canonical linear map `M → CliffordAlgebra Q` is denoted `CliffordAlgebra.ι Q`. ## Theorems The main theorems proved ensure that `CliffordAlgebra Q` satisfies the universal property of the Clifford algebra. 1. `ι_comp_lift` is the fact that the composition of `ι Q` with `lift Q f cond` agrees with `f`. 2. `lift_unique` ensures the uniqueness of `lift Q f cond` with respect to 1. ## Implementation details The Clifford algebra of `M` is constructed as a quotient of the tensor algebra, as follows. 1. We define a relation `CliffordAlgebra.Rel Q` on `TensorAlgebra R M`. This is the smallest relation which identifies squares of elements of `M` with `Q m`. 2. The Clifford algebra is the quotient of the tensor algebra by this relation. This file is almost identical to `Mathlib/LinearAlgebra/ExteriorAlgebra/Basic.lean`. -/ variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable (Q : QuadraticForm R M) namespace CliffordAlgebra open TensorAlgebra /-- `Rel` relates each `ι m * ι m`, for `m : M`, with `Q m`. The Clifford algebra of `M` is defined as the quotient modulo this relation. -/ inductive Rel : TensorAlgebra R M → TensorAlgebra R M → Prop | of (m : M) : Rel (ι R m * ι R m) (algebraMap R _ (Q m)) end CliffordAlgebra /-- The Clifford algebra of an `R`-module `M` equipped with a quadratic_form `Q`. -/ def CliffordAlgebra := RingQuot (CliffordAlgebra.Rel Q) deriving Inhabited, Ring, Algebra R namespace CliffordAlgebra instance (priority := 900) instAlgebra' {R A M} [CommSemiring R] [AddCommGroup M] [CommRing A] [Algebra R A] [Module R M] [Module A M] (Q : QuadraticForm A M) [IsScalarTower R A M] : Algebra R (CliffordAlgebra Q) := RingQuot.instAlgebra _ -- verify there are no diamonds -- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 example : (Semiring.toNatAlgebra : Algebra ℕ (CliffordAlgebra Q)) = instAlgebra' _ := rfl -- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 example : (Ring.toIntAlgebra _ : Algebra ℤ (CliffordAlgebra Q)) = instAlgebra' _ := rfl instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] (Q : QuadraticForm A M) [IsScalarTower R A M] [IsScalarTower S A M] : SMulCommClass R S (CliffordAlgebra Q) := RingQuot.instSMulCommClass _ instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A] [SMul R S] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S A] (Q : QuadraticForm A M) : IsScalarTower R S (CliffordAlgebra Q) := RingQuot.instIsScalarTower _ /-- The canonical linear map `M →ₗ[R] CliffordAlgebra Q`. -/ def ι : M →ₗ[R] CliffordAlgebra Q := (RingQuot.mkAlgHom R _).toLinearMap.comp (TensorAlgebra.ι R) /-- As well as being linear, `ι Q` squares to the quadratic form -/ @[simp] theorem ι_sq_scalar (m : M) : ι Q m * ι Q m = algebraMap R _ (Q m) := by rw [ι] erw [LinearMap.comp_apply] rw [AlgHom.toLinearMap_apply, ← map_mul (RingQuot.mkAlgHom R (Rel Q)), RingQuot.mkAlgHom_rel R (Rel.of m), AlgHom.commutes] rfl variable {Q} {A : Type*} [Semiring A] [Algebra R A] @[simp] theorem comp_ι_sq_scalar (g : CliffordAlgebra Q →ₐ[R] A) (m : M) : g (ι Q m) * g (ι Q m) = algebraMap _ _ (Q m) := by rw [← map_mul, ι_sq_scalar, AlgHom.commutes] variable (Q) in /-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition: `cond : ∀ m : M, f m * f m = Q(m)`, this is the canonical lift of `f` to a morphism of `R`-algebras from `CliffordAlgebra Q` to `A`. -/ @[simps symm_apply] def lift : { f : M →ₗ[R] A // ∀ m, f m * f m = algebraMap _ _ (Q m) } ≃ (CliffordAlgebra Q →ₐ[R] A) where toFun f := RingQuot.liftAlgHom R ⟨TensorAlgebra.lift R (f : M →ₗ[R] A), fun x y (h : Rel Q x y) => by induction h rw [AlgHom.commutes, map_mul, TensorAlgebra.lift_ι_apply, f.prop]⟩ invFun F := ⟨F.toLinearMap.comp (ι Q), fun m => by rw [LinearMap.comp_apply, AlgHom.toLinearMap_apply, comp_ι_sq_scalar]⟩ left_inv f := by ext x exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ x) right_inv F := RingQuot.ringQuot_ext' _ _ _ <| TensorAlgebra.hom_ext <| LinearMap.ext fun x ↦ (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ _) @[simp] theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) : (lift Q ⟨f, cond⟩).toLinearMap.comp (ι Q) = f := Subtype.mk_eq_mk.mp <| (lift Q).symm_apply_apply ⟨f, cond⟩ @[simp] theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) (x) : lift Q ⟨f, cond⟩ (ι Q x) = f x := (LinearMap.ext_iff.mp <| ι_comp_lift f cond) x @[simp] theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m : M, f m * f m = algebraMap _ _ (Q m)) (g : CliffordAlgebra Q →ₐ[R] A) : g.toLinearMap.comp (ι Q) = f ↔ g = lift Q ⟨f, cond⟩ := by convert (lift Q : _ ≃ (CliffordAlgebra Q →ₐ[R] A)).symm_apply_eq rw [lift_symm_apply, Subtype.mk_eq_mk] @[simp] theorem lift_comp_ι (g : CliffordAlgebra Q →ₐ[R] A) : lift Q ⟨g.toLinearMap.comp (ι Q), comp_ι_sq_scalar _⟩ = g := by exact (lift Q : _ ≃ (CliffordAlgebra Q →ₐ[R] A)).apply_symm_apply g /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem hom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : CliffordAlgebra Q →ₐ[R] A} : f.toLinearMap.comp (ι Q) = g.toLinearMap.comp (ι Q) → f = g := by intro h apply (lift Q).symm.injective rw [lift_symm_apply, lift_symm_apply] simp only [h] -- This proof closely follows `TensorAlgebra.induction` /-- If `C` holds for the `algebraMap` of `r : R` into `CliffordAlgebra Q`, the `ι` of `x : M`, and is preserved under addition and multiplication, then it holds for all of `CliffordAlgebra Q`. See also the stronger `CliffordAlgebra.left_induction` and `CliffordAlgebra.right_induction`. -/ @[elab_as_elim] theorem induction {C : CliffordAlgebra Q → Prop} (algebraMap : ∀ r, C (algebraMap R (CliffordAlgebra Q) r)) (ι : ∀ x, C (ι Q x)) (mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b)) (a : CliffordAlgebra Q) : C a := by -- the arguments are enough to construct a subalgebra, and a mapping into it from M let s : Subalgebra R (CliffordAlgebra Q) := { carrier := C mul_mem' := @mul add_mem' := @add algebraMap_mem' := algebraMap } let of : { f : M →ₗ[R] s // ∀ m, f m * f m = _root_.algebraMap _ _ (Q m) } := ⟨(CliffordAlgebra.ι Q).codRestrict (Subalgebra.toSubmodule s) ι, fun m => Subtype.eq <| ι_sq_scalar Q m⟩ -- the mapping through the subalgebra is the identity have of_id : s.val.comp (lift Q of) = AlgHom.id R (CliffordAlgebra Q) := by ext x simpa [of, -LinearMap.codRestrict_apply] -- This `@[simp]` lemma applies to `coeSort s.subModule`, but the goal contains -- a plain `coeSort s`. So we remove it from the `simp` arguments, and add it to -- the term that `simpa` will simplify before applying. using LinearMap.codRestrict_apply s.toSubmodule (CliffordAlgebra.ι Q) x (h := ι) -- finding a proof is finding an element of the subalgebra rw [← AlgHom.id_apply (R := R) a, ← of_id] exact (lift Q of a).prop @[simp] theorem adjoin_range_ι : Algebra.adjoin R (Set.range (ι Q)) = ⊤ := by refine top_unique fun x hx => ?_; clear hx induction x using induction with | algebraMap => exact algebraMap_mem _ _ | add x y hx hy => exact add_mem hx hy | mul x y hx hy => exact mul_mem hx hy | ι x => exact Algebra.subset_adjoin (Set.mem_range_self _) @[simp] theorem range_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) : (lift Q ⟨f, cond⟩).range = Algebra.adjoin R (Set.range f) := by simp_rw [← Algebra.map_top, ← adjoin_range_ι, AlgHom.map_adjoin, ← Set.range_comp, Function.comp_def, lift_ι_apply] theorem mul_add_swap_eq_polar_of_forall_mul_self_eq {A : Type*} [Ring A] [Algebra R A] (f : M →ₗ[R] A) (hf : ∀ x, f x * f x = algebraMap _ _ (Q x)) (a b : M) : f a * f b + f b * f a = algebraMap R _ (QuadraticMap.polar Q a b) := calc f a * f b + f b * f a = f (a + b) * f (a + b) - f a * f a - f b * f b := by rw [f.map_add, mul_add, add_mul, add_mul]; abel _ = algebraMap R _ (Q (a + b)) - algebraMap R _ (Q a) - algebraMap R _ (Q b) := by rw [hf, hf, hf] _ = algebraMap R _ (Q (a + b) - Q a - Q b) := by rw [← RingHom.map_sub, ← RingHom.map_sub] _ = algebraMap R _ (QuadraticMap.polar Q a b) := rfl /-- An alternative way to provide the argument to `CliffordAlgebra.lift` when `2` is invertible. To show a function squares to the quadratic form, it suffices to show that `f x * f y + f y * f x = algebraMap _ _ (polar Q x y)` -/ theorem forall_mul_self_eq_iff {A : Type*} [Ring A] [Algebra R A] (h2 : IsUnit (2 : A)) (f : M →ₗ[R] A) : (∀ x, f x * f x = algebraMap _ _ (Q x)) ↔ (LinearMap.mul R A).compl₂ f ∘ₗ f + (LinearMap.mul R A).flip.compl₂ f ∘ₗ f = Q.polarBilin.compr₂ (Algebra.linearMap R A) := by simp_rw [DFunLike.ext_iff] refine ⟨mul_add_swap_eq_polar_of_forall_mul_self_eq _, fun h x => ?_⟩ change ∀ x y : M, f x * f y + f y * f x = algebraMap R A (QuadraticMap.polar Q x y) at h apply h2.mul_left_cancel rw [two_mul, two_mul, h x x, QuadraticMap.polar_self, two_smul, map_add] /-- The symmetric product of vectors is a scalar -/ theorem ι_mul_ι_add_swap (a b : M) : ι Q a * ι Q b + ι Q b * ι Q a = algebraMap R _ (QuadraticMap.polar Q a b) := mul_add_swap_eq_polar_of_forall_mul_self_eq _ (ι_sq_scalar _) _ _ theorem ι_mul_ι_comm (a b : M) : ι Q a * ι Q b = algebraMap R _ (QuadraticMap.polar Q a b) - ι Q b * ι Q a := eq_sub_of_add_eq (ι_mul_ι_add_swap a b) section isOrtho @[simp] theorem ι_mul_ι_add_swap_of_isOrtho {a b : M} (h : Q.IsOrtho a b) : ι Q a * ι Q b + ι Q b * ι Q a = 0 := by rw [ι_mul_ι_add_swap, h.polar_eq_zero] simp theorem ι_mul_ι_comm_of_isOrtho {a b : M} (h : Q.IsOrtho a b) : ι Q a * ι Q b = -(ι Q b * ι Q a) := eq_neg_of_add_eq_zero_left <| ι_mul_ι_add_swap_of_isOrtho h theorem mul_ι_mul_ι_of_isOrtho (x : CliffordAlgebra Q) {a b : M} (h : Q.IsOrtho a b) : x * ι Q a * ι Q b = -(x * ι Q b * ι Q a) := by rw [mul_assoc, ι_mul_ι_comm_of_isOrtho h, mul_neg, mul_assoc] theorem ι_mul_ι_mul_of_isOrtho (x : CliffordAlgebra Q) {a b : M} (h : Q.IsOrtho a b) : ι Q a * (ι Q b * x) = -(ι Q b * (ι Q a * x)) := by rw [← mul_assoc, ι_mul_ι_comm_of_isOrtho h, neg_mul, mul_assoc] end isOrtho /-- $aba$ is a vector. -/ theorem ι_mul_ι_mul_ι (a b : M) : ι Q a * ι Q b * ι Q a = ι Q (QuadraticMap.polar Q a b • a - Q a • b) := by rw [ι_mul_ι_comm, sub_mul, mul_assoc, ι_sq_scalar, ← Algebra.smul_def, ← Algebra.commutes, ← Algebra.smul_def, ← map_smul, ← map_smul, ← map_sub] @[simp] theorem ι_range_map_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) : (LinearMap.range (ι Q)).map (lift Q ⟨f, cond⟩).toLinearMap = LinearMap.range f := by rw [← LinearMap.range_comp, ι_comp_lift] section Map variable {M₁ M₂ M₃ : Type*} variable [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup M₃] variable [Module R M₁] [Module R M₂] [Module R M₃] variable {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} {Q₃ : QuadraticForm R M₃} /-- Any linear map that preserves the quadratic form lifts to an `AlgHom` between algebras. See `CliffordAlgebra.equivOfIsometry` for the case when `f` is a `QuadraticForm.IsometryEquiv`. -/ def map (f : Q₁ →qᵢ Q₂) : CliffordAlgebra Q₁ →ₐ[R] CliffordAlgebra Q₂ := CliffordAlgebra.lift Q₁ ⟨ι Q₂ ∘ₗ f.toLinearMap, fun m => (ι_sq_scalar _ _).trans <| RingHom.congr_arg _ <| f.map_app m⟩ @[simp] theorem map_comp_ι (f : Q₁ →qᵢ Q₂) : (map f).toLinearMap ∘ₗ ι Q₁ = ι Q₂ ∘ₗ f.toLinearMap := ι_comp_lift _ _ @[simp] theorem map_apply_ι (f : Q₁ →qᵢ Q₂) (m : M₁) : map f (ι Q₁ m) = ι Q₂ (f m) := lift_ι_apply _ _ m variable (Q₁) in @[simp] theorem map_id : map (QuadraticMap.Isometry.id Q₁) = AlgHom.id R (CliffordAlgebra Q₁) := by ext m; exact map_apply_ι _ m @[simp] theorem map_comp_map (f : Q₂ →qᵢ Q₃) (g : Q₁ →qᵢ Q₂) : (map f).comp (map g) = map (f.comp g) := by ext m dsimp only [LinearMap.comp_apply, AlgHom.comp_apply, AlgHom.toLinearMap_apply, AlgHom.id_apply] rw [map_apply_ι, map_apply_ι, map_apply_ι, QuadraticMap.Isometry.comp_apply] @[simp] theorem ι_range_map_map (f : Q₁ →qᵢ Q₂) : (LinearMap.range (ι Q₁)).map (map f).toLinearMap = (LinearMap.range f).map (ι Q₂) := (ι_range_map_lift _ _).trans (LinearMap.range_comp _ _) open Function in /-- If `f` is a linear map from `M₁` to `M₂` that preserves the quadratic forms, and if it has a linear retraction `g` that also preserves the quadratic forms, then `CliffordAlgebra.map g` is a retraction of `CliffordAlgebra.map f`. -/ lemma leftInverse_map_of_leftInverse {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} (f : Q₁ →qᵢ Q₂) (g : Q₂ →qᵢ Q₁) (h : LeftInverse g f) : LeftInverse (map g) (map f) := by refine fun x => ?_ replace h : g.comp f = QuadraticMap.Isometry.id Q₁ := DFunLike.ext _ _ h rw [← AlgHom.comp_apply, map_comp_map, h, map_id, AlgHom.coe_id, id_eq] /-- If a linear map preserves the quadratic forms and is surjective, then the algebra maps it induces between Clifford algebras is also surjective. -/ lemma map_surjective {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} (f : Q₁ →qᵢ Q₂) (hf : Function.Surjective f) : Function.Surjective (CliffordAlgebra.map f) := CliffordAlgebra.induction (fun r ↦ ⟨algebraMap R (CliffordAlgebra Q₁) r, by simp only [AlgHom.commutes]⟩) (fun y ↦ let ⟨x, hx⟩ := hf y; ⟨CliffordAlgebra.ι Q₁ x, by simp only [map_apply_ι, hx]⟩) (fun _ _ ⟨x, hx⟩ ⟨y, hy⟩ ↦ ⟨x * y, by simp only [map_mul, hx, hy]⟩) (fun _ _ ⟨x, hx⟩ ⟨y, hy⟩ ↦ ⟨x + y, by simp only [map_add, hx, hy]⟩) /-- Two `CliffordAlgebra`s are equivalent as algebras if their quadratic forms are equivalent. -/ @[simps! apply] def equivOfIsometry (e : Q₁.IsometryEquiv Q₂) : CliffordAlgebra Q₁ ≃ₐ[R] CliffordAlgebra Q₂ := AlgEquiv.ofAlgHom (map e.toIsometry) (map e.symm.toIsometry) ((map_comp_map _ _).trans <| by convert map_id Q₂ using 2 ext m exact e.toLinearEquiv.apply_symm_apply m) ((map_comp_map _ _).trans <| by convert map_id Q₁ using 2 ext m exact e.toLinearEquiv.symm_apply_apply m) @[simp] theorem equivOfIsometry_symm (e : Q₁.IsometryEquiv Q₂) : (equivOfIsometry e).symm = equivOfIsometry e.symm := rfl @[simp] theorem equivOfIsometry_trans (e₁₂ : Q₁.IsometryEquiv Q₂) (e₂₃ : Q₂.IsometryEquiv Q₃) : (equivOfIsometry e₁₂).trans (equivOfIsometry e₂₃) = equivOfIsometry (e₁₂.trans e₂₃) := by ext x exact AlgHom.congr_fun (map_comp_map _ _) x @[simp] theorem equivOfIsometry_refl : (equivOfIsometry <| QuadraticMap.IsometryEquiv.refl Q₁) = AlgEquiv.refl := by ext x exact AlgHom.congr_fun (map_id Q₁) x end Map end CliffordAlgebra namespace TensorAlgebra variable {Q} /-- The canonical image of the `TensorAlgebra` in the `CliffordAlgebra`, which maps `TensorAlgebra.ι R x` to `CliffordAlgebra.ι Q x`. -/ def toClifford : TensorAlgebra R M →ₐ[R] CliffordAlgebra Q := TensorAlgebra.lift R (CliffordAlgebra.ι Q) @[simp] theorem toClifford_ι (m : M) : toClifford (TensorAlgebra.ι R m) = CliffordAlgebra.ι Q m := by simp [toClifford] end TensorAlgebra
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/Grading.lean
import Mathlib.LinearAlgebra.CliffordAlgebra.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 [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`. -/ 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 _ _) theorem GradedAlgebra.lift_ι_eq (i' : ZMod 2) (x' : evenOdd Q i') : lift Q ⟨GradedAlgebra.ι Q, GradedAlgebra.ι_sq_scalar Q⟩ x' = DirectSum.of (fun i => evenOdd Q i) i' x' := by obtain ⟨x', hx'⟩ := x' dsimp only [Subtype.coe_mk, DirectSum.lof_eq_of] induction hx' using Submodule.iSup_induction' with | mem i x hx => obtain ⟨i, rfl⟩ := i dsimp only [Subtype.coe_mk] 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 => rw [map_add, ihx, ihy, ← AddMonoidHom.map_add] rfl | mem_mul m hm i x hx ih => obtain ⟨_, rfl⟩ := hm rw [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 [map_zero] apply Eq.symm apply DFinsupp.single_eq_zero.mpr; rfl | add x y hx hy ihx ihy => rw [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' (motive := 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 h => ?_) add ι_mul_ι_mul x hx obtain ⟨r, rfl⟩ := Submodule.mem_one.mp h 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 simp_rw [ZMod.val_one, pow_one] rintro ⟨v, rfl⟩ exact ι v end CliffordAlgebra
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/Contraction.lean
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation import Mathlib.LinearAlgebra.CliffordAlgebra.Fold import Mathlib.LinearAlgebra.ExteriorAlgebra.Basic import Mathlib.LinearAlgebra.Dual.Defs /-! # Contraction in Clifford Algebras This file contains some of the results from [grinberg_clifford_2016][]. The key result is `CliffordAlgebra.equivExterior`. ## Main definitions * `CliffordAlgebra.contractLeft`: contract a multivector by a `Module.Dual R M` on the left. * `CliffordAlgebra.contractRight`: contract a multivector by a `Module.Dual R M` on the right. * `CliffordAlgebra.changeForm`: convert between two algebras of different quadratic form, sending vectors to vectors. The difference of the quadratic forms must be a bilinear form. * `CliffordAlgebra.equivExterior`: in characteristic not-two, the `CliffordAlgebra Q` is isomorphic as a module to the exterior algebra. ## Implementation notes This file somewhat follows [grinberg_clifford_2016][], although we are missing some of the induction principles needed to prove many of the results. Here, we avoid the quotient-based approach described in [grinberg_clifford_2016][], instead directly constructing our objects using the universal property. Note that [grinberg_clifford_2016][] concludes that its contents are not novel, and are in fact just a rehash of parts of [bourbaki2007][]; we should at some point consider swapping our references to refer to the latter. Within this file, we use the local notation * `x ⌊ d` for `contractRight x d` * `d ⌋ x` for `contractLeft d x` -/ open LinearMap (BilinMap BilinForm) universe u1 u2 u3 variable {R : Type u1} [CommRing R] variable {M : Type u2} [AddCommGroup M] [Module R M] variable (Q : QuadraticForm R M) namespace CliffordAlgebra section contractLeft variable (d d' : Module.Dual R M) /-- Auxiliary construction for `CliffordAlgebra.contractLeft` -/ @[simps!] def contractLeftAux (d : Module.Dual R M) : M →ₗ[R] CliffordAlgebra Q × CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q := haveI v_mul := (Algebra.lmul R (CliffordAlgebra Q)).toLinearMap ∘ₗ ι Q d.smulRight (LinearMap.fst _ (CliffordAlgebra Q) (CliffordAlgebra Q)) - v_mul.compl₂ (LinearMap.snd _ (CliffordAlgebra Q) _) theorem contractLeftAux_contractLeftAux (v : M) (x : CliffordAlgebra Q) (fx : CliffordAlgebra Q) : contractLeftAux Q d v (ι Q v * x, contractLeftAux Q d v (x, fx)) = Q v • fx := by simp only [contractLeftAux_apply_apply] rw [mul_sub, ← mul_assoc, ι_sq_scalar, ← Algebra.smul_def, ← sub_add, mul_smul_comm, sub_self, zero_add] variable {Q} /-- Contract an element of the clifford algebra with an element `d : Module.Dual R M` from the left. Note that $v ⌋ x$ is spelt `contractLeft (Q.associated v) x`. This includes [grinberg_clifford_2016][] Theorem 10.75 -/ def contractLeft : Module.Dual R M →ₗ[R] CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q where toFun d := foldr' Q (contractLeftAux Q d) (contractLeftAux_contractLeftAux Q d) 0 map_add' d₁ d₂ := LinearMap.ext fun x => by rw [LinearMap.add_apply] induction x using CliffordAlgebra.left_induction with | algebraMap => simp_rw [foldr'_algebraMap, smul_zero, zero_add] | add _ _ hx hy => rw [map_add, map_add, map_add, add_add_add_comm, hx, hy] | ι_mul _ _ hx => rw [foldr'_ι_mul, foldr'_ι_mul, foldr'_ι_mul, hx] dsimp only [contractLeftAux_apply_apply] rw [sub_add_sub_comm, mul_add, LinearMap.add_apply, add_smul] map_smul' c d := LinearMap.ext fun x => by rw [LinearMap.smul_apply, RingHom.id_apply] induction x using CliffordAlgebra.left_induction with | algebraMap => simp_rw [foldr'_algebraMap, smul_zero] | add _ _ hx hy => rw [map_add, map_add, smul_add, hx, hy] | ι_mul _ _ hx => rw [foldr'_ι_mul, foldr'_ι_mul, hx] dsimp only [contractLeftAux_apply_apply] rw [LinearMap.smul_apply, smul_assoc, mul_smul_comm, smul_sub] /-- Contract an element of the clifford algebra with an element `d : Module.Dual R M` from the right. Note that $x ⌊ v$ is spelt `contractRight x (Q.associated v)`. This includes [grinberg_clifford_2016][] Theorem 16.75 -/ def contractRight : CliffordAlgebra Q →ₗ[R] Module.Dual R M →ₗ[R] CliffordAlgebra Q := LinearMap.flip (LinearMap.compl₂ (LinearMap.compr₂ contractLeft reverse) reverse) theorem contractRight_eq (x : CliffordAlgebra Q) : contractRight (Q := Q) x d = reverse (contractLeft (R := R) (M := M) d <| reverse x) := rfl local infixl:70 "⌋" => contractLeft (R := R) (M := M) local infixl:70 "⌊" => contractRight (R := R) (M := M) (Q := Q) /-- This is [grinberg_clifford_2016][] Theorem 6 -/ theorem contractLeft_ι_mul (a : M) (b : CliffordAlgebra Q) : d⌋(ι Q a * b) = d a • b - ι Q a * (d⌋b) := by -- Porting note: Lean cannot figure out anymore the third argument refine foldr'_ι_mul _ _ ?_ _ _ _ exact fun m x fx ↦ contractLeftAux_contractLeftAux Q d m x fx /-- This is [grinberg_clifford_2016][] Theorem 12 -/ theorem contractRight_mul_ι (a : M) (b : CliffordAlgebra Q) : b * ι Q a⌊d = d a • b - b⌊d * ι Q a := by rw [contractRight_eq, reverse.map_mul, reverse_ι, contractLeft_ι_mul, map_sub, map_smul, reverse_reverse, reverse.map_mul, reverse_ι, contractRight_eq] theorem contractLeft_algebraMap_mul (r : R) (b : CliffordAlgebra Q) : d⌋(algebraMap _ _ r * b) = algebraMap _ _ r * (d⌋b) := by rw [← Algebra.smul_def, map_smul, Algebra.smul_def] theorem contractLeft_mul_algebraMap (a : CliffordAlgebra Q) (r : R) : d⌋(a * algebraMap _ _ r) = d⌋a * algebraMap _ _ r := by rw [← Algebra.commutes, contractLeft_algebraMap_mul, Algebra.commutes] theorem contractRight_algebraMap_mul (r : R) (b : CliffordAlgebra Q) : algebraMap _ _ r * b⌊d = algebraMap _ _ r * (b⌊d) := by rw [← Algebra.smul_def, LinearMap.map_smul₂, Algebra.smul_def] theorem contractRight_mul_algebraMap (a : CliffordAlgebra Q) (r : R) : a * algebraMap _ _ r⌊d = a⌊d * algebraMap _ _ r := by rw [← Algebra.commutes, contractRight_algebraMap_mul, Algebra.commutes] variable (Q) @[simp] theorem contractLeft_ι (x : M) : d⌋ι Q x = algebraMap R _ (d x) := by -- Porting note: Lean cannot figure out anymore the third argument refine (foldr'_ι _ _ ?_ _ _).trans <| by simp_rw [contractLeftAux_apply_apply, mul_zero, sub_zero, Algebra.algebraMap_eq_smul_one] exact fun m x fx ↦ contractLeftAux_contractLeftAux Q d m x fx @[simp] theorem contractRight_ι (x : M) : ι Q x⌊d = algebraMap R _ (d x) := by rw [contractRight_eq, reverse_ι, contractLeft_ι, reverse.commutes] @[simp] theorem contractLeft_algebraMap (r : R) : d⌋algebraMap R (CliffordAlgebra Q) r = 0 := by -- Porting note: Lean cannot figure out anymore the third argument refine (foldr'_algebraMap _ _ ?_ _ _).trans <| smul_zero _ exact fun m x fx ↦ contractLeftAux_contractLeftAux Q d m x fx @[simp] theorem contractRight_algebraMap (r : R) : algebraMap R (CliffordAlgebra Q) r⌊d = 0 := by rw [contractRight_eq, reverse.commutes, contractLeft_algebraMap, map_zero] @[simp] theorem contractLeft_one : d⌋(1 : CliffordAlgebra Q) = 0 := by simpa only [map_one] using contractLeft_algebraMap Q d 1 @[simp] theorem contractRight_one : (1 : CliffordAlgebra Q)⌊d = 0 := by simpa only [map_one] using contractRight_algebraMap Q d 1 variable {Q} /-- This is [grinberg_clifford_2016][] Theorem 7 -/ theorem contractLeft_contractLeft (x : CliffordAlgebra Q) : d⌋(d⌋x) = 0 := by induction x using CliffordAlgebra.left_induction with | algebraMap => simp_rw [contractLeft_algebraMap, map_zero] | add _ _ hx hy => rw [map_add, map_add, hx, hy, add_zero] | ι_mul _ _ hx => rw [contractLeft_ι_mul, map_sub, contractLeft_ι_mul, hx, LinearMap.map_smul, mul_zero, sub_zero, sub_self] /-- This is [grinberg_clifford_2016][] Theorem 13 -/ theorem contractRight_contractRight (x : CliffordAlgebra Q) : x⌊d⌊d = 0 := by rw [contractRight_eq, contractRight_eq, reverse_reverse, contractLeft_contractLeft, map_zero] /-- This is [grinberg_clifford_2016][] Theorem 8 -/ theorem contractLeft_comm (x : CliffordAlgebra Q) : d⌋(d'⌋x) = -(d'⌋(d⌋x)) := by induction x using CliffordAlgebra.left_induction with | algebraMap => simp_rw [contractLeft_algebraMap, map_zero, neg_zero] | add _ _ hx hy => rw [map_add, map_add, map_add, map_add, hx, hy, neg_add] | ι_mul _ _ hx => simp only [contractLeft_ι_mul, map_sub, LinearMap.map_smul] rw [neg_sub, sub_sub_eq_add_sub, hx, mul_neg, ← sub_eq_add_neg] /-- This is [grinberg_clifford_2016][] Theorem 14 -/ theorem contractRight_comm (x : CliffordAlgebra Q) : x⌊d⌊d' = -(x⌊d'⌊d) := by rw [contractRight_eq, contractRight_eq, contractRight_eq, contractRight_eq, reverse_reverse, reverse_reverse, contractLeft_comm, map_neg] /- TODO: lemma contractRight_contractLeft (x : CliffordAlgebra Q) : (d ⌋ x) ⌊ d' = d ⌋ (x ⌊ d') := -/ end contractLeft local infixl:70 "⌋" => contractLeft local infixl:70 "⌊" => contractRight /-- Auxiliary construction for `CliffordAlgebra.changeForm` -/ @[simps!] def changeFormAux (B : BilinForm R M) : M →ₗ[R] CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q := haveI v_mul := (Algebra.lmul R (CliffordAlgebra Q)).toLinearMap ∘ₗ ι Q v_mul - contractLeft ∘ₗ B theorem changeFormAux_changeFormAux (B : BilinForm R M) (v : M) (x : CliffordAlgebra Q) : changeFormAux Q B v (changeFormAux Q B v x) = (Q v - B v v) • x := by simp only [changeFormAux_apply_apply] rw [mul_sub, ← mul_assoc, ι_sq_scalar, map_sub, contractLeft_ι_mul, ← sub_add, sub_sub_sub_comm, ← Algebra.smul_def, sub_self, sub_zero, contractLeft_contractLeft, add_zero, sub_smul] variable {Q} variable {Q' Q'' : QuadraticForm R M} {B B' : BilinForm R M} /-- Convert between two algebras of different quadratic form, sending vector to vectors, scalars to scalars, and adjusting products by a contraction term. This is $\lambda_B$ from [bourbaki2007][] $9 Lemma 2. -/ def changeForm (h : B.toQuadraticMap = Q' - Q) : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q' := foldr Q (changeFormAux Q' B) (fun m x => (changeFormAux_changeFormAux Q' B m x).trans <| by dsimp only [← BilinMap.toQuadraticMap_apply] rw [h, QuadraticMap.sub_apply, sub_sub_cancel]) 1 /-- Auxiliary lemma used as an argument to `CliffordAlgebra.changeForm` -/ theorem changeForm.zero_proof : (0 : BilinForm R M).toQuadraticMap = Q - Q := (sub_self _).symm variable (h : B.toQuadraticMap = Q' - Q) (h' : B'.toQuadraticMap = Q'' - Q') include h h' in /-- Auxiliary lemma used as an argument to `CliffordAlgebra.changeForm` -/ theorem changeForm.add_proof : (B + B').toQuadraticMap = Q'' - Q := (congr_arg₂ (· + ·) h h').trans <| sub_add_sub_cancel' _ _ _ include h in /-- Auxiliary lemma used as an argument to `CliffordAlgebra.changeForm` -/ theorem changeForm.neg_proof : (-B).toQuadraticMap = Q - Q' := (congr_arg Neg.neg h).trans <| neg_sub _ _ theorem changeForm.associated_neg_proof [Invertible (2 : R)] : (QuadraticMap.associated (R := R) (M := M) (-Q)).toQuadraticMap = 0 - Q := by simp [QuadraticMap.toQuadraticMap_associated] @[simp] theorem changeForm_algebraMap (r : R) : changeForm h (algebraMap R _ r) = algebraMap R _ r := (foldr_algebraMap _ _ _ _ _).trans <| Eq.symm <| Algebra.algebraMap_eq_smul_one r @[simp] theorem changeForm_one : changeForm h (1 : CliffordAlgebra Q) = 1 := by simpa using changeForm_algebraMap h (1 : R) @[simp] theorem changeForm_ι (m : M) : changeForm h (ι (M := M) Q m) = ι (M := M) Q' m := (foldr_ι _ _ _ _ _).trans <| Eq.symm <| by rw [changeFormAux_apply_apply, mul_one, contractLeft_one, sub_zero] theorem changeForm_ι_mul (m : M) (x : CliffordAlgebra Q) : changeForm h (ι Q m * x) = ι Q' m * changeForm h x - B m⌋changeForm h x := (foldr_mul _ _ _ _ _ _).trans <| by rw [foldr_ι]; rfl theorem changeForm_ι_mul_ι (m₁ m₂ : M) : changeForm h (ι Q m₁ * ι Q m₂) = ι Q' m₁ * ι Q' m₂ - algebraMap _ _ (B m₁ m₂) := by rw [changeForm_ι_mul, changeForm_ι, contractLeft_ι] /-- Theorem 23 of [grinberg_clifford_2016][] -/ theorem changeForm_contractLeft (d : Module.Dual R M) (x : CliffordAlgebra Q) : changeForm h (d⌋x) = d⌋(changeForm h x) := by induction x using CliffordAlgebra.left_induction with | algebraMap => simp only [contractLeft_algebraMap, changeForm_algebraMap, map_zero] | add _ _ hx hy => rw [map_add, map_add, map_add, map_add, hx, hy] | ι_mul _ _ hx => simp only [contractLeft_ι_mul, changeForm_ι_mul, map_sub, LinearMap.map_smul] rw [← hx, contractLeft_comm, ← sub_add, sub_neg_eq_add, ← hx] theorem changeForm_self_apply (x : CliffordAlgebra Q) : changeForm (Q' := Q) changeForm.zero_proof x = x := by induction x using CliffordAlgebra.left_induction with | algebraMap => simp_rw [changeForm_algebraMap] | add _ _ hx hy => rw [map_add, hx, hy] | ι_mul _ _ hx => rw [changeForm_ι_mul, hx, LinearMap.zero_apply, map_zero, LinearMap.zero_apply, sub_zero] @[simp] theorem changeForm_self : changeForm changeForm.zero_proof = (LinearMap.id : CliffordAlgebra Q →ₗ[R] _) := LinearMap.ext <| changeForm_self_apply /-- This is [bourbaki2007][] $9 Lemma 3. -/ theorem changeForm_changeForm (x : CliffordAlgebra Q) : changeForm h' (changeForm h x) = changeForm (changeForm.add_proof h h') x := by induction x using CliffordAlgebra.left_induction with | algebraMap => simp_rw [changeForm_algebraMap] | add _ _ hx hy => rw [map_add, map_add, map_add, hx, hy] | ι_mul _ _ hx => rw [changeForm_ι_mul, map_sub, changeForm_ι_mul, changeForm_ι_mul, hx, sub_sub, LinearMap.add_apply, map_add, LinearMap.add_apply, changeForm_contractLeft, hx, add_comm (_ : CliffordAlgebra Q'')] theorem changeForm_comp_changeForm : (changeForm h').comp (changeForm h) = changeForm (changeForm.add_proof h h') := LinearMap.ext <| changeForm_changeForm _ h' /-- Any two algebras whose quadratic forms differ by a bilinear form are isomorphic as modules. This is $\bar \lambda_B$ from [bourbaki2007][] $9 Proposition 3. -/ @[simps apply] def changeFormEquiv : CliffordAlgebra Q ≃ₗ[R] CliffordAlgebra Q' := { changeForm h with toFun := changeForm h invFun := changeForm (changeForm.neg_proof h) left_inv := fun x => by exact (changeForm_changeForm _ _ x).trans <| by simp_rw [(add_neg_cancel B), changeForm_self_apply] right_inv := fun x => by exact (changeForm_changeForm _ _ x).trans <| by simp_rw [(neg_add_cancel B), changeForm_self_apply] } @[simp] theorem changeFormEquiv_symm : (changeFormEquiv h).symm = changeFormEquiv (changeForm.neg_proof h) := LinearEquiv.ext fun _ => rfl variable (Q) /-- The module isomorphism to the exterior algebra. Note that this holds more generally when `Q` is divisible by two, rather than only when `1` is divisible by two; but that would be more awkward to use. -/ @[simp] def equivExterior [Invertible (2 : R)] : CliffordAlgebra Q ≃ₗ[R] ExteriorAlgebra R M := changeFormEquiv changeForm.associated_neg_proof /-- A `CliffordAlgebra` over a nontrivial ring is nontrivial, in characteristic not two. -/ instance [Nontrivial R] [Invertible (2 : R)] : Nontrivial (CliffordAlgebra Q) := (equivExterior Q).symm.injective.nontrivial end CliffordAlgebra
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/Even.lean
import Mathlib.LinearAlgebra.CliffordAlgebra.Fold import Mathlib.LinearAlgebra.CliffordAlgebra.Grading /-! # The universal property of the even subalgebra ## Main definitions * `CliffordAlgebra.even Q`: The even subalgebra of `CliffordAlgebra Q`. * `CliffordAlgebra.EvenHom`: The type of bilinear maps that satisfy the universal property of the even subalgebra * `CliffordAlgebra.even.lift`: The universal property of the even subalgebra, which states that every bilinear map `f` with `f v v = Q v` and `f u v * f v w = Q v • f u w` is in unique correspondence with an algebra morphism from `CliffordAlgebra.even Q`. ## Implementation notes The approach here is outlined in "Computing with the universal properties of the Clifford algebra and the even subalgebra" (to appear). The broad summary is that we have two tricks available to us for implementing complex recursors on top of `CliffordAlgebra.lift`: the first is to use morphisms as the output type, such as `A = Module.End R N` which is how we obtained `CliffordAlgebra.foldr`; and the second is to use `N = (N', S)` where `N'` is the value we wish to compute, and `S` is some auxiliary state passed between one recursor invocation and the next. For the universal property of the even subalgebra, we apply a variant of the first trick again by choosing `S` to itself be a submodule of morphisms. -/ namespace CliffordAlgebra variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] variable {Q : QuadraticForm R M} -- put this after `Q` since we want to talk about morphisms from `CliffordAlgebra Q` to `A` and -- that order is more natural variable {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] open scoped DirectSum variable (Q) /-- The even submodule `CliffordAlgebra.evenOdd Q 0` is also a subalgebra. -/ def even : Subalgebra R (CliffordAlgebra Q) := (evenOdd Q 0).toSubalgebra (SetLike.one_mem_graded _) fun _x _y hx hy => add_zero (0 : ZMod 2) ▸ SetLike.mul_mem_graded hx hy @[simp] theorem even_toSubmodule : Subalgebra.toSubmodule (even Q) = evenOdd Q 0 := rfl variable (A) /-- The type of bilinear maps which are accepted by `CliffordAlgebra.even.lift`. -/ @[ext] structure EvenHom where bilin : M →ₗ[R] M →ₗ[R] A contract (m : M) : bilin m m = algebraMap R A (Q m) contract_mid (m₁ m₂ m₃ : M) : bilin m₁ m₂ * bilin m₂ m₃ = Q m₂ • bilin m₁ m₃ variable {A Q} /-- Compose an `EvenHom` with an `AlgHom` on the output. -/ @[simps] def EvenHom.compr₂ (g : EvenHom Q A) (f : A →ₐ[R] B) : EvenHom Q B where bilin := g.bilin.compr₂ f.toLinearMap contract _m := (f.congr_arg <| g.contract _).trans <| f.commutes _ contract_mid _m₁ _m₂ _m₃ := (map_mul f _ _).symm.trans <| (f.congr_arg <| g.contract_mid _ _ _).trans <| map_smul f _ _ variable (Q) /-- The embedding of pairs of vectors into the even subalgebra, as a bilinear map. -/ nonrec def even.ι : EvenHom Q (even Q) where bilin := LinearMap.mk₂ R (fun m₁ m₂ => ⟨ι Q m₁ * ι Q m₂, ι_mul_ι_mem_evenOdd_zero Q _ _⟩) (fun _ _ _ => by simp only [LinearMap.map_add, add_mul]; rfl) (fun _ _ _ => by simp only [LinearMap.map_smul, smul_mul_assoc]; rfl) (fun _ _ _ => by simp only [LinearMap.map_add, mul_add]; rfl) fun _ _ _ => by simp only [LinearMap.map_smul, mul_smul_comm]; rfl contract m := Subtype.ext <| ι_sq_scalar Q m contract_mid m₁ m₂ m₃ := Subtype.ext <| calc ι Q m₁ * ι Q m₂ * (ι Q m₂ * ι Q m₃) = ι Q m₁ * (ι Q m₂ * ι Q m₂ * ι Q m₃) := by simp only [mul_assoc] _ = Q m₂ • (ι Q m₁ * ι Q m₃) := by rw [Algebra.smul_def, ι_sq_scalar, Algebra.left_comm] instance : Inhabited (EvenHom Q (even Q)) := ⟨even.ι Q⟩ variable (f : EvenHom Q A) /-- Two algebra morphisms from the even subalgebra are equal if they agree on pairs of generators. See note [partially-applied ext lemmas]. -/ @[ext high] theorem even.algHom_ext ⦃f g : even Q →ₐ[R] A⦄ (h : (even.ι Q).compr₂ f = (even.ι Q).compr₂ g) : f = g := by rw [EvenHom.ext_iff] at h ext ⟨x, hx⟩ induction x, hx using even_induction with | algebraMap r => exact (f.commutes r).trans (g.commutes r).symm | add x y hx hy ihx ihy => have := congr_arg₂ (· + ·) ihx ihy exact (map_add f _ _).trans (this.trans <| (map_add g _ _).symm) | ι_mul_ι_mul m₁ m₂ x hx ih => have := congr_arg₂ (· * ·) (LinearMap.congr_fun (LinearMap.congr_fun h m₁) m₂) ih exact (map_mul f _ _).trans (this.trans <| (map_mul g _ _).symm) variable {Q} namespace even.lift /-- An auxiliary submodule used to store the half-applied values of `f`. This is the span of elements `f'` such that `∃ x m₂, ∀ m₁, f' m₁ = f m₁ m₂ * x`. -/ private def S : Submodule R (M →ₗ[R] A) := Submodule.span R {f' | ∃ x m₂, f' = LinearMap.lcomp R _ (f.bilin.flip m₂) (LinearMap.mulRight R x)} /-- An auxiliary bilinear map that is later passed into `CliffordAlgebra.foldr`. Our desired result is stored in the `A` part of the accumulator, while auxiliary recursion state is stored in the `S f` part. -/ private def fFold : M →ₗ[R] A × S f →ₗ[R] A × S f := LinearMap.mk₂ R (fun m acc => /- We could write this `snd` term in a point-free style as follows, but it wouldn't help as we don't have any prod or subtype combinators to deal with n-linear maps of this degree. ```lean (LinearMap.lcomp R _ (Algebra.lmul R A).to_linear_map.flip).comp <| (LinearMap.llcomp R M A A).flip.comp f.flip : M →ₗ[R] A →ₗ[R] M →ₗ[R] A) ``` -/ (acc.2.val m, ⟨(LinearMap.mulRight R acc.1).comp (f.bilin.flip m), Submodule.subset_span <| ⟨_, _, rfl⟩⟩)) (fun m₁ m₂ a => Prod.ext (LinearMap.map_add _ m₁ m₂) (Subtype.ext <| LinearMap.ext fun m₃ => show f.bilin m₃ (m₁ + m₂) * a.1 = f.bilin m₃ m₁ * a.1 + f.bilin m₃ m₂ * a.1 by rw [map_add, add_mul])) (fun c m a => Prod.ext (LinearMap.map_smul _ c m) (Subtype.ext <| LinearMap.ext fun m₃ => show f.bilin m₃ (c • m) * a.1 = c • (f.bilin m₃ m * a.1) by rw [LinearMap.map_smul, smul_mul_assoc])) (fun _ _ _ => Prod.ext rfl (Subtype.ext <| LinearMap.ext fun _ => mul_add _ _ _)) fun _ _ _ => Prod.ext rfl (Subtype.ext <| LinearMap.ext fun _ => mul_smul_comm _ _ _) @[simp] private theorem fst_fFold_fFold (m₁ m₂ : M) (x : A × S f) : (fFold f m₁ (fFold f m₂ x)).fst = f.bilin m₁ m₂ * x.fst := rfl @[simp] private theorem snd_fFold_fFold (m₁ m₂ m₃ : M) (x : A × S f) : ((fFold f m₁ (fFold f m₂ x)).snd : M →ₗ[R] A) m₃ = f.bilin m₃ m₁ * (x.snd : M →ₗ[R] A) m₂ := rfl private theorem fFold_fFold (m : M) (x : A × S f) : fFold f m (fFold f m x) = Q m • x := by obtain ⟨a, ⟨g, hg⟩⟩ := x ext : 2 · change f.bilin m m * a = Q m • a rw [Algebra.smul_def, f.contract] · ext m₁ change f.bilin _ _ * g m = Q m • g m₁ refine Submodule.span_induction ?_ ?_ ?_ ?_ hg · rintro _ ⟨b, m₃, rfl⟩ change f.bilin _ _ * (f.bilin _ _ * b) = Q m • (f.bilin _ _ * b) rw [← smul_mul_assoc, ← mul_assoc, f.contract_mid] · simp · rintro x y _hx _hy ihx ihy rw [LinearMap.add_apply, LinearMap.add_apply, mul_add, smul_add, ihx, ihy] · rintro x hx _c ihx rw [LinearMap.smul_apply, LinearMap.smul_apply, mul_smul_comm, ihx, smul_comm] /-- The final auxiliary construction for `CliffordAlgebra.even.lift`. This map is the forwards direction of that equivalence, but not in the fully-bundled form. -/ @[simps! -isSimp apply] def aux (f : EvenHom Q A) : CliffordAlgebra.even Q →ₗ[R] A := by refine ?_ ∘ₗ (even Q).val.toLinearMap exact LinearMap.fst R _ _ ∘ₗ foldr Q (fFold f) (fFold_fFold f) (1, 0) @[simp] theorem aux_one : aux f 1 = 1 := congr_arg Prod.fst (foldr_one _ _ _ _) @[simp] theorem aux_ι (m₁ m₂ : M) : aux f ((even.ι Q).bilin m₁ m₂) = f.bilin m₁ m₂ := (congr_arg Prod.fst (foldr_mul _ _ _ _ _ _)).trans (by rw [foldr_ι, foldr_ι] exact mul_one _) @[simp] theorem aux_algebraMap (r) : aux f (algebraMap R (even Q) r) = algebraMap R A r := (congr_arg Prod.fst (foldr_algebraMap _ _ _ _ _)).trans (Algebra.algebraMap_eq_smul_one r).symm @[simp] theorem aux_mul (x y : even Q) : aux f (x * y) = aux f x * aux f y := by obtain ⟨x, x_property⟩ := x cases y refine (congr_arg Prod.fst (foldr_mul _ _ _ _ _ _)).trans ?_ dsimp only induction x, x_property using even_induction Q with | algebraMap r => generalize_proofs at ⊢ simpa using Algebra.smul_def r _ | add x y hx hy ihx ihy => rw [LinearMap.map_add, Prod.fst_add] simp [ihx, ihy, ← add_mul, ← LinearMap.map_add] | ι_mul_ι_mul m₁ m₂ x hx ih => simp [aux_apply, ih, ← mul_assoc] end even.lift open even.lift variable (Q) /-- Every algebra morphism from the even subalgebra is in one-to-one correspondence with a bilinear map that sends duplicate arguments to the quadratic form, and contracts across multiplication. -/ @[simps! symm_apply_bilin] def even.lift : EvenHom Q A ≃ (CliffordAlgebra.even Q →ₐ[R] A) where toFun f := AlgHom.ofLinearMap (aux f) (aux_one f) (aux_mul f) invFun F := (even.ι Q).compr₂ F left_inv f := EvenHom.ext <| LinearMap.ext₂ <| even.lift.aux_ι f right_inv _ := even.algHom_ext Q <| EvenHom.ext <| LinearMap.ext₂ <| even.lift.aux_ι _ @[simp] theorem even.lift_ι (f : EvenHom Q A) (m₁ m₂ : M) : even.lift Q f ((even.ι Q).bilin m₁ m₂) = f.bilin m₁ m₂ := even.lift.aux_ι _ _ _ end CliffordAlgebra
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/Fold.lean
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 | nil => rw [List.map_nil, List.prod_nil, List.foldr_nil, foldr_one] | cons hd tl ih => 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 | algebraMap r => simpa only [reverse.commutes] using algebraMap r | add _ _ hx hy => simpa only [map_add] using add _ _ hx hy | mul_ι _ _ hx => 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 obtain ⟨x, fx⟩ := 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
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/CategoryTheory.lean
import Mathlib.LinearAlgebra.CliffordAlgebra.Basic import Mathlib.LinearAlgebra.QuadraticForm.QuadraticModuleCat import Mathlib.Algebra.Category.AlgCat.Basic /-! # Category-theoretic interpretations of `CliffordAlgebra` ## Main definitions * `QuadraticModuleCat.cliffordAlgebra`: the functor from quadratic modules to algebras -/ universe v u open CategoryTheory variable {R : Type u} [CommRing R] /-- The "clifford algebra" functor, sending a quadratic `R`-module `V` to the clifford algebra on `V`. This is `CliffordAlgebra.map` through the lens of category theory. -/ @[simps] def QuadraticModuleCat.cliffordAlgebra : QuadraticModuleCat.{u} R ⥤ AlgCat.{u} R where obj M := AlgCat.of R (CliffordAlgebra M.form) map {_M _N} f := AlgCat.ofHom <| CliffordAlgebra.map f.toIsometry map_id _M := by simp map_comp {_M _N _P} f g := by ext; simp
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/BaseChange.lean
import Mathlib.LinearAlgebra.QuadraticForm.TensorProduct import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation import Mathlib.LinearAlgebra.TensorProduct.Opposite import Mathlib.RingTheory.TensorProduct.Basic /-! # The base change of a clifford algebra In this file we show the isomorphism * `CliffordAlgebra.equivBaseChange A Q` : `CliffordAlgebra (Q.baseChange A) ≃ₐ[A] (A ⊗[R] CliffordAlgebra Q)` with forward direction `CliffordAlgebra.toBaseChange A Q` and reverse direction `CliffordAlgebra.ofBaseChange A Q`. This covers a more general case of the complexification of clifford algebras (as described in §2.2 of https://empg.maths.ed.ac.uk/Activities/Spin/Lecture2.pdf), where ℂ and ℝ are replaced by an `R`-algebra `A` (where `2 : R` is invertible). We show the additional results: * `CliffordAlgebra.toBaseChange_ι`: the effect of base-changing pure vectors. * `CliffordAlgebra.ofBaseChange_tmul_ι`: the effect of un-base-changing a tensor of a pure vectors. * `CliffordAlgebra.toBaseChange_involute`: the effect of base-changing an involution. * `CliffordAlgebra.toBaseChange_reverse`: the effect of base-changing a reversal. -/ variable {R A V : Type*} variable [CommRing R] [CommRing A] [AddCommGroup V] variable [Algebra R A] [Module R V] variable [Invertible (2 : R)] open scoped TensorProduct namespace CliffordAlgebra variable (A) /-- Auxiliary construction: note this is really just a heterobasic `CliffordAlgebra.map`. -/ def ofBaseChangeAux (Q : QuadraticForm R V) : CliffordAlgebra Q →ₐ[R] CliffordAlgebra (Q.baseChange A) := CliffordAlgebra.lift Q <| by refine ⟨(ι (Q.baseChange A)).restrictScalars R ∘ₗ TensorProduct.mk R A V 1, fun v => ?_⟩ refine (CliffordAlgebra.ι_sq_scalar (Q.baseChange A) (1 ⊗ₜ v)).trans ?_ rw [QuadraticForm.baseChange_tmul, one_mul, ← Algebra.algebraMap_eq_smul_one, ← IsScalarTower.algebraMap_apply] @[simp] theorem ofBaseChangeAux_ι (Q : QuadraticForm R V) (v : V) : ofBaseChangeAux A Q (ι Q v) = ι (Q.baseChange A) (1 ⊗ₜ v) := CliffordAlgebra.lift_ι_apply _ _ v /-- Convert from the base-changed clifford algebra to the clifford algebra over a base-changed module. -/ def ofBaseChange (Q : QuadraticForm R V) : A ⊗[R] CliffordAlgebra Q →ₐ[A] CliffordAlgebra (Q.baseChange A) := Algebra.TensorProduct.lift (Algebra.ofId _ _) (ofBaseChangeAux A Q) fun _a _x => Algebra.commutes _ _ @[simp] theorem ofBaseChange_tmul_ι (Q : QuadraticForm R V) (z : A) (v : V) : ofBaseChange A Q (z ⊗ₜ ι Q v) = ι (Q.baseChange A) (z ⊗ₜ v) := by change algebraMap _ _ z * ofBaseChangeAux A Q (ι Q v) = ι (Q.baseChange A) (z ⊗ₜ[R] v) rw [ofBaseChangeAux_ι, ← Algebra.smul_def, ← map_smul, TensorProduct.smul_tmul', smul_eq_mul, mul_one] @[simp] theorem ofBaseChange_tmul_one (Q : QuadraticForm R V) (z : A) : ofBaseChange A Q (z ⊗ₜ 1) = algebraMap _ _ z := by change algebraMap _ _ z * ofBaseChangeAux A Q 1 = _ rw [map_one, mul_one] /-- Convert from the clifford algebra over a base-changed module to the base-changed clifford algebra. -/ def toBaseChange (Q : QuadraticForm R V) : CliffordAlgebra (Q.baseChange A) →ₐ[A] A ⊗[R] CliffordAlgebra Q := CliffordAlgebra.lift _ <| by refine ⟨TensorProduct.AlgebraTensorModule.map (LinearMap.id : A →ₗ[A] A) (ι Q), ?_⟩ letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm letI : Invertible (2 : A ⊗[R] CliffordAlgebra Q) := (Invertible.map (algebraMap R _) 2).copy 2 (map_ofNat _ _).symm suffices hpure_tensor : ∀ v w, (1 * 1) ⊗ₜ[R] (ι Q v * ι Q w) + (1 * 1) ⊗ₜ[R] (ι Q w * ι Q v) = QuadraticMap.polarBilin (Q.baseChange A) (1 ⊗ₜ[R] v) (1 ⊗ₜ[R] w) ⊗ₜ[R] 1 by -- the crux is that by converting to a statement about linear maps instead of quadratic forms, -- we then have access to all the partially-applied `ext` lemmas. rw [CliffordAlgebra.forall_mul_self_eq_iff (isUnit_of_invertible _)] refine TensorProduct.AlgebraTensorModule.curry_injective ?_ ext v w dsimp exact hpure_tensor v w intro v w rw [← TensorProduct.tmul_add, CliffordAlgebra.ι_mul_ι_add_swap, QuadraticForm.polarBilin_baseChange, LinearMap.BilinForm.baseChange_tmul, one_mul, TensorProduct.smul_tmul, Algebra.algebraMap_eq_smul_one, QuadraticMap.polarBilin_apply_apply] @[simp] theorem toBaseChange_ι (Q : QuadraticForm R V) (z : A) (v : V) : toBaseChange A Q (ι (Q.baseChange A) (z ⊗ₜ v)) = z ⊗ₜ ι Q v := CliffordAlgebra.lift_ι_apply _ _ _ theorem toBaseChange_comp_involute (Q : QuadraticForm R V) : (toBaseChange A Q).comp (involute : CliffordAlgebra (Q.baseChange A) →ₐ[A] _) = (Algebra.TensorProduct.map (AlgHom.id _ _) involute).comp (toBaseChange A Q) := by ext v change toBaseChange A Q (involute (ι (Q.baseChange A) (1 ⊗ₜ[R] v))) = (Algebra.TensorProduct.map (AlgHom.id _ _) involute : A ⊗[R] CliffordAlgebra Q →ₐ[A] _) (toBaseChange A Q (ι (Q.baseChange A) (1 ⊗ₜ[R] v))) rw [toBaseChange_ι, involute_ι, map_neg (toBaseChange A Q), toBaseChange_ι, Algebra.TensorProduct.map_tmul, AlgHom.id_apply, involute_ι, TensorProduct.tmul_neg] /-- The involution acts only on the right of the tensor product. -/ theorem toBaseChange_involute (Q : QuadraticForm R V) (x : CliffordAlgebra (Q.baseChange A)) : toBaseChange A Q (involute x) = TensorProduct.map LinearMap.id (involute.toLinearMap) (toBaseChange A Q x) := DFunLike.congr_fun (toBaseChange_comp_involute A Q) x open MulOpposite /-- Auxiliary theorem used to prove `toBaseChange_reverse` without needing induction. -/ theorem toBaseChange_comp_reverseOp (Q : QuadraticForm R V) : (toBaseChange A Q).op.comp reverseOp = ((Algebra.TensorProduct.opAlgEquiv R A A (CliffordAlgebra Q)).toAlgHom.comp <| (Algebra.TensorProduct.map (AlgEquiv.toOpposite A A).toAlgHom (reverseOp (Q := Q))).comp (toBaseChange A Q)) := by ext v change op (toBaseChange A Q (reverse (ι (Q.baseChange A) (1 ⊗ₜ[R] v)))) = Algebra.TensorProduct.opAlgEquiv R A A (CliffordAlgebra Q) (Algebra.TensorProduct.map (AlgEquiv.toOpposite A A).toAlgHom (reverseOp (Q := Q)) (toBaseChange A Q (ι (Q.baseChange A) (1 ⊗ₜ[R] v)))) rw [toBaseChange_ι, reverse_ι, toBaseChange_ι, Algebra.TensorProduct.map_tmul, Algebra.TensorProduct.opAlgEquiv_tmul, reverseOp_ι] rfl /-- `reverse` acts only on the right of the tensor product. -/ theorem toBaseChange_reverse (Q : QuadraticForm R V) (x : CliffordAlgebra (Q.baseChange A)) : toBaseChange A Q (reverse x) = TensorProduct.map LinearMap.id reverse (toBaseChange A Q x) := by have := DFunLike.congr_fun (toBaseChange_comp_reverseOp A Q) x refine (congr_arg unop this).trans ?_; clear this refine (LinearMap.congr_fun (TensorProduct.AlgebraTensorModule.map_comp _ _ _ _).symm _).trans ?_ rw [reverse, ← AlgEquiv.toLinearMap, ← AlgEquiv.toLinearEquiv_toLinearMap, AlgEquiv.toLinearEquiv_toOpposite] dsimp -- `simp` fails here due to a timeout looking for a `Subsingleton` instance!? rw [LinearEquiv.self_trans_symm] rfl attribute [ext] TensorProduct.ext theorem toBaseChange_comp_ofBaseChange (Q : QuadraticForm R V) : (toBaseChange A Q).comp (ofBaseChange A Q) = AlgHom.id _ _ := by ext v simp @[simp] theorem toBaseChange_ofBaseChange (Q : QuadraticForm R V) (x : A ⊗[R] CliffordAlgebra Q) : toBaseChange A Q (ofBaseChange A Q x) = x := AlgHom.congr_fun (toBaseChange_comp_ofBaseChange A Q :) x theorem ofBaseChange_comp_toBaseChange (Q : QuadraticForm R V) : (ofBaseChange A Q).comp (toBaseChange A Q) = AlgHom.id _ _ := by ext x change ofBaseChange A Q (toBaseChange A Q (ι (Q.baseChange A) (1 ⊗ₜ[R] x))) = ι (Q.baseChange A) (1 ⊗ₜ[R] x) rw [toBaseChange_ι, ofBaseChange_tmul_ι] @[simp] theorem ofBaseChange_toBaseChange (Q : QuadraticForm R V) (x : CliffordAlgebra (Q.baseChange A)) : ofBaseChange A Q (toBaseChange A Q x) = x := AlgHom.congr_fun (ofBaseChange_comp_toBaseChange A Q :) x /-- Base-changing the vector space of a clifford algebra is isomorphic as an A-algebra to base-changing the clifford algebra itself; <|Cℓ(A ⊗_R V, Q_A) ≅ A ⊗_R Cℓ(V, Q)<|. This is `CliffordAlgebra.toBaseChange` and `CliffordAlgebra.ofBaseChange` as an equivalence. -/ @[simps!] def equivBaseChange (Q : QuadraticForm R V) : CliffordAlgebra (Q.baseChange A) ≃ₐ[A] A ⊗[R] CliffordAlgebra Q := AlgEquiv.ofAlgHom (toBaseChange A Q) (ofBaseChange A Q) (toBaseChange_comp_ofBaseChange A Q) (ofBaseChange_comp_toBaseChange A Q) end CliffordAlgebra
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/Conjugation.lean
import Mathlib.LinearAlgebra.CliffordAlgebra.Grading import Mathlib.Algebra.Module.Opposite /-! # Conjugations This file defines the grade reversal and grade involution functions on multivectors, `reverse` and `involute`. Together, these operations compose to form the "Clifford conjugate", hence the name of this file. https://en.wikipedia.org/wiki/Clifford_algebra#Antiautomorphisms ## Main definitions * `CliffordAlgebra.involute`: the grade involution, negating each basis vector * `CliffordAlgebra.reverse`: the grade reversion, reversing the order of a product of vectors ## Main statements * `CliffordAlgebra.involute_involutive` * `CliffordAlgebra.reverse_involutive` * `CliffordAlgebra.reverse_involute_commute` * `CliffordAlgebra.involute_mem_evenOdd_iff` * `CliffordAlgebra.reverse_mem_evenOdd_iff` -/ variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable {Q : QuadraticForm R M} namespace CliffordAlgebra section Involute /-- Grade involution, inverting the sign of each basis vector. -/ def involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q := CliffordAlgebra.lift Q ⟨-ι Q, fun m => by simp⟩ @[simp] theorem involute_ι (m : M) : involute (ι Q m) = -ι Q m := lift_ι_apply _ _ m @[simp] theorem involute_comp_involute : involute.comp involute = AlgHom.id R (CliffordAlgebra Q) := by ext; simp theorem involute_involutive : Function.Involutive (involute : _ → CliffordAlgebra Q) := AlgHom.congr_fun involute_comp_involute @[simp] theorem involute_involute : ∀ a : CliffordAlgebra Q, involute (involute a) = a := involute_involutive /-- `CliffordAlgebra.involute` as an `AlgEquiv`. -/ @[simps!] def involuteEquiv : CliffordAlgebra Q ≃ₐ[R] CliffordAlgebra Q := AlgEquiv.ofAlgHom involute involute (AlgHom.ext <| involute_involute) (AlgHom.ext <| involute_involute) end Involute section Reverse open MulOpposite /-- `CliffordAlgebra.reverse` as an `AlgHom` to the opposite algebra -/ def reverseOp : CliffordAlgebra Q →ₐ[R] (CliffordAlgebra Q)ᵐᵒᵖ := CliffordAlgebra.lift Q ⟨(MulOpposite.opLinearEquiv R).toLinearMap ∘ₗ ι Q, fun m => unop_injective <| by simp⟩ @[simp] theorem reverseOp_ι (m : M) : reverseOp (ι Q m) = op (ι Q m) := lift_ι_apply _ _ _ /-- `CliffordAlgebra.reverseEquiv` as an `AlgEquiv` to the opposite algebra -/ @[simps! apply] def reverseOpEquiv : CliffordAlgebra Q ≃ₐ[R] (CliffordAlgebra Q)ᵐᵒᵖ := AlgEquiv.ofAlgHom reverseOp (AlgHom.opComm reverseOp) (AlgHom.unop.injective <| hom_ext <| LinearMap.ext fun _ => by simp) (hom_ext <| LinearMap.ext fun _ => by simp) @[simp] theorem reverseOpEquiv_opComm : AlgEquiv.opComm (reverseOpEquiv (Q := Q)) = reverseOpEquiv.symm := rfl /-- Grade reversion, inverting the multiplication order of basis vectors. Also called *transpose* in some literature. -/ def reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q := (opLinearEquiv R).symm.toLinearMap.comp reverseOp.toLinearMap @[simp] theorem unop_reverseOp (x : CliffordAlgebra Q) : (reverseOp x).unop = reverse x := rfl @[simp] theorem op_reverse (x : CliffordAlgebra Q) : op (reverse x) = reverseOp x := rfl @[simp] theorem reverse_ι (m : M) : reverse (ι Q m) = ι Q m := by simp [reverse] @[simp] theorem reverse.commutes (r : R) : reverse (algebraMap R (CliffordAlgebra Q) r) = algebraMap R _ r := op_injective <| reverseOp.commutes r @[simp] protected theorem reverse.map_one : reverse (1 : CliffordAlgebra Q) = 1 := op_injective (map_one reverseOp) @[simp] protected theorem reverse.map_mul (a b : CliffordAlgebra Q) : reverse (a * b) = reverse b * reverse a := op_injective (map_mul reverseOp a b) @[simp] theorem reverse_involutive : Function.Involutive (reverse (Q := Q)) := AlgHom.congr_fun reverseOpEquiv.symm_comp @[simp] theorem reverse_comp_reverse : reverse.comp reverse = (LinearMap.id : _ →ₗ[R] CliffordAlgebra Q) := LinearMap.ext reverse_involutive @[simp] theorem reverse_reverse : ∀ a : CliffordAlgebra Q, reverse (reverse a) = a := reverse_involutive /-- `CliffordAlgebra.reverse` as a `LinearEquiv`. -/ @[simps!] def reverseEquiv : CliffordAlgebra Q ≃ₗ[R] CliffordAlgebra Q := LinearEquiv.ofInvolutive reverse reverse_involutive theorem reverse_comp_involute : reverse.comp involute.toLinearMap = (involute.toLinearMap.comp reverse : _ →ₗ[R] CliffordAlgebra Q) := by ext x simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply] induction x using CliffordAlgebra.induction with | algebraMap => simp | ι => simp | mul a b ha hb => simp only [ha, hb, reverse.map_mul, map_mul] | add a b ha hb => simp only [ha, hb, reverse.map_add, map_add] /-- `CliffordAlgebra.reverse` and `CliffordAlgebra.involute` commute. Note that the composition is sometimes referred to as the "clifford conjugate". -/ theorem reverse_involute_commute : Function.Commute (reverse (Q := Q)) involute := LinearMap.congr_fun reverse_comp_involute theorem reverse_involute : ∀ a : CliffordAlgebra Q, reverse (involute a) = involute (reverse a) := reverse_involute_commute end Reverse /-! ### Statements about conjugations of products of lists -/ section List /-- Taking the reverse of the product a list of $n$ vectors lifted via `ι` is equivalent to taking the product of the reverse of that list. -/ theorem reverse_prod_map_ι : ∀ l : List M, reverse (l.map <| ι Q).prod = (l.map <| ι Q).reverse.prod | [] => by simp | x::xs => by simp [reverse_prod_map_ι xs] /-- Taking the involute of the product a list of $n$ vectors lifted via `ι` is equivalent to premultiplying by ${-1}^n$. -/ theorem involute_prod_map_ι : ∀ l : List M, involute (l.map <| ι Q).prod = (-1 : R) ^ l.length • (l.map <| ι Q).prod | [] => by simp | x::xs => by simp [pow_succ, involute_prod_map_ι xs] end List /-! ### Statements about `Submodule.map` and `Submodule.comap` -/ section Submodule variable (Q) section Involute theorem submodule_map_involute_eq_comap (p : Submodule R (CliffordAlgebra Q)) : p.map (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap = p.comap (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap := Submodule.map_equiv_eq_comap_symm involuteEquiv.toLinearEquiv _ @[simp] theorem ι_range_map_involute : (LinearMap.range (ι Q)).map (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap = LinearMap.range (ι Q) := (ι_range_map_lift _ _).trans (LinearMap.range_neg _) @[simp] theorem ι_range_comap_involute : (LinearMap.range (ι Q)).comap (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap = LinearMap.range (ι Q) := by rw [← submodule_map_involute_eq_comap, ι_range_map_involute] @[simp] theorem evenOdd_map_involute (n : ZMod 2) : (evenOdd Q n).map (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap = evenOdd Q n := by simp_rw [evenOdd, Submodule.map_iSup, Submodule.map_pow, ι_range_map_involute] @[simp] theorem evenOdd_comap_involute (n : ZMod 2) : (evenOdd Q n).comap (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap = evenOdd Q n := by rw [← submodule_map_involute_eq_comap, evenOdd_map_involute] end Involute section Reverse theorem submodule_map_reverse_eq_comap (p : Submodule R (CliffordAlgebra Q)) : p.map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = p.comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) := Submodule.map_equiv_eq_comap_symm (reverseEquiv : _ ≃ₗ[R] _) _ @[simp] theorem ι_range_map_reverse : (LinearMap.range (ι Q)).map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = LinearMap.range (ι Q) := by rw [reverse, reverseOp, Submodule.map_comp, ι_range_map_lift, LinearMap.range_comp, ← Submodule.map_comp] exact Submodule.map_id _ @[simp] theorem ι_range_comap_reverse : (LinearMap.range (ι Q)).comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = LinearMap.range (ι Q) := by rw [← submodule_map_reverse_eq_comap, ι_range_map_reverse] /-- Like `Submodule.map_mul`, but with the multiplication reversed. -/ theorem submodule_map_mul_reverse (p q : Submodule R (CliffordAlgebra Q)) : (p * q).map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = q.map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) * p.map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) := by simp_rw [reverse, Submodule.map_comp, Submodule.map_mul, Submodule.map_unop_mul] theorem submodule_comap_mul_reverse (p q : Submodule R (CliffordAlgebra Q)) : (p * q).comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = q.comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) * p.comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) := by simp_rw [← submodule_map_reverse_eq_comap, submodule_map_mul_reverse] /-- Like `Submodule.map_pow` -/ theorem submodule_map_pow_reverse (p : Submodule R (CliffordAlgebra Q)) (n : ℕ) : (p ^ n).map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = p.map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) ^ n := by simp_rw [reverse, Submodule.map_comp, Submodule.map_pow, Submodule.map_unop_pow] theorem submodule_comap_pow_reverse (p : Submodule R (CliffordAlgebra Q)) (n : ℕ) : (p ^ n).comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = p.comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) ^ n := by simp_rw [← submodule_map_reverse_eq_comap, submodule_map_pow_reverse] @[simp] theorem evenOdd_map_reverse (n : ZMod 2) : (evenOdd Q n).map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = evenOdd Q n := by simp_rw [evenOdd, Submodule.map_iSup, submodule_map_pow_reverse, ι_range_map_reverse] @[simp] theorem evenOdd_comap_reverse (n : ZMod 2) : (evenOdd Q n).comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = evenOdd Q n := by rw [← submodule_map_reverse_eq_comap, evenOdd_map_reverse] end Reverse @[simp] theorem involute_mem_evenOdd_iff {x : CliffordAlgebra Q} {n : ZMod 2} : involute x ∈ evenOdd Q n ↔ x ∈ evenOdd Q n := SetLike.ext_iff.mp (evenOdd_comap_involute Q n) x @[simp] theorem reverse_mem_evenOdd_iff {x : CliffordAlgebra Q} {n : ZMod 2} : reverse x ∈ evenOdd Q n ↔ x ∈ evenOdd Q n := SetLike.ext_iff.mp (evenOdd_comap_reverse Q n) x end Submodule /-! ### Related properties of the even and odd submodules TODO: show that these are `iff`s when `Invertible (2 : R)`. -/ theorem involute_eq_of_mem_even {x : CliffordAlgebra Q} (h : x ∈ evenOdd Q 0) : involute x = x := by induction x, h using even_induction with | algebraMap r => exact AlgHom.commutes _ _ | add x y _hx _hy ihx ihy => rw [map_add, ihx, ihy] | ι_mul_ι_mul m₁ m₂ x _hx ihx => rw [map_mul, map_mul, involute_ι, involute_ι, ihx, neg_mul_neg] theorem involute_eq_of_mem_odd {x : CliffordAlgebra Q} (h : x ∈ evenOdd Q 1) : involute x = -x := by induction x, h using odd_induction with | ι m => exact involute_ι _ | add x y _hx _hy ihx ihy => rw [map_add, ihx, ihy, neg_add] | ι_mul_ι_mul m₁ m₂ x _hx ihx => rw [map_mul, map_mul, involute_ι, involute_ι, ihx, neg_mul_neg, mul_neg] end CliffordAlgebra
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/Inversion.lean
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
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/EvenEquiv.lean
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation import Mathlib.LinearAlgebra.CliffordAlgebra.Even import Mathlib.LinearAlgebra.QuadraticForm.Prod /-! # Isomorphisms with the even subalgebra of a Clifford algebra This file provides some notable isomorphisms regarding the even subalgebra, `CliffordAlgebra.even`. ## Main definitions * `CliffordAlgebra.equivEven`: Every Clifford algebra is isomorphic as an algebra to the even subalgebra of a Clifford algebra with one more dimension. * `CliffordAlgebra.EquivEven.Q'`: The quadratic form used by this "one-up" algebra. * `CliffordAlgebra.toEven`: The simp-normal form of the forward direction of this isomorphism. * `CliffordAlgebra.ofEven`: The simp-normal form of the reverse direction of this isomorphism. * `CliffordAlgebra.evenEquivEvenNeg`: Every even subalgebra is isomorphic to the even subalgebra of the Clifford algebra with negated quadratic form. * `CliffordAlgebra.evenToNeg`: The simp-normal form of each direction of this isomorphism. ## Main results * `CliffordAlgebra.coe_toEven_reverse_involute`: the behavior of `CliffordAlgebra.toEven` on the "Clifford conjugate", that is `CliffordAlgebra.reverse` composed with `CliffordAlgebra.involute`. -/ namespace CliffordAlgebra variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] variable (Q : QuadraticForm R M) /-! ### Constructions needed for `CliffordAlgebra.equivEven` -/ namespace EquivEven /-- The quadratic form on the augmented vector space `M × R` sending `v + r•e0` to `Q v - r^2`. -/ abbrev Q' : QuadraticForm R (M × R) := Q.prod <| -QuadraticMap.sq (R := R) theorem Q'_apply (m : M × R) : Q' Q m = Q m.1 - m.2 * m.2 := (sub_eq_add_neg _ _).symm /-- The unit vector in the new dimension -/ def e0 : CliffordAlgebra (Q' Q) := ι (Q' Q) (0, 1) /-- The embedding from the existing vector space -/ def v : M →ₗ[R] CliffordAlgebra (Q' Q) := ι (Q' Q) ∘ₗ LinearMap.inl _ _ _ theorem ι_eq_v_add_smul_e0 (m : M) (r : R) : ι (Q' Q) (m, r) = v Q m + r • e0 Q := by rw [e0, v, LinearMap.comp_apply, LinearMap.inl_apply, ← LinearMap.map_smul, Prod.smul_mk, smul_zero, smul_eq_mul, mul_one, ← LinearMap.map_add, Prod.mk_add_mk, zero_add, add_zero] theorem e0_mul_e0 : e0 Q * e0 Q = -1 := (ι_sq_scalar _ _).trans <| by simp theorem v_sq_scalar (m : M) : v Q m * v Q m = algebraMap _ _ (Q m) := (ι_sq_scalar _ _).trans <| by simp theorem neg_e0_mul_v (m : M) : -(e0 Q * v Q m) = v Q m * e0 Q := by refine neg_eq_of_add_eq_zero_right ((ι_mul_ι_add_swap _ _).trans ?_) dsimp [QuadraticMap.polar] simp only [add_zero, mul_zero, mul_one, zero_add, neg_zero, add_sub_cancel_right, sub_self, map_zero] theorem neg_v_mul_e0 (m : M) : -(v Q m * e0 Q) = e0 Q * v Q m := by rw [neg_eq_iff_eq_neg] exact (neg_e0_mul_v _ m).symm @[simp] theorem e0_mul_v_mul_e0 (m : M) : e0 Q * v Q m * e0 Q = v Q m := by rw [← neg_v_mul_e0, ← neg_mul, mul_assoc, e0_mul_e0, mul_neg_one, neg_neg] @[simp] theorem reverse_v (m : M) : reverse (Q := Q' Q) (v Q m) = v Q m := reverse_ι _ @[simp] theorem involute_v (m : M) : involute (v Q m) = -v Q m := involute_ι _ @[simp] theorem reverse_e0 : reverse (Q := Q' Q) (e0 Q) = e0 Q := reverse_ι _ @[simp] theorem involute_e0 : involute (e0 Q) = -e0 Q := involute_ι _ end EquivEven open EquivEven /-- The embedding from the smaller algebra into the new larger one. -/ def toEven : CliffordAlgebra Q →ₐ[R] CliffordAlgebra.even (Q' Q) := by refine CliffordAlgebra.lift Q ⟨?_, fun m => ?_⟩ · refine LinearMap.codRestrict _ ?_ fun m => Submodule.mem_iSup_of_mem ⟨2, rfl⟩ ?_ · exact (LinearMap.mulLeft R <| e0 Q).comp (v Q) rw [Subtype.coe_mk, pow_two] exact Submodule.mul_mem_mul (LinearMap.mem_range_self _ _) (LinearMap.mem_range_self _ _) · ext1 rw [Subalgebra.coe_mul] -- Porting note: was part of the `dsimp only` below erw [LinearMap.codRestrict_apply] -- Porting note: was part of the `dsimp only` below dsimp only [LinearMap.comp_apply, LinearMap.mulLeft_apply, Subalgebra.coe_algebraMap] rw [← mul_assoc, e0_mul_v_mul_e0, v_sq_scalar] theorem toEven_ι (m : M) : (toEven Q (ι Q m) : CliffordAlgebra (Q' Q)) = e0 Q * v Q m := by rw [toEven, CliffordAlgebra.lift_ι_apply] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11224): was `rw` erw [LinearMap.codRestrict_apply] rw [LinearMap.coe_comp, Function.comp_apply, LinearMap.mulLeft_apply] /-- The embedding from the even subalgebra with an extra dimension into the original algebra. -/ def ofEven : CliffordAlgebra.even (Q' Q) →ₐ[R] CliffordAlgebra Q := by /- Recall that we need: * `f ⟨0,1⟩ ⟨x,0⟩ = ι x` * `f ⟨x,0⟩ ⟨0,1⟩ = -ι x` * `f ⟨x,0⟩ ⟨y,0⟩ = ι x * ι y` * `f ⟨0,1⟩ ⟨0,1⟩ = -1` -/ let f : M × R →ₗ[R] M × R →ₗ[R] CliffordAlgebra Q := ((Algebra.lmul R (CliffordAlgebra Q)).toLinearMap.comp <| (ι Q).comp (LinearMap.fst _ _ _) + (Algebra.linearMap R _).comp (LinearMap.snd _ _ _)).compl₂ ((ι Q).comp (LinearMap.fst _ _ _) - (Algebra.linearMap R _).comp (LinearMap.snd _ _ _)) haveI f_apply : ∀ x y, f x y = (ι Q x.1 + algebraMap R _ x.2) * (ι Q y.1 - algebraMap R _ y.2) := fun x y => by rfl haveI hc : ∀ (r : R) (x : CliffordAlgebra Q), Commute (algebraMap _ _ r) x := Algebra.commutes haveI hm : ∀ m : M × R, ι Q m.1 * ι Q m.1 - algebraMap R _ m.2 * algebraMap R _ m.2 = algebraMap R _ (Q' Q m) := by intro m rw [ι_sq_scalar, ← RingHom.map_mul, ← RingHom.map_sub, sub_eq_add_neg, Q'_apply, sub_eq_add_neg] refine even.lift (Q' Q) ⟨f, ?_, ?_⟩ <;> simp_rw [f_apply] · intro m rw [← (hc _ _).symm.mul_self_sub_mul_self_eq, hm] · intro m₁ m₂ m₃ rw [← mul_smul_comm, ← mul_assoc, mul_assoc (_ + _), ← (hc _ _).symm.mul_self_sub_mul_self_eq', Algebra.smul_def, ← mul_assoc, hm] theorem ofEven_ι (x y : M × R) : ofEven Q ((even.ι (Q' Q)).bilin x y) = (ι Q x.1 + algebraMap R _ x.2) * (ι Q y.1 - algebraMap R _ y.2) := even.lift_ι (Q' Q) _ x y theorem toEven_comp_ofEven : (toEven Q).comp (ofEven Q) = AlgHom.id R _ := even.algHom_ext (Q' Q) <| EvenHom.ext <| LinearMap.ext fun m₁ => LinearMap.ext fun m₂ => Subtype.ext <| let ⟨m₁, r₁⟩ := m₁ let ⟨m₂, r₂⟩ := m₂ calc ↑(toEven Q (ofEven Q ((even.ι (Q' Q)).bilin (m₁, r₁) (m₂, r₂)))) = (e0 Q * v Q m₁ + algebraMap R _ r₁) * (e0 Q * v Q m₂ - algebraMap R _ r₂) := by rw [ofEven_ι, map_mul, map_add, map_sub, AlgHom.commutes, AlgHom.commutes, Subalgebra.coe_mul, Subalgebra.coe_add, Subalgebra.coe_sub, toEven_ι, toEven_ι, Subalgebra.coe_algebraMap, Subalgebra.coe_algebraMap] _ = e0 Q * v Q m₁ * (e0 Q * v Q m₂) + r₁ • e0 Q * v Q m₂ - r₂ • e0 Q * v Q m₁ - algebraMap R _ (r₁ * r₂) := by rw [mul_sub, add_mul, add_mul, ← Algebra.commutes, ← Algebra.smul_def, ← map_mul, ← Algebra.smul_def, sub_add_eq_sub_sub, smul_mul_assoc, smul_mul_assoc] _ = v Q m₁ * v Q m₂ + r₁ • e0 Q * v Q m₂ + v Q m₁ * r₂ • e0 Q + r₁ • e0 Q * r₂ • e0 Q := by have h1 : e0 Q * v Q m₁ * (e0 Q * v Q m₂) = v Q m₁ * v Q m₂ := by rw [← mul_assoc, e0_mul_v_mul_e0] have h2 : -(r₂ • e0 Q * v Q m₁) = v Q m₁ * r₂ • e0 Q := by rw [mul_smul_comm, smul_mul_assoc, ← smul_neg, neg_e0_mul_v] have h3 : -algebraMap R _ (r₁ * r₂) = r₁ • e0 Q * r₂ • e0 Q := by rw [Algebra.algebraMap_eq_smul_one, smul_mul_smul_comm, e0_mul_e0, smul_neg] rw [sub_eq_add_neg, sub_eq_add_neg, h1, h2, h3] _ = ι (Q' Q) (m₁, r₁) * ι (Q' Q) (m₂, r₂) := by rw [ι_eq_v_add_smul_e0, ι_eq_v_add_smul_e0, mul_add, add_mul, add_mul, add_assoc] theorem ofEven_comp_toEven : (ofEven Q).comp (toEven Q) = AlgHom.id R _ := CliffordAlgebra.hom_ext <| LinearMap.ext fun m => calc ofEven Q (toEven Q (ι Q m)) = ofEven Q ⟨_, (toEven Q (ι Q m)).prop⟩ := by rw [Subtype.coe_eta] _ = (ι Q 0 + algebraMap R _ 1) * (ι Q m - algebraMap R _ 0) := by simp_rw [toEven_ι] exact ofEven_ι Q _ _ _ = ι Q m := by rw [map_one, map_zero, map_zero, sub_zero, zero_add, one_mul] /-- Any clifford algebra is isomorphic to the even subalgebra of a clifford algebra with an extra dimension (that is, with vector space `M × R`), with a quadratic form evaluating to `-1` on that new basis vector. -/ def equivEven : CliffordAlgebra Q ≃ₐ[R] CliffordAlgebra.even (Q' Q) := AlgEquiv.ofAlgHom (toEven Q) (ofEven Q) (toEven_comp_ofEven Q) (ofEven_comp_toEven Q) /-- The representation of the clifford conjugate (i.e. the reverse of the involute) in the even subalgebra is just the reverse of the representation. -/ theorem coe_toEven_reverse_involute (x : CliffordAlgebra Q) : ↑(toEven Q (reverse (involute x))) = reverse (Q := Q' Q) (toEven Q x : CliffordAlgebra (Q' Q)) := by induction x using CliffordAlgebra.induction with | algebraMap r => simp only [AlgHom.commutes, Subalgebra.coe_algebraMap, reverse.commutes] | ι m => simp only [involute_ι, Subalgebra.coe_neg, toEven_ι, reverse.map_mul, reverse_v, reverse_e0, reverse_ι, neg_e0_mul_v, map_neg] | mul x y hx hy => simp only [map_mul, Subalgebra.coe_mul, reverse.map_mul, hx, hy] | add x y hx hy => simp only [map_add, Subalgebra.coe_add, hx, hy] /-! ### Constructions needed for `CliffordAlgebra.evenEquivEvenNeg` -/ /-- One direction of `CliffordAlgebra.evenEquivEvenNeg` -/ def evenToNeg (Q' : QuadraticForm R M) (h : Q' = -Q) : CliffordAlgebra.even Q →ₐ[R] CliffordAlgebra.even Q' := even.lift Q <| { bilin := -(even.ι Q' :).bilin contract := fun m => by simp_rw [LinearMap.neg_apply, EvenHom.contract, h, QuadraticMap.neg_apply, map_neg, neg_neg] contract_mid := fun m₁ m₂ m₃ => by simp_rw [LinearMap.neg_apply, neg_mul_neg, EvenHom.contract_mid, h, QuadraticMap.neg_apply, smul_neg, neg_smul] } @[simp] theorem evenToNeg_ι (Q' : QuadraticForm R M) (h : Q' = -Q) (m₁ m₂ : M) : evenToNeg Q Q' h ((even.ι Q).bilin m₁ m₂) = -(even.ι Q').bilin m₁ m₂ := even.lift_ι _ _ m₁ m₂ theorem evenToNeg_comp_evenToNeg (Q' : QuadraticForm R M) (h : Q' = -Q) (h' : Q = -Q') : (evenToNeg Q' Q h').comp (evenToNeg Q Q' h) = AlgHom.id R _ := by ext m₁ m₂ : 4 simp [evenToNeg_ι] /-- The even subalgebras of the algebras with quadratic form `Q` and `-Q` are isomorphic. Stated another way, `𝒞ℓ⁺(p,q,r)` and `𝒞ℓ⁺(q,p,r)` are isomorphic. -/ @[simps!] def evenEquivEvenNeg : CliffordAlgebra.even Q ≃ₐ[R] CliffordAlgebra.even (-Q) := AlgEquiv.ofAlgHom (evenToNeg Q _ rfl) (evenToNeg (-Q) _ (neg_neg _).symm) (evenToNeg_comp_evenToNeg _ _ _ _) (evenToNeg_comp_evenToNeg _ _ _ _) end CliffordAlgebra
.lake/packages/mathlib/Mathlib/LinearAlgebra/CliffordAlgebra/Equivs.lean
import Mathlib.Algebra.DualNumber import Mathlib.Algebra.QuaternionBasis import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation import Mathlib.LinearAlgebra.CliffordAlgebra.Star import Mathlib.LinearAlgebra.Complex.Module import Mathlib.LinearAlgebra.QuadraticForm.Prod /-! # Other constructions isomorphic to Clifford Algebras This file contains isomorphisms showing that other types are equivalent to some `CliffordAlgebra`. ## Rings * `CliffordAlgebraRing.equiv`: any ring is equivalent to a `CliffordAlgebra` over a zero-dimensional vector space. ## Complex numbers * `CliffordAlgebraComplex.equiv`: the `Complex` numbers are equivalent as an `ℝ`-algebra to a `CliffordAlgebra` over a one-dimensional vector space with a quadratic form that satisfies `Q (ι Q 1) = -1`. * `CliffordAlgebraComplex.toComplex`: the forward direction of this equiv * `CliffordAlgebraComplex.ofComplex`: the reverse direction of this equiv We show additionally that this equivalence sends `Complex.conj` to `CliffordAlgebra.involute` and vice-versa: * `CliffordAlgebraComplex.toComplex_involute` * `CliffordAlgebraComplex.ofComplex_conj` Note that in this algebra `CliffordAlgebra.reverse` is the identity and so the clifford conjugate is the same as `CliffordAlgebra.involute`. ## Quaternion algebras * `CliffordAlgebraQuaternion.equiv`: a `QuaternionAlgebra` over `R` is equivalent as an `R`-algebra to a clifford algebra over `R × R`, sending `i` to `(0, 1)` and `j` to `(1, 0)`. * `CliffordAlgebraQuaternion.toQuaternion`: the forward direction of this equiv * `CliffordAlgebraQuaternion.ofQuaternion`: the reverse direction of this equiv We show additionally that this equivalence sends `QuaternionAlgebra.conj` to the clifford conjugate and vice-versa: * `CliffordAlgebraQuaternion.toQuaternion_star` * `CliffordAlgebraQuaternion.ofQuaternion_star` ## Dual numbers * `CliffordAlgebraDualNumber.equiv`: `R[ε]` is equivalent as an `R`-algebra to a clifford algebra over `R` where `Q = 0`. -/ open CliffordAlgebra /-! ### The clifford algebra isomorphic to a ring -/ namespace CliffordAlgebraRing open scoped ComplexConjugate variable {R : Type*} [CommRing R] @[simp] theorem ι_eq_zero : ι (0 : QuadraticForm R Unit) = 0 := Subsingleton.elim _ _ /-- Since the vector space is empty the ring is commutative. -/ instance : CommRing (CliffordAlgebra (0 : QuadraticForm R Unit)) where mul_comm := fun x y => by induction x using CliffordAlgebra.induction with | algebraMap r => apply Algebra.commutes | ι x => simp | add x₁ x₂ hx₁ hx₂ => rw [mul_add, add_mul, hx₁, hx₂] | mul x₁ x₂ hx₁ hx₂ => rw [mul_assoc, hx₂, ← mul_assoc, hx₁, ← mul_assoc] theorem reverse_apply (x : CliffordAlgebra (0 : QuadraticForm R Unit)) : x.reverse = x := by induction x using CliffordAlgebra.induction with | algebraMap r => exact reverse.commutes _ | ι x => rw [ι_eq_zero, LinearMap.zero_apply, reverse.map_zero] | mul x₁ x₂ hx₁ hx₂ => rw [reverse.map_mul, mul_comm, hx₁, hx₂] | add x₁ x₂ hx₁ hx₂ => rw [reverse.map_add, hx₁, hx₂] @[simp] theorem reverse_eq_id : (reverse : CliffordAlgebra (0 : QuadraticForm R Unit) →ₗ[R] _) = LinearMap.id := LinearMap.ext reverse_apply @[simp] theorem involute_eq_id : (involute : CliffordAlgebra (0 : QuadraticForm R Unit) →ₐ[R] _) = AlgHom.id R _ := by ext; simp /-- The clifford algebra over a 0-dimensional vector space is isomorphic to its scalars. -/ protected def equiv : CliffordAlgebra (0 : QuadraticForm R Unit) ≃ₐ[R] R := AlgEquiv.ofAlgHom (CliffordAlgebra.lift (0 : QuadraticForm R Unit) <| ⟨0, fun _ : Unit => (zero_mul (0 : R)).trans (algebraMap R _).map_zero.symm⟩) (Algebra.ofId R _) (by ext) (by ext : 1; rw [ι_eq_zero, LinearMap.comp_zero, LinearMap.comp_zero]) end CliffordAlgebraRing /-! ### The clifford algebra isomorphic to the complex numbers -/ namespace CliffordAlgebraComplex open scoped ComplexConjugate /-- The quadratic form sending elements to the negation of their square. -/ def Q : QuadraticForm ℝ ℝ := -QuadraticMap.sq @[simp] theorem Q_apply (r : ℝ) : Q r = -(r * r) := rfl /-- Intermediate result for `CliffordAlgebraComplex.equiv`: clifford algebras over `CliffordAlgebraComplex.Q` above can be converted to `ℂ`. -/ def toComplex : CliffordAlgebra Q →ₐ[ℝ] ℂ := CliffordAlgebra.lift Q ⟨LinearMap.toSpanSingleton _ _ Complex.I, fun r => by dsimp [LinearMap.toSpanSingleton, LinearMap.id] rw [mul_mul_mul_comm] simp⟩ @[simp] theorem toComplex_ι (r : ℝ) : toComplex (ι Q r) = r • Complex.I := CliffordAlgebra.lift_ι_apply _ _ r /-- `CliffordAlgebra.involute` is analogous to `Complex.conj`. -/ @[simp] theorem toComplex_involute (c : CliffordAlgebra Q) : toComplex (involute c) = conj (toComplex c) := by have : toComplex (involute (ι Q 1)) = conj (toComplex (ι Q 1)) := by simp only [involute_ι, toComplex_ι, map_neg, one_smul, Complex.conj_I] suffices toComplex.comp involute = Complex.conjAe.toAlgHom.comp toComplex by exact AlgHom.congr_fun this c ext : 2 exact this /-- Intermediate result for `CliffordAlgebraComplex.equiv`: `ℂ` can be converted to `CliffordAlgebraComplex.Q` above can be converted to. -/ def ofComplex : ℂ →ₐ[ℝ] CliffordAlgebra Q := Complex.lift ⟨CliffordAlgebra.ι Q 1, by rw [CliffordAlgebra.ι_sq_scalar, Q_apply, one_mul, RingHom.map_neg, RingHom.map_one]⟩ @[simp] theorem ofComplex_I : ofComplex Complex.I = ι Q 1 := Complex.liftAux_apply_I _ (by simp) @[simp] theorem toComplex_comp_ofComplex : toComplex.comp ofComplex = AlgHom.id ℝ ℂ := by ext1 dsimp only [AlgHom.comp_apply, Subtype.coe_mk, AlgHom.id_apply] rw [ofComplex_I, toComplex_ι, one_smul] @[simp] theorem toComplex_ofComplex (c : ℂ) : toComplex (ofComplex c) = c := AlgHom.congr_fun toComplex_comp_ofComplex c @[simp] theorem ofComplex_comp_toComplex : ofComplex.comp toComplex = AlgHom.id ℝ (CliffordAlgebra Q) := by ext dsimp only [LinearMap.comp_apply, Subtype.coe_mk, AlgHom.id_apply, AlgHom.toLinearMap_apply, AlgHom.comp_apply] rw [toComplex_ι, one_smul, ofComplex_I] @[simp] theorem ofComplex_toComplex (c : CliffordAlgebra Q) : ofComplex (toComplex c) = c := AlgHom.congr_fun ofComplex_comp_toComplex c /-- The clifford algebras over `CliffordAlgebraComplex.Q` is isomorphic as an `ℝ`-algebra to `ℂ`. -/ @[simps!] protected def equiv : CliffordAlgebra Q ≃ₐ[ℝ] ℂ := AlgEquiv.ofAlgHom toComplex ofComplex toComplex_comp_ofComplex ofComplex_comp_toComplex /-- The clifford algebra is commutative since it is isomorphic to the complex numbers. TODO: prove this is true for all `CliffordAlgebra`s over a 1-dimensional vector space. -/ instance : CommRing (CliffordAlgebra Q) where mul_comm := fun x y => CliffordAlgebraComplex.equiv.injective <| by rw [map_mul, mul_comm, map_mul] /-- `reverse` is a no-op over `CliffordAlgebraComplex.Q`. -/ theorem reverse_apply (x : CliffordAlgebra Q) : x.reverse = x := by induction x using CliffordAlgebra.induction with | algebraMap r => exact reverse.commutes _ | ι x => rw [reverse_ι] | mul x₁ x₂ hx₁ hx₂ => rw [reverse.map_mul, mul_comm, hx₁, hx₂] | add x₁ x₂ hx₁ hx₂ => rw [reverse.map_add, hx₁, hx₂] @[simp] theorem reverse_eq_id : (reverse : CliffordAlgebra Q →ₗ[ℝ] _) = LinearMap.id := LinearMap.ext reverse_apply /-- `Complex.conj` is analogous to `CliffordAlgebra.involute`. -/ @[simp] theorem ofComplex_conj (c : ℂ) : ofComplex (conj c) = involute (ofComplex c) := CliffordAlgebraComplex.equiv.injective <| by rw [equiv_apply, equiv_apply, toComplex_involute, toComplex_ofComplex, toComplex_ofComplex] end CliffordAlgebraComplex /-! ### The clifford algebra isomorphic to the quaternions -/ namespace CliffordAlgebraQuaternion open scoped Quaternion open QuaternionAlgebra variable {R : Type*} [CommRing R] (c₁ c₂ : R) /-- `Q c₁ c₂` is a quadratic form over `R × R` such that `CliffordAlgebra (Q c₁ c₂)` is isomorphic as an `R`-algebra to `ℍ[R,c₁,c₂]`. -/ def Q : QuadraticForm R (R × R) := (c₁ • QuadraticMap.sq).prod (c₂ • QuadraticMap.sq) @[simp] theorem Q_apply (v : R × R) : Q c₁ c₂ v = c₁ * (v.1 * v.1) + c₂ * (v.2 * v.2) := rfl /-- The quaternion basis vectors within the algebra. -/ @[simps i j k] def quaternionBasis : QuaternionAlgebra.Basis (CliffordAlgebra (Q c₁ c₂)) c₁ 0 c₂ where i := ι (Q c₁ c₂) (1, 0) j := ι (Q c₁ c₂) (0, 1) k := ι (Q c₁ c₂) (1, 0) * ι (Q c₁ c₂) (0, 1) i_mul_i := by rw [ι_sq_scalar, Q_apply, ← Algebra.algebraMap_eq_smul_one] simp j_mul_j := by rw [ι_sq_scalar, Q_apply, ← Algebra.algebraMap_eq_smul_one] simp i_mul_j := rfl j_mul_i := by rw [zero_smul, zero_sub, eq_neg_iff_add_eq_zero, ι_mul_ι_add_swap, QuadraticMap.polar] simp variable {c₁ c₂} /-- Intermediate result of `CliffordAlgebraQuaternion.equiv`: clifford algebras over `CliffordAlgebraQuaternion.Q` can be converted to `ℍ[R,c₁,c₂]`. -/ def toQuaternion : CliffordAlgebra (Q c₁ c₂) →ₐ[R] ℍ[R,c₁,0,c₂] := CliffordAlgebra.lift (Q c₁ c₂) ⟨{ toFun := fun v => (⟨0, v.1, v.2, 0⟩ : ℍ[R,c₁,0,c₂]) map_add' := fun v₁ v₂ => by simp map_smul' := fun r v => by dsimp; rw [mul_zero] }, fun v => by dsimp ext all_goals dsimp; ring⟩ @[simp] theorem toQuaternion_ι (v : R × R) : toQuaternion (ι (Q c₁ c₂) v) = (⟨0, v.1, v.2, 0⟩ : ℍ[R,c₁,0,c₂]) := CliffordAlgebra.lift_ι_apply _ _ v /-- The "clifford conjugate" maps to the quaternion conjugate. -/ theorem toQuaternion_star (c : CliffordAlgebra (Q c₁ c₂)) : toQuaternion (star c) = star (toQuaternion c) := by simp only [CliffordAlgebra.star_def'] induction c using CliffordAlgebra.induction with | algebraMap r => simp | ι x => simp | mul x₁ x₂ hx₁ hx₂ => simp [hx₁, hx₂] | add x₁ x₂ hx₁ hx₂ => simp [hx₁, hx₂] /-- Map a quaternion into the clifford algebra. -/ def ofQuaternion : ℍ[R,c₁,0,c₂] →ₐ[R] CliffordAlgebra (Q c₁ c₂) := (quaternionBasis c₁ c₂).liftHom @[simp] theorem ofQuaternion_mk (a₁ a₂ a₃ a₄ : R) : ofQuaternion (⟨a₁, a₂, a₃, a₄⟩ : ℍ[R,c₁,0,c₂]) = algebraMap R _ a₁ + a₂ • ι (Q c₁ c₂) (1, 0) + a₃ • ι (Q c₁ c₂) (0, 1) + a₄ • (ι (Q c₁ c₂) (1, 0) * ι (Q c₁ c₂) (0, 1)) := rfl @[simp] theorem ofQuaternion_comp_toQuaternion : ofQuaternion.comp toQuaternion = AlgHom.id R (CliffordAlgebra (Q c₁ c₂)) := by ext : 1 dsimp -- before we end up with two goals and have to do this twice ext all_goals dsimp rw [toQuaternion_ι] dsimp simp only [zero_smul, one_smul, zero_add, add_zero, RingHom.map_zero] @[simp] theorem ofQuaternion_toQuaternion (c : CliffordAlgebra (Q c₁ c₂)) : ofQuaternion (toQuaternion c) = c := AlgHom.congr_fun ofQuaternion_comp_toQuaternion c @[simp] theorem toQuaternion_comp_ofQuaternion : toQuaternion.comp ofQuaternion = AlgHom.id R ℍ[R,c₁,0,c₂] := by ext : 1 <;> simp @[simp] theorem toQuaternion_ofQuaternion (q : ℍ[R,c₁,0,c₂]) : toQuaternion (ofQuaternion q) = q := AlgHom.congr_fun toQuaternion_comp_ofQuaternion q /-- The clifford algebra over `CliffordAlgebraQuaternion.Q c₁ c₂` is isomorphic as an `R`-algebra to `ℍ[R,c₁,c₂]`. -/ @[simps!] protected def equiv : CliffordAlgebra (Q c₁ c₂) ≃ₐ[R] ℍ[R,c₁,0,c₂] := AlgEquiv.ofAlgHom toQuaternion ofQuaternion toQuaternion_comp_ofQuaternion ofQuaternion_comp_toQuaternion /-- The quaternion conjugate maps to the "clifford conjugate" (aka `star`). -/ @[simp] theorem ofQuaternion_star (q : ℍ[R,c₁,0,c₂]) : ofQuaternion (star q) = star (ofQuaternion q) := CliffordAlgebraQuaternion.equiv.injective <| by rw [equiv_apply, equiv_apply, toQuaternion_star, toQuaternion_ofQuaternion, toQuaternion_ofQuaternion] end CliffordAlgebraQuaternion /-! ### The clifford algebra isomorphic to the dual numbers -/ namespace CliffordAlgebraDualNumber open scoped DualNumber open DualNumber TrivSqZeroExt variable {R : Type*} [CommRing R] theorem ι_mul_ι (r₁ r₂) : ι (0 : QuadraticForm R R) r₁ * ι (0 : QuadraticForm R R) r₂ = 0 := by rw [← mul_one r₁, ← mul_one r₂, ← smul_eq_mul r₁, ← smul_eq_mul r₂, LinearMap.map_smul, LinearMap.map_smul, smul_mul_smul_comm, ι_sq_scalar, QuadraticMap.zero_apply, RingHom.map_zero, smul_zero] /-- The clifford algebra over a 1-dimensional vector space with 0 quadratic form is isomorphic to the dual numbers. -/ protected def equiv : CliffordAlgebra (0 : QuadraticForm R R) ≃ₐ[R] R[ε] := AlgEquiv.ofAlgHom (CliffordAlgebra.lift (0 : QuadraticForm R R) ⟨inrHom R _, fun m => inr_mul_inr _ m m⟩) (DualNumber.lift ⟨ (Algebra.ofId _ _, ι (R := R) _ 1), ι_mul_ι (1 : R) 1, fun _ => (Algebra.commutes _ _).symm⟩) (by ext : 1 -- This used to be a single `simp` before https://github.com/leanprover/lean4/pull/2644 simp only [QuadraticMap.zero_apply, AlgHom.coe_comp, Function.comp_apply, lift_apply_eps, AlgHom.coe_id, id_eq] erw [lift_ι_apply] simp) -- This used to be a single `simp` before https://github.com/leanprover/lean4/pull/2644 (by ext : 2 simp only [QuadraticMap.zero_apply, AlgHom.comp_toLinearMap, LinearMap.coe_comp, Function.comp_apply, AlgHom.toLinearMap_apply, AlgHom.toLinearMap_id, LinearMap.id_comp] erw [lift_ι_apply] simp) @[simp] theorem equiv_ι (r : R) : CliffordAlgebraDualNumber.equiv (ι (R := R) _ r) = r • ε := (lift_ι_apply _ _ r).trans (inr_eq_smul_eps _) @[simp] theorem equiv_symm_eps : CliffordAlgebraDualNumber.equiv.symm (eps : R[ε]) = ι (0 : QuadraticForm R R) 1 := DualNumber.lift_apply_eps _ end CliffordAlgebraDualNumber
.lake/packages/mathlib/Mathlib/LinearAlgebra/Alternating/DomCoprod.lean
import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.GroupTheory.Coset.Card import Mathlib.GroupTheory.GroupAction.Quotient import Mathlib.GroupTheory.Perm.Basic import Mathlib.LinearAlgebra.Alternating.Basic import Mathlib.LinearAlgebra.Multilinear.TensorProduct /-! # Exterior product of alternating maps In this file we define `AlternatingMap.domCoprod` to be the exterior product of two alternating maps, taking values in the tensor product of the codomains of the original maps. -/ open TensorProduct variable {ιa ιb : Type*} [Fintype ιa] [Fintype ιb] variable {R' : Type*} {Mᵢ N₁ N₂ : Type*} [CommSemiring R'] [AddCommGroup N₁] [Module R' N₁] [AddCommGroup N₂] [Module R' N₂] [AddCommMonoid Mᵢ] [Module R' Mᵢ] namespace Equiv.Perm /-- Elements which are considered equivalent if they differ only by swaps within α or β -/ abbrev ModSumCongr (α β : Type*) := _ ⧸ (Equiv.Perm.sumCongrHom α β).range end Equiv.Perm namespace AlternatingMap open Equiv variable [DecidableEq ιa] [DecidableEq ιb] /-- summand used in `AlternatingMap.domCoprod` -/ def domCoprod.summand (a : Mᵢ [⋀^ιa]→ₗ[R'] N₁) (b : Mᵢ [⋀^ιb]→ₗ[R'] N₂) (σ : Perm.ModSumCongr ιa ιb) : MultilinearMap R' (fun _ : ιa ⊕ ιb => Mᵢ) (N₁ ⊗[R'] N₂) := Quotient.liftOn' σ (fun σ => Equiv.Perm.sign σ • (MultilinearMap.domCoprod ↑a ↑b : MultilinearMap R' (fun _ => Mᵢ) (N₁ ⊗ N₂)).domDomCongr σ) fun σ₁ σ₂ H => by rw [QuotientGroup.leftRel_apply] at H obtain ⟨⟨sl, sr⟩, h⟩ := H ext v simp only [MultilinearMap.domDomCongr_apply, MultilinearMap.domCoprod_apply, coe_multilinearMap, MultilinearMap.smul_apply] replace h := inv_mul_eq_iff_eq_mul.mp h.symm have : Equiv.Perm.sign (σ₁ * Perm.sumCongrHom _ _ (sl, sr)) = Equiv.Perm.sign σ₁ * (Equiv.Perm.sign sl * Equiv.Perm.sign sr) := by simp rw [h, this, mul_smul, mul_smul, smul_left_cancel_iff, ← TensorProduct.tmul_smul, TensorProduct.smul_tmul', a.map_congr_perm _ sl, b.map_congr_perm _ sr] simp only [Sum.map_inr, Perm.sumCongrHom_apply, Perm.sumCongr_apply, Sum.map_inl, Function.comp_def, Perm.coe_mul] theorem domCoprod.summand_mk'' (a : Mᵢ [⋀^ιa]→ₗ[R'] N₁) (b : Mᵢ [⋀^ιb]→ₗ[R'] N₂) (σ : Equiv.Perm (ιa ⊕ ιb)) : domCoprod.summand a b (Quotient.mk'' σ) = Equiv.Perm.sign σ • (MultilinearMap.domCoprod ↑a ↑b : MultilinearMap R' (fun _ => Mᵢ) (N₁ ⊗ N₂)).domDomCongr σ := rfl /-- Swapping elements in `σ` with equal values in `v` results in an addition that cancels -/ theorem domCoprod.summand_add_swap_smul_eq_zero (a : Mᵢ [⋀^ιa]→ₗ[R'] N₁) (b : Mᵢ [⋀^ιb]→ₗ[R'] N₂) (σ : Perm.ModSumCongr ιa ιb) {v : ιa ⊕ ιb → Mᵢ} {i j : ιa ⊕ ιb} (hv : v i = v j) (hij : i ≠ j) : domCoprod.summand a b σ v + domCoprod.summand a b (swap i j • σ) v = 0 := by refine Quotient.inductionOn' σ fun σ => ?_ dsimp only [Quotient.liftOn'_mk'', Quotient.map'_mk'', MulAction.Quotient.smul_mk, domCoprod.summand] rw [smul_eq_mul, Perm.sign_mul, Perm.sign_swap hij] simp only [one_mul, neg_mul, Function.comp_apply, Units.neg_smul, Perm.coe_mul, MultilinearMap.smul_apply, MultilinearMap.neg_apply, MultilinearMap.domDomCongr_apply, MultilinearMap.domCoprod_apply] convert add_neg_cancel (G := N₁ ⊗[R'] N₂) _ using 6 <;> · ext k rw [Equiv.apply_swap_eq_self hv] /-- Swapping elements in `σ` with equal values in `v` result in zero if the swap has no effect on the quotient. -/ theorem domCoprod.summand_eq_zero_of_smul_invariant (a : Mᵢ [⋀^ιa]→ₗ[R'] N₁) (b : Mᵢ [⋀^ιb]→ₗ[R'] N₂) (σ : Perm.ModSumCongr ιa ιb) {v : ιa ⊕ ιb → Mᵢ} {i j : ιa ⊕ ιb} (hv : v i = v j) (hij : i ≠ j) : swap i j • σ = σ → domCoprod.summand a b σ v = 0 := by refine Quotient.inductionOn' σ fun σ => ?_ dsimp only [Quotient.liftOn'_mk'', Quotient.map'_mk'', MultilinearMap.smul_apply, MultilinearMap.domDomCongr_apply, MultilinearMap.domCoprod_apply, domCoprod.summand] intro hσ obtain ⟨⟨sl, sr⟩, hσ⟩ := QuotientGroup.leftRel_apply.mp (Quotient.exact' hσ) rcases hi : σ⁻¹ i with i' | i' <;> rcases hj : σ⁻¹ j with j' | j' <;> rw [Perm.inv_eq_iff_eq] at hi hj <;> substs hi hj -- the term pairs with and cancels another term case inl.inr => simpa using Equiv.congr_fun hσ (Sum.inl i') case inr.inl => simpa using Equiv.congr_fun hσ (Sum.inr i') -- the term does not pair but is zero case inl.inl => suffices (a fun i ↦ v (σ (Sum.inl i))) = 0 by simp_all exact AlternatingMap.map_eq_zero_of_eq _ _ hv fun hij' => hij (hij' ▸ rfl) case inr.inr => suffices (b fun i ↦ v (σ (Sum.inr i))) = 0 by simp_all exact b.map_eq_zero_of_eq _ hv fun hij' => hij (hij' ▸ rfl) /-- Like `MultilinearMap.domCoprod`, but ensures the result is also alternating. Note that this is usually defined (for instance, as used in Proposition 22.24 in [Gallier2011Notes]) over integer indices `ιa = Fin n` and `ιb = Fin m`, as $$ (f \wedge g)(u_1, \ldots, u_{m+n}) = \sum_{\operatorname{shuffle}(m, n)} \operatorname{sign}(\sigma) f(u_{\sigma(1)}, \ldots, u_{\sigma(m)}) g(u_{\sigma(m+1)}, \ldots, u_{\sigma(m+n)}), $$ where $\operatorname{shuffle}(m, n)$ consists of all permutations of $[1, m+n]$ such that $\sigma(1) < \cdots < \sigma(m)$ and $\sigma(m+1) < \cdots < \sigma(m+n)$. Here, we generalize this by replacing: * the product in the sum with a tensor product * the filtering of $[1, m+n]$ to shuffles with an isomorphic quotient * the additions in the subscripts of $\sigma$ with an index of type `Sum` The specialized version can be obtained by combining this definition with `finSumFinEquiv` and `LinearMap.mul'`. -/ @[simps] def domCoprod (a : Mᵢ [⋀^ιa]→ₗ[R'] N₁) (b : Mᵢ [⋀^ιb]→ₗ[R'] N₂) : Mᵢ [⋀^ιa ⊕ ιb]→ₗ[R'] (N₁ ⊗[R'] N₂) := { ∑ σ : Perm.ModSumCongr ιa ιb, domCoprod.summand a b σ with toFun := fun v => (⇑(∑ σ : Perm.ModSumCongr ιa ιb, domCoprod.summand a b σ)) v map_eq_zero_of_eq' := fun v i j hv hij => by rw [MultilinearMap.sum_apply] exact Finset.sum_involution (fun σ _ => Equiv.swap i j • σ) (fun σ _ => domCoprod.summand_add_swap_smul_eq_zero a b σ hv hij) (fun σ _ => mt <| domCoprod.summand_eq_zero_of_smul_invariant a b σ hv hij) (fun σ _ => Finset.mem_univ _) fun σ _ => Equiv.swap_smul_involutive i j σ } theorem domCoprod_coe (a : Mᵢ [⋀^ιa]→ₗ[R'] N₁) (b : Mᵢ [⋀^ιb]→ₗ[R'] N₂) : (↑(a.domCoprod b) : MultilinearMap R' (fun _ => Mᵢ) _) = ∑ σ : Perm.ModSumCongr ιa ιb, domCoprod.summand a b σ := MultilinearMap.ext fun _ => rfl /-- A more bundled version of `AlternatingMap.domCoprod` that maps `((ι₁ → N) → N₁) ⊗ ((ι₂ → N) → N₂)` to `(ι₁ ⊕ ι₂ → N) → N₁ ⊗ N₂`. -/ def domCoprod' : (Mᵢ [⋀^ιa]→ₗ[R'] N₁) ⊗[R'] (Mᵢ [⋀^ιb]→ₗ[R'] N₂) →ₗ[R'] (Mᵢ [⋀^ιa ⊕ ιb]→ₗ[R'] (N₁ ⊗[R'] N₂)) := TensorProduct.lift <| by refine LinearMap.mk₂ R' domCoprod (fun m₁ m₂ n => ?_) (fun c m n => ?_) (fun m n₁ n₂ => ?_) fun c m n => ?_ <;> · ext simp only [domCoprod_apply, add_apply, smul_apply, ← Finset.sum_add_distrib, Finset.smul_sum, MultilinearMap.sum_apply, domCoprod.summand] congr ext σ refine Quotient.inductionOn' σ fun σ => ?_ simp only [Quotient.liftOn'_mk'', coe_add, coe_smul, MultilinearMap.smul_apply, ← MultilinearMap.domCoprod'_apply] simp only [TensorProduct.add_tmul, ← TensorProduct.smul_tmul', TensorProduct.tmul_add, TensorProduct.tmul_smul, LinearMap.map_add, LinearMap.map_smul] first | rw [← smul_add] | rw [smul_comm] rfl @[simp] theorem domCoprod'_apply (a : Mᵢ [⋀^ιa]→ₗ[R'] N₁) (b : Mᵢ [⋀^ιb]→ₗ[R'] N₂) : domCoprod' (a ⊗ₜ[R'] b) = domCoprod a b := rfl end AlternatingMap open Equiv /-- A helper lemma for `MultilinearMap.domCoprod_alternization`. -/ theorem MultilinearMap.domCoprod_alternization_coe [DecidableEq ιa] [DecidableEq ιb] (a : MultilinearMap R' (fun _ : ιa => Mᵢ) N₁) (b : MultilinearMap R' (fun _ : ιb => Mᵢ) N₂) : MultilinearMap.domCoprod (MultilinearMap.alternatization a) (MultilinearMap.alternatization b) = ∑ σa : Perm ιa, ∑ σb : Perm ιb, Equiv.Perm.sign σa • Equiv.Perm.sign σb • MultilinearMap.domCoprod (a.domDomCongr σa) (b.domDomCongr σb) := by simp_rw [← MultilinearMap.domCoprod'_apply, MultilinearMap.alternatization_coe] simp_rw [TensorProduct.sum_tmul, TensorProduct.tmul_sum, _root_.map_sum, ← TensorProduct.smul_tmul', TensorProduct.tmul_smul] rfl open AlternatingMap open Perm in /-- Computing the `MultilinearMap.alternatization` of the `MultilinearMap.domCoprod` is the same as computing the `AlternatingMap.domCoprod` of the `MultilinearMap.alternatization`s. -/ theorem MultilinearMap.domCoprod_alternization [DecidableEq ιa] [DecidableEq ιb] (a : MultilinearMap R' (fun _ : ιa => Mᵢ) N₁) (b : MultilinearMap R' (fun _ : ιb => Mᵢ) N₂) : MultilinearMap.alternatization (MultilinearMap.domCoprod a b) = a.alternatization.domCoprod (MultilinearMap.alternatization b) := by apply coe_multilinearMap_injective rw [domCoprod_coe, MultilinearMap.alternatization_coe, Finset.sum_partition (QuotientGroup.leftRel (Perm.sumCongrHom ιa ιb).range)] congr 1 ext1 σ induction σ using Quotient.inductionOn' with | h σ => set f := sumCongrHom ιa ιb calc ∑ τ ∈ _, sign τ • domDomCongr τ (a.domCoprod b) = ∑ τ ∈ {τ | τ⁻¹ * σ ∈ f.range}, sign τ • domDomCongr τ (a.domCoprod b) := by simp [QuotientGroup.leftRel_apply, f] _ = ∑ τ ∈ {τ | τ⁻¹ ∈ f.range}, sign (σ * τ) • domDomCongr (σ * τ) (a.domCoprod b) := by conv_lhs => rw [← Finset.map_univ_equiv (Equiv.mulLeft σ), Finset.filter_map, Finset.sum_map] simp [Function.comp_def, -MonoidHom.mem_range] _ = ∑ τ, sign (σ * f τ) • domDomCongr (σ * f τ) (a.domCoprod b) := by simp_rw [f, Subgroup.inv_mem_iff, MonoidHom.mem_range, Finset.univ_filter_exists, Finset.sum_image sumCongrHom_injective.injOn] _ = ∑ τ : Perm ιa × Perm ιb, sign σ • (domDomCongrEquiv σ) (sign τ.1 • sign τ.2 • (domDomCongr τ.1 a).domCoprod (domDomCongr τ.2 b)) := by simp [f, domDomCongr_mul, domCoprod_domDomCongr_sumCongr, mul_smul] _ = domCoprod.summand (alternatization a) (alternatization b) (Quotient.mk'' σ) := by simp [domCoprod.summand_mk'', domCoprod_alternization_coe, ← domDomCongrEquiv_apply, Finset.smul_sum, ← Finset.sum_product'] /-- Taking the `MultilinearMap.alternatization` of the `MultilinearMap.domCoprod` of two `AlternatingMap`s gives a scaled version of the `AlternatingMap.coprod` of those maps. -/ theorem MultilinearMap.domCoprod_alternization_eq [DecidableEq ιa] [DecidableEq ιb] (a : Mᵢ [⋀^ιa]→ₗ[R'] N₁) (b : Mᵢ [⋀^ιb]→ₗ[R'] N₂) : MultilinearMap.alternatization (MultilinearMap.domCoprod a b : MultilinearMap R' (fun _ : ιa ⊕ ιb => Mᵢ) (N₁ ⊗ N₂)) = ((Fintype.card ιa).factorial * (Fintype.card ιb).factorial) • a.domCoprod b := by rw [MultilinearMap.domCoprod_alternization, coe_alternatization, coe_alternatization, mul_smul, ← AlternatingMap.domCoprod'_apply, ← AlternatingMap.domCoprod'_apply, ← TensorProduct.smul_tmul', TensorProduct.tmul_smul, LinearMap.map_smul_of_tower AlternatingMap.domCoprod', LinearMap.map_smul_of_tower AlternatingMap.domCoprod']
.lake/packages/mathlib/Mathlib/LinearAlgebra/Alternating/Curry.lean
import Mathlib.LinearAlgebra.Alternating.Basic import Mathlib.LinearAlgebra.Multilinear.Curry /-! # Currying alternating forms In this file we define `AlternatingMap.curryLeft` which interprets an alternating map in `n + 1` variables as a linear map in the 0th variable taking values in the alternating maps in `n` variables. -/ variable {R : Type*} {M M₂ N N₂ : Type*} [CommSemiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid N] [AddCommMonoid N₂] [Module R M] [Module R M₂] [Module R N] [Module R N₂] {n : ℕ} namespace AlternatingMap /-- Given an alternating map `f` in `n+1` variables, split the first variable to obtain a linear map into alternating maps in `n` variables, given by `x ↦ (m ↦ f (Matrix.vecCons x m))`. It can be thought of as a map $Hom(\bigwedge^{n+1} M, N) \to Hom(M, Hom(\bigwedge^n M, N))$. This is `MultilinearMap.curryLeft` for `AlternatingMap`. See also `AlternatingMap.curryLeftLinearMap`. -/ @[simps apply_toMultilinearMap] def curryLeft (f : M [⋀^Fin n.succ]→ₗ[R] N) : M →ₗ[R] M [⋀^Fin n]→ₗ[R] N where toFun m := { f.toMultilinearMap.curryLeft m with map_eq_zero_of_eq' v i j hv hij := f.map_eq_zero_of_eq _ (by simpa) ((Fin.succ_injective _).ne hij) } map_add' _ _ := ext fun _ => f.map_vecCons_add _ _ _ map_smul' _ _ := ext fun _ => f.map_vecCons_smul _ _ _ @[simp] theorem curryLeft_apply_apply (f : M [⋀^Fin n.succ]→ₗ[R] N) (x : M) (v : Fin n → M) : curryLeft f x v = f (Matrix.vecCons x v) := rfl @[simp] theorem curryLeft_zero : curryLeft (0 : M [⋀^Fin n.succ]→ₗ[R] N) = 0 := rfl @[simp] theorem curryLeft_add (f g : M [⋀^Fin n.succ]→ₗ[R] N) : curryLeft (f + g) = curryLeft f + curryLeft g := rfl @[simp] theorem curryLeft_smul (r : R) (f : M [⋀^Fin n.succ]→ₗ[R] N) : curryLeft (r • f) = r • curryLeft f := rfl /-- `AlternatingMap.curryLeft` as a `LinearMap`. This is a separate definition as dot notation does not work for this version. -/ @[simps] def curryLeftLinearMap : (M [⋀^Fin n.succ]→ₗ[R] N) →ₗ[R] M →ₗ[R] M [⋀^Fin n]→ₗ[R] N where toFun f := f.curryLeft map_add' := curryLeft_add map_smul' := curryLeft_smul /-- Currying with the same element twice gives the zero map. -/ @[simp] theorem curryLeft_same (f : M [⋀^Fin n.succ.succ]→ₗ[R] N) (m : M) : (f.curryLeft m).curryLeft m = 0 := ext fun _ => f.map_eq_zero_of_eq _ (by simp) Fin.zero_ne_one @[simp] theorem curryLeft_compAlternatingMap (g : N →ₗ[R] N₂) (f : M [⋀^Fin n.succ]→ₗ[R] N) (m : M) : (g.compAlternatingMap f).curryLeft m = g.compAlternatingMap (f.curryLeft m) := rfl @[simp] theorem curryLeft_compLinearMap (g : M₂ →ₗ[R] M) (f : M [⋀^Fin n.succ]→ₗ[R] N) (m : M₂) : (f.compLinearMap g).curryLeft m = (f.curryLeft (g m)).compLinearMap g := ext fun v ↦ congr_arg f <| funext fun i ↦ by cases i using Fin.cases <;> simp end AlternatingMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/Alternating/Basic.lean
import Mathlib.GroupTheory.Perm.Sign import Mathlib.LinearAlgebra.LinearIndependent.Defs import Mathlib.LinearAlgebra.Multilinear.Basis /-! # Alternating Maps We construct the bundled function `AlternatingMap`, which extends `MultilinearMap` with all the arguments of the same type. ## Main definitions * `AlternatingMap R M N ι` is the space of `R`-linear alternating maps from `ι → M` to `N`. * `f.map_eq_zero_of_eq` expresses that `f` is zero when two inputs are equal. * `f.map_swap` expresses that `f` is negated when two inputs are swapped. * `f.map_perm` expresses how `f` varies by a sign change under a permutation of its inputs. * An `AddCommMonoid`, `AddCommGroup`, and `Module` structure over `AlternatingMap`s that matches the definitions over `MultilinearMap`s. * `MultilinearMap.domDomCongr`, for permuting the elements within a family. * `MultilinearMap.alternatization`, which makes an alternating map out of a non-alternating one. * `AlternatingMap.curryLeft`, for binding the leftmost argument of an alternating map indexed by `Fin n.succ`. ## Implementation notes `AlternatingMap` is defined in terms of `map_eq_zero_of_eq`, as this is easier to work with than using `map_swap` as a definition, and does not require `Neg N`. `AlternatingMap`s are provided with a coercion to `MultilinearMap`, along with a set of `norm_cast` lemmas that act on the algebraic structure: * `AlternatingMap.coe_add` * `AlternatingMap.coe_zero` * `AlternatingMap.coe_sub` * `AlternatingMap.coe_neg` * `AlternatingMap.coe_smul` -/ -- semiring / add_comm_monoid variable {R : Type*} [Semiring R] variable {M : Type*} [AddCommMonoid M] [Module R M] variable {N : Type*} [AddCommMonoid N] [Module R N] variable {P : Type*} [AddCommMonoid P] [Module R P] -- semiring / add_comm_group variable {M' : Type*} [AddCommGroup M'] [Module R M'] variable {N' : Type*} [AddCommGroup N'] [Module R N'] variable {ι ι' ι'' : Type*} section variable (R M N ι) /-- An alternating map from `ι → M` to `N`, denoted `M [⋀^ι]→ₗ[R] N`, is a multilinear map that vanishes when two of its arguments are equal. -/ structure AlternatingMap extends MultilinearMap R (fun _ : ι => M) N where /-- The map is alternating: if `v` has two equal coordinates, then `f v = 0`. -/ map_eq_zero_of_eq' : ∀ (v : ι → M) (i j : ι), v i = v j → i ≠ j → toFun v = 0 @[inherit_doc] notation M " [⋀^" ι "]→ₗ[" R "] " N:100 => AlternatingMap R M N ι end /-- The multilinear map associated to an alternating map -/ add_decl_doc AlternatingMap.toMultilinearMap namespace AlternatingMap variable (f f' : M [⋀^ι]→ₗ[R] N) variable (g g₂ : M [⋀^ι]→ₗ[R] N') variable (g' : M' [⋀^ι]→ₗ[R] N') variable (v : ι → M) (v' : ι → M') open Function /-! Basic coercion simp lemmas, largely copied from `RingHom` and `MultilinearMap` -/ section Coercions instance instFunLike : FunLike (M [⋀^ι]→ₗ[R] N) (ι → M) N where coe f := f.toFun coe_injective' f g h := by rcases f with ⟨⟨_, _, _⟩, _⟩ rcases g with ⟨⟨_, _, _⟩, _⟩ congr initialize_simps_projections AlternatingMap (toFun → apply) @[simp] theorem toFun_eq_coe : f.toFun = f := rfl @[simp] theorem coe_mk (f : MultilinearMap R (fun _ : ι => M) N) (h) : ⇑(⟨f, h⟩ : M [⋀^ι]→ₗ[R] N) = f := rfl protected theorem congr_fun {f g : M [⋀^ι]→ₗ[R] N} (h : f = g) (x : ι → M) : f x = g x := congr_arg (fun h : M [⋀^ι]→ₗ[R] N => h x) h protected theorem congr_arg (f : M [⋀^ι]→ₗ[R] N) {x y : ι → M} (h : x = y) : f x = f y := congr_arg (fun x : ι → M => f x) h theorem coe_injective : Injective ((↑) : M [⋀^ι]→ₗ[R] N → (ι → M) → N) := DFunLike.coe_injective @[norm_cast] theorem coe_inj {f g : M [⋀^ι]→ₗ[R] N} : (f : (ι → M) → N) = g ↔ f = g := coe_injective.eq_iff @[ext] theorem ext {f f' : M [⋀^ι]→ₗ[R] N} (H : ∀ x, f x = f' x) : f = f' := DFunLike.ext _ _ H attribute [coe] AlternatingMap.toMultilinearMap instance instCoe : Coe (M [⋀^ι]→ₗ[R] N) (MultilinearMap R (fun _ : ι => M) N) := ⟨fun x => x.toMultilinearMap⟩ @[simp, norm_cast] theorem coe_multilinearMap : ⇑(f : MultilinearMap R (fun _ : ι => M) N) = f := rfl theorem coe_multilinearMap_injective : Function.Injective ((↑) : M [⋀^ι]→ₗ[R] N → MultilinearMap R (fun _ : ι => M) N) := fun _ _ h => ext <| MultilinearMap.congr_fun h theorem coe_multilinearMap_mk (f : (ι → M) → N) (h₁ h₂ h₃) : ((⟨⟨f, h₁, h₂⟩, h₃⟩ : M [⋀^ι]→ₗ[R] N) : MultilinearMap R (fun _ : ι => M) N) = ⟨f, @h₁, @h₂⟩ := by simp end Coercions /-! ### Simp-normal forms of the structure fields These are expressed in terms of `⇑f` instead of `f.toFun`. -/ @[simp] theorem map_update_add [DecidableEq ι] (i : ι) (x y : M) : f (update v i (x + y)) = f (update v i x) + f (update v i y) := f.map_update_add' v i x y @[simp] theorem map_update_sub [DecidableEq ι] (i : ι) (x y : M') : g' (update v' i (x - y)) = g' (update v' i x) - g' (update v' i y) := g'.toMultilinearMap.map_update_sub v' i x y @[simp] theorem map_update_neg [DecidableEq ι] (i : ι) (x : M') : g' (update v' i (-x)) = -g' (update v' i x) := g'.toMultilinearMap.map_update_neg v' i x @[simp] theorem map_update_smul [DecidableEq ι] (i : ι) (r : R) (x : M) : f (update v i (r • x)) = r • f (update v i x) := f.map_update_smul' v i r x -- Cannot be @[simp] because `i` and `j` cannot be inferred by `simp`. theorem map_eq_zero_of_eq (v : ι → M) {i j : ι} (h : v i = v j) (hij : i ≠ j) : f v = 0 := f.map_eq_zero_of_eq' v i j h hij theorem map_coord_zero {m : ι → M} (i : ι) (h : m i = 0) : f m = 0 := f.toMultilinearMap.map_coord_zero i h @[simp] theorem map_update_zero [DecidableEq ι] (m : ι → M) (i : ι) : f (update m i 0) = 0 := f.toMultilinearMap.map_update_zero m i @[simp] theorem map_zero [Nonempty ι] : f 0 = 0 := f.toMultilinearMap.map_zero theorem map_eq_zero_of_not_injective (v : ι → M) (hv : ¬Function.Injective v) : f v = 0 := by rw [Function.Injective] at hv push_neg at hv rcases hv with ⟨i₁, i₂, heq, hne⟩ exact f.map_eq_zero_of_eq v heq hne /-! ### Algebraic structure inherited from `MultilinearMap` `AlternatingMap` carries the same `AddCommMonoid`, `AddCommGroup`, and `Module` structure as `MultilinearMap` -/ section SMul variable {S : Type*} [Monoid S] [DistribMulAction S N] [SMulCommClass R S N] instance instSMul : SMul S (M [⋀^ι]→ₗ[R] N) := ⟨fun c f => { c • (f : MultilinearMap R (fun _ : ι => M) N) with map_eq_zero_of_eq' := fun v i j h hij => by simp [f.map_eq_zero_of_eq v h hij] }⟩ @[simp] theorem smul_apply (c : S) (m : ι → M) : (c • f) m = c • f m := rfl @[norm_cast] theorem coe_smul (c : S) : ↑(c • f) = c • (f : MultilinearMap R (fun _ : ι => M) N) := rfl theorem coeFn_smul (c : S) (f : M [⋀^ι]→ₗ[R] N) : ⇑(c • f) = c • ⇑f := rfl instance instSMulCommClass {T : Type*} [Monoid T] [DistribMulAction T N] [SMulCommClass R T N] [SMulCommClass S T N] : SMulCommClass S T (M [⋀^ι]→ₗ[R] N) where smul_comm _ _ _ := ext fun _ ↦ smul_comm .. instance instIsCentralScalar [DistribMulAction Sᵐᵒᵖ N] [IsCentralScalar S N] : IsCentralScalar S (M [⋀^ι]→ₗ[R] N) := ⟨fun _ _ => ext fun _ => op_smul_eq_smul _ _⟩ end SMul /-- The Cartesian product of two alternating maps, as an alternating map. -/ @[simps!] def prod (f : M [⋀^ι]→ₗ[R] N) (g : M [⋀^ι]→ₗ[R] P) : M [⋀^ι]→ₗ[R] (N × P) := { f.toMultilinearMap.prod g.toMultilinearMap with map_eq_zero_of_eq' := fun _ _ _ h hne => Prod.ext (f.map_eq_zero_of_eq _ h hne) (g.map_eq_zero_of_eq _ h hne) } @[simp] theorem coe_prod (f : M [⋀^ι]→ₗ[R] N) (g : M [⋀^ι]→ₗ[R] P) : (f.prod g : MultilinearMap R (fun _ : ι => M) (N × P)) = MultilinearMap.prod f g := rfl /-- Combine a family of alternating maps with the same domain and codomains `N i` into an alternating map taking values in the space of functions `Π i, N i`. -/ @[simps!] def pi {ι' : Type*} {N : ι' → Type*} [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)] (f : ∀ i, M [⋀^ι]→ₗ[R] N i) : M [⋀^ι]→ₗ[R] (∀ i, N i) := { MultilinearMap.pi fun a => (f a).toMultilinearMap with map_eq_zero_of_eq' := fun _ _ _ h hne => funext fun a => (f a).map_eq_zero_of_eq _ h hne } @[simp] theorem coe_pi {ι' : Type*} {N : ι' → Type*} [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)] (f : ∀ i, M [⋀^ι]→ₗ[R] N i) : (pi f : MultilinearMap R (fun _ : ι => M) (∀ i, N i)) = MultilinearMap.pi fun a => f a := rfl /-- Given an alternating `R`-multilinear map `f` taking values in `R`, `f.smul_right z` is the map sending `m` to `f m • z`. -/ @[simps!] def smulRight {R M₁ M₂ ι : Type*} [CommSemiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] (f : M₁ [⋀^ι]→ₗ[R] R) (z : M₂) : M₁ [⋀^ι]→ₗ[R] M₂ := { f.toMultilinearMap.smulRight z with map_eq_zero_of_eq' := fun v i j h hne => by simp [f.map_eq_zero_of_eq v h hne] } @[simp] theorem coe_smulRight {R M₁ M₂ ι : Type*} [CommSemiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] (f : M₁ [⋀^ι]→ₗ[R] R) (z : M₂) : (f.smulRight z : MultilinearMap R (fun _ : ι => M₁) M₂) = MultilinearMap.smulRight f z := rfl instance instAdd : Add (M [⋀^ι]→ₗ[R] N) where add a b := { (a + b : MultilinearMap R (fun _ : ι => M) N) with map_eq_zero_of_eq' := fun v i j h hij => by simp [a.map_eq_zero_of_eq v h hij, b.map_eq_zero_of_eq v h hij] } @[simp] theorem add_apply : (f + f') v = f v + f' v := rfl @[norm_cast] theorem coe_add : (↑(f + f') : MultilinearMap R (fun _ : ι => M) N) = f + f' := rfl instance instZero : Zero (M [⋀^ι]→ₗ[R] N) := ⟨{ (0 : MultilinearMap R (fun _ : ι => M) N) with map_eq_zero_of_eq' := fun _ _ _ _ _ => by simp }⟩ @[simp] theorem zero_apply : (0 : M [⋀^ι]→ₗ[R] N) v = 0 := rfl @[norm_cast] theorem coe_zero : ((0 : M [⋀^ι]→ₗ[R] N) : MultilinearMap R (fun _ : ι => M) N) = 0 := rfl @[simp] theorem mk_zero : mk (0 : MultilinearMap R (fun _ : ι ↦ M) N) (0 : M [⋀^ι]→ₗ[R] N).2 = 0 := rfl instance instInhabited : Inhabited (M [⋀^ι]→ₗ[R] N) := ⟨0⟩ instance instAddCommMonoid : AddCommMonoid (M [⋀^ι]→ₗ[R] N) := fast_instance% coe_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => coeFn_smul _ _ instance instNeg : Neg (M [⋀^ι]→ₗ[R] N') := ⟨fun f => { -(f : MultilinearMap R (fun _ : ι => M) N') with map_eq_zero_of_eq' := fun v i j h hij => by simp [f.map_eq_zero_of_eq v h hij] }⟩ @[simp] theorem neg_apply (m : ι → M) : (-g) m = -g m := rfl @[norm_cast] theorem coe_neg : ((-g : M [⋀^ι]→ₗ[R] N') : MultilinearMap R (fun _ : ι => M) N') = -g := rfl instance instSub : Sub (M [⋀^ι]→ₗ[R] N') := ⟨fun f g => { (f - g : MultilinearMap R (fun _ : ι => M) N') with map_eq_zero_of_eq' := fun v i j h hij => by simp [f.map_eq_zero_of_eq v h hij, g.map_eq_zero_of_eq v h hij] }⟩ @[simp] theorem sub_apply (m : ι → M) : (g - g₂) m = g m - g₂ m := rfl @[norm_cast] theorem coe_sub : (↑(g - g₂) : MultilinearMap R (fun _ : ι => M) N') = g - g₂ := rfl instance instAddCommGroup : AddCommGroup (M [⋀^ι]→ₗ[R] N') := fast_instance% coe_injective.addCommGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => coeFn_smul _ _) fun _ _ => coeFn_smul _ _ section DistribMulAction variable {S : Type*} [Monoid S] [DistribMulAction S N] [SMulCommClass R S N] instance instDistribMulAction : DistribMulAction S (M [⋀^ι]→ₗ[R] N) where one_smul _ := ext fun _ => one_smul _ _ mul_smul _ _ _ := ext fun _ => mul_smul _ _ _ smul_zero _ := ext fun _ => smul_zero _ smul_add _ _ _ := ext fun _ => smul_add _ _ _ end DistribMulAction section Module variable {S : Type*} [Semiring S] [Module S N] [SMulCommClass R S N] /-- The space of multilinear maps over an algebra over `R` is a module over `R`, for the pointwise addition and scalar multiplication. -/ instance instModule : Module S (M [⋀^ι]→ₗ[R] N) where add_smul _ _ _ := ext fun _ => add_smul _ _ _ zero_smul _ := ext fun _ => zero_smul _ _ instance instNoZeroSMulDivisors [NoZeroSMulDivisors S N] : NoZeroSMulDivisors S (M [⋀^ι]→ₗ[R] N) := coe_injective.noZeroSMulDivisors _ rfl coeFn_smul /-- Embedding of alternating maps into multilinear maps as a linear map. -/ @[simps] def toMultilinearMapLM : (M [⋀^ι]→ₗ[R] N) →ₗ[S] MultilinearMap R (fun _ : ι ↦ M) N where toFun := toMultilinearMap map_add' _ _ := rfl map_smul' _ _ := rfl end Module section variable (R M N) /-- The natural equivalence between linear maps from `M` to `N` and `1`-multilinear alternating maps from `M` to `N`. -/ @[simps!] def ofSubsingleton [Subsingleton ι] (i : ι) : (M →ₗ[R] N) ≃ (M [⋀^ι]→ₗ[R] N) where toFun f := ⟨MultilinearMap.ofSubsingleton R M N i f, fun _ _ _ _ ↦ absurd (Subsingleton.elim _ _)⟩ invFun f := (MultilinearMap.ofSubsingleton R M N i).symm f right_inv _ := coe_multilinearMap_injective <| (MultilinearMap.ofSubsingleton R M N i).apply_symm_apply _ variable (ι) {N} /-- The constant map is alternating when `ι` is empty. -/ @[simps -fullyApplied] def constOfIsEmpty [IsEmpty ι] (m : N) : M [⋀^ι]→ₗ[R] N := { MultilinearMap.constOfIsEmpty R _ m with toFun := Function.const _ m map_eq_zero_of_eq' := fun _ => isEmptyElim } end /-- Restrict the codomain of an alternating map to a submodule. -/ @[simps] def codRestrict (f : M [⋀^ι]→ₗ[R] N) (p : Submodule R N) (h : ∀ v, f v ∈ p) : M [⋀^ι]→ₗ[R] p := { f.toMultilinearMap.codRestrict p h with toFun := fun v => ⟨f v, h v⟩ map_eq_zero_of_eq' := fun _ _ _ hv hij => Subtype.ext <| map_eq_zero_of_eq _ _ hv hij } end AlternatingMap /-! ### Composition with linear maps -/ namespace LinearMap variable {S : Type*} {N₂ : Type*} [AddCommMonoid N₂] [Module R N₂] /-- Composing an alternating map with a linear map on the left gives again an alternating map. -/ def compAlternatingMap (g : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N) : M [⋀^ι]→ₗ[R] N₂ where __ := g.compMultilinearMap (f : MultilinearMap R (fun _ : ι => M) N) map_eq_zero_of_eq' v i j h hij := by simp [f.map_eq_zero_of_eq v h hij] @[simp] theorem coe_compAlternatingMap (g : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N) : ⇑(g.compAlternatingMap f) = g ∘ f := rfl @[simp] theorem compAlternatingMap_apply (g : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N) (m : ι → M) : g.compAlternatingMap f m = g (f m) := rfl @[simp] theorem compAlternatingMap_zero (g : N →ₗ[R] N₂) : g.compAlternatingMap (0 : M [⋀^ι]→ₗ[R] N) = 0 := AlternatingMap.ext fun _ => map_zero g @[simp] theorem zero_compAlternatingMap (f : M [⋀^ι]→ₗ[R] N) : (0 : N →ₗ[R] N₂).compAlternatingMap f = 0 := rfl @[simp] theorem compAlternatingMap_add (g : N →ₗ[R] N₂) (f₁ f₂ : M [⋀^ι]→ₗ[R] N) : g.compAlternatingMap (f₁ + f₂) = g.compAlternatingMap f₁ + g.compAlternatingMap f₂ := AlternatingMap.ext fun _ => map_add g _ _ @[simp] theorem add_compAlternatingMap (g₁ g₂ : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N) : (g₁ + g₂).compAlternatingMap f = g₁.compAlternatingMap f + g₂.compAlternatingMap f := rfl @[simp] theorem compAlternatingMap_smul [Monoid S] [DistribMulAction S N] [DistribMulAction S N₂] [SMulCommClass R S N] [SMulCommClass R S N₂] [CompatibleSMul N N₂ S R] (g : N →ₗ[R] N₂) (s : S) (f : M [⋀^ι]→ₗ[R] N) : g.compAlternatingMap (s • f) = s • g.compAlternatingMap f := AlternatingMap.ext fun _ => g.map_smul_of_tower _ _ @[simp] theorem smul_compAlternatingMap [Monoid S] [DistribMulAction S N₂] [SMulCommClass R S N₂] (g : N →ₗ[R] N₂) (s : S) (f : M [⋀^ι]→ₗ[R] N) : (s • g).compAlternatingMap f = s • g.compAlternatingMap f := rfl variable (S) in /-- `LinearMap.compAlternatingMap` as an `S`-linear map. -/ @[simps] def compAlternatingMapₗ [Semiring S] [Module S N] [Module S N₂] [SMulCommClass R S N] [SMulCommClass R S N₂] [LinearMap.CompatibleSMul N N₂ S R] (g : N →ₗ[R] N₂) : (M [⋀^ι]→ₗ[R] N) →ₗ[S] (M [⋀^ι]→ₗ[R] N₂) where toFun := g.compAlternatingMap map_add' := g.compAlternatingMap_add map_smul' := g.compAlternatingMap_smul theorem smulRight_eq_comp {R M₁ M₂ ι : Type*} [CommSemiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] (f : M₁ [⋀^ι]→ₗ[R] R) (z : M₂) : f.smulRight z = (LinearMap.id.smulRight z).compAlternatingMap f := rfl @[simp] theorem subtype_compAlternatingMap_codRestrict (f : M [⋀^ι]→ₗ[R] N) (p : Submodule R N) (h) : p.subtype.compAlternatingMap (f.codRestrict p h) = f := AlternatingMap.ext fun _ => rfl @[simp] theorem compAlternatingMap_codRestrict (g : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N) (p : Submodule R N₂) (h) : (g.codRestrict p h).compAlternatingMap f = (g.compAlternatingMap f).codRestrict p fun v => h (f v) := AlternatingMap.ext fun _ => rfl end LinearMap namespace AlternatingMap variable {M₂ : Type*} [AddCommMonoid M₂] [Module R M₂] variable {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] /-- Composing an alternating map with the same linear map on each argument gives again an alternating map. -/ def compLinearMap (f : M [⋀^ι]→ₗ[R] N) (g : M₂ →ₗ[R] M) : M₂ [⋀^ι]→ₗ[R] N := { (f : MultilinearMap R (fun _ : ι => M) N).compLinearMap fun _ => g with map_eq_zero_of_eq' := fun _ _ _ h hij => f.map_eq_zero_of_eq _ (LinearMap.congr_arg h) hij } theorem coe_compLinearMap (f : M [⋀^ι]→ₗ[R] N) (g : M₂ →ₗ[R] M) : ⇑(f.compLinearMap g) = f ∘ (g ∘ ·) := rfl @[simp] theorem compLinearMap_apply (f : M [⋀^ι]→ₗ[R] N) (g : M₂ →ₗ[R] M) (v : ι → M₂) : f.compLinearMap g v = f fun i => g (v i) := rfl /-- Composing an alternating map twice with the same linear map in each argument is the same as composing with their composition. -/ theorem compLinearMap_assoc (f : M [⋀^ι]→ₗ[R] N) (g₁ : M₂ →ₗ[R] M) (g₂ : M₃ →ₗ[R] M₂) : (f.compLinearMap g₁).compLinearMap g₂ = f.compLinearMap (g₁ ∘ₗ g₂) := rfl @[simp] theorem zero_compLinearMap (g : M₂ →ₗ[R] M) : (0 : M [⋀^ι]→ₗ[R] N).compLinearMap g = 0 := by ext simp only [compLinearMap_apply, zero_apply] @[simp] theorem add_compLinearMap (f₁ f₂ : M [⋀^ι]→ₗ[R] N) (g : M₂ →ₗ[R] M) : (f₁ + f₂).compLinearMap g = f₁.compLinearMap g + f₂.compLinearMap g := by ext simp only [compLinearMap_apply, add_apply] @[simp] theorem compLinearMap_zero [Nonempty ι] (f : M [⋀^ι]→ₗ[R] N) : f.compLinearMap (0 : M₂ →ₗ[R] M) = 0 := by ext simp_rw [compLinearMap_apply, LinearMap.zero_apply, ← Pi.zero_def, map_zero, zero_apply] /-- Composing an alternating map with the identity linear map in each argument. -/ @[simp] theorem compLinearMap_id (f : M [⋀^ι]→ₗ[R] N) : f.compLinearMap LinearMap.id = f := ext fun _ => rfl /-- Composing with a surjective linear map is injective. -/ theorem compLinearMap_injective (f : M₂ →ₗ[R] M) (hf : Function.Surjective f) : Function.Injective fun g : M [⋀^ι]→ₗ[R] N => g.compLinearMap f := fun g₁ g₂ h => ext fun x => by simpa [Function.surjInv_eq hf] using AlternatingMap.ext_iff.mp h (Function.surjInv hf ∘ x) theorem compLinearMap_inj (f : M₂ →ₗ[R] M) (hf : Function.Surjective f) (g₁ g₂ : M [⋀^ι]→ₗ[R] N) : g₁.compLinearMap f = g₂.compLinearMap f ↔ g₁ = g₂ := (compLinearMap_injective _ hf).eq_iff /-- If two `R`-alternating maps from `R` are equal on 1, then they are equal. This is the alternating version of `LinearMap.ext_ring`. -/ @[ext] theorem ext_ring {R} [CommSemiring R] [Module R N] [Finite ι] ⦃f g : R [⋀^ι]→ₗ[R] N⦄ (h : f (fun _ ↦ 1) = g (fun _ ↦ 1)) : f = g := coe_multilinearMap_injective <| MultilinearMap.ext_ring h /-- The only `R`-alternating map from two or more copies of `R` is the zero map. -/ instance uniqueOfCommRing {R} [CommSemiring R] [Module R N] [Finite ι] [Nontrivial ι] : Unique (R [⋀^ι]→ₗ[R] N) where uniq f := let ⟨_, _, hij⟩ := exists_pair_ne ι; ext_ring <| f.map_eq_zero_of_eq _ rfl hij section DomLcongr variable (ι R N) variable (S : Type*) [Semiring S] [Module S N] [SMulCommClass R S N] /-- Construct a linear equivalence between maps from a linear equivalence between domains. This is `AlternatingMap.compLinearMap` as an isomorphism, and the alternating version of `LinearEquiv.multilinearMapCongrLeft`. It could also have been called `LinearEquiv.alternatingMapCongrLeft`. -/ @[simps apply] def domLCongr (e : M ≃ₗ[R] M₂) : M [⋀^ι]→ₗ[R] N ≃ₗ[S] (M₂ [⋀^ι]→ₗ[R] N) where toFun f := f.compLinearMap e.symm invFun g := g.compLinearMap e map_add' _ _ := rfl map_smul' _ _ := rfl left_inv f := AlternatingMap.ext fun _ => f.congr_arg <| funext fun _ => e.symm_apply_apply _ right_inv f := AlternatingMap.ext fun _ => f.congr_arg <| funext fun _ => e.apply_symm_apply _ @[simp] theorem domLCongr_refl : domLCongr R N ι S (LinearEquiv.refl R M) = LinearEquiv.refl S _ := LinearEquiv.ext fun _ => AlternatingMap.ext fun _ => rfl @[simp] theorem domLCongr_symm (e : M ≃ₗ[R] M₂) : (domLCongr R N ι S e).symm = domLCongr R N ι S e.symm := rfl theorem domLCongr_trans (e : M ≃ₗ[R] M₂) (f : M₂ ≃ₗ[R] M₃) : (domLCongr R N ι S e).trans (domLCongr R N ι S f) = domLCongr R N ι S (e.trans f) := rfl end DomLcongr /-- Composing an alternating map with the same linear equiv on each argument gives the zero map if and only if the alternating map is the zero map. -/ @[simp] theorem compLinearEquiv_eq_zero_iff (f : M [⋀^ι]→ₗ[R] N) (g : M₂ ≃ₗ[R] M) : f.compLinearMap (g : M₂ →ₗ[R] M) = 0 ↔ f = 0 := (domLCongr R N ι ℕ g.symm).map_eq_zero_iff variable (f f' : M [⋀^ι]→ₗ[R] N) variable (g g₂ : M [⋀^ι]→ₗ[R] N') variable (g' : M' [⋀^ι]→ₗ[R] N') variable (v : ι → M) (v' : ι → M') open Function /-! ### Other lemmas from `MultilinearMap` -/ section theorem map_update_sum {α : Type*} [DecidableEq ι] (t : Finset α) (i : ι) (g : α → M) (m : ι → M) : f (update m i (∑ a ∈ t, g a)) = ∑ a ∈ t, f (update m i (g a)) := f.toMultilinearMap.map_update_sum t i g m end /-! ### Theorems specific to alternating maps Various properties of reordered and repeated inputs which follow from `AlternatingMap.map_eq_zero_of_eq`. -/ theorem map_update_self [DecidableEq ι] {i j : ι} (hij : i ≠ j) : f (Function.update v i (v j)) = 0 := f.map_eq_zero_of_eq _ (by rw [Function.update_self, Function.update_of_ne hij.symm]) hij theorem map_update_update [DecidableEq ι] {i j : ι} (hij : i ≠ j) (m : M) : f (Function.update (Function.update v i m) j m) = 0 := f.map_eq_zero_of_eq _ (by rw [Function.update_self, Function.update_of_ne hij, Function.update_self]) hij theorem map_swap_add [DecidableEq ι] {i j : ι} (hij : i ≠ j) : f (v ∘ Equiv.swap i j) + f v = 0 := by rw [Equiv.comp_swap_eq_update] convert f.map_update_update v hij (v i + v j) simp [f.map_update_self _ hij, f.map_update_self _ hij.symm, Function.update_comm hij (v i + v j) (v _) v, Function.update_comm hij.symm (v i) (v i) v] theorem map_add_swap [DecidableEq ι] {i j : ι} (hij : i ≠ j) : f v + f (v ∘ Equiv.swap i j) = 0 := by rw [add_comm] exact f.map_swap_add v hij theorem map_swap [DecidableEq ι] {i j : ι} (hij : i ≠ j) : g (v ∘ Equiv.swap i j) = -g v := eq_neg_of_add_eq_zero_left <| g.map_swap_add v hij theorem map_perm [DecidableEq ι] [Fintype ι] (v : ι → M) (σ : Equiv.Perm ι) : g (v ∘ σ) = Equiv.Perm.sign σ • g v := by induction σ using Equiv.Perm.swap_induction_on' with | one => simp | mul_swap s x y hxy hI => simp_all [← Function.comp_assoc, g.map_swap] theorem map_congr_perm [DecidableEq ι] [Fintype ι] (σ : Equiv.Perm ι) : g v = Equiv.Perm.sign σ • g (v ∘ σ) := by rw [g.map_perm, smul_smul] simp section DomDomCongr /-- Transfer the arguments to a map along an equivalence between argument indices. This is the alternating version of `MultilinearMap.domDomCongr`. -/ @[simps] def domDomCongr (σ : ι ≃ ι') (f : M [⋀^ι]→ₗ[R] N) : M [⋀^ι']→ₗ[R] N := { f.toMultilinearMap.domDomCongr σ with toFun := fun v => f (v ∘ σ) map_eq_zero_of_eq' := fun v i j hv hij => f.map_eq_zero_of_eq (v ∘ σ) (i := σ.symm i) (j := σ.symm j) (by simpa using hv) (σ.symm.injective.ne hij) } @[simp] theorem domDomCongr_refl (f : M [⋀^ι]→ₗ[R] N) : f.domDomCongr (Equiv.refl ι) = f := rfl theorem domDomCongr_trans (σ₁ : ι ≃ ι') (σ₂ : ι' ≃ ι'') (f : M [⋀^ι]→ₗ[R] N) : f.domDomCongr (σ₁.trans σ₂) = (f.domDomCongr σ₁).domDomCongr σ₂ := rfl @[simp] theorem domDomCongr_zero (σ : ι ≃ ι') : (0 : M [⋀^ι]→ₗ[R] N).domDomCongr σ = 0 := rfl @[simp] theorem domDomCongr_add (σ : ι ≃ ι') (f g : M [⋀^ι]→ₗ[R] N) : (f + g).domDomCongr σ = f.domDomCongr σ + g.domDomCongr σ := rfl @[simp] theorem domDomCongr_smul {S : Type*} [Monoid S] [DistribMulAction S N] [SMulCommClass R S N] (σ : ι ≃ ι') (c : S) (f : M [⋀^ι]→ₗ[R] N) : (c • f).domDomCongr σ = c • f.domDomCongr σ := rfl /-- `AlternatingMap.domDomCongr` as an equivalence. This is declared separately because it does not work with dot notation. -/ @[simps apply symm_apply] def domDomCongrEquiv (σ : ι ≃ ι') : M [⋀^ι]→ₗ[R] N ≃+ M [⋀^ι']→ₗ[R] N where toFun := domDomCongr σ invFun := domDomCongr σ.symm left_inv f := by ext simp [Function.comp_def] right_inv m := by ext simp [Function.comp_def] map_add' := domDomCongr_add σ section DomDomLcongr variable (S : Type*) [Semiring S] [Module S N] [SMulCommClass R S N] /-- `AlternatingMap.domDomCongr` as a linear equivalence. -/ @[simps apply symm_apply] def domDomCongrₗ (σ : ι ≃ ι') : M [⋀^ι]→ₗ[R] N ≃ₗ[S] M [⋀^ι']→ₗ[R] N where toFun := domDomCongr σ invFun := domDomCongr σ.symm left_inv f := by ext; simp [Function.comp_def] right_inv m := by ext; simp [Function.comp_def] map_add' := domDomCongr_add σ map_smul' := domDomCongr_smul σ @[simp] theorem domDomCongrₗ_refl : (domDomCongrₗ S (Equiv.refl ι) : M [⋀^ι]→ₗ[R] N ≃ₗ[S] M [⋀^ι]→ₗ[R] N) = LinearEquiv.refl _ _ := rfl @[simp] theorem domDomCongrₗ_toAddEquiv (σ : ι ≃ ι') : (↑(domDomCongrₗ S σ : M [⋀^ι]→ₗ[R] N ≃ₗ[S] _) : M [⋀^ι]→ₗ[R] N ≃+ _) = domDomCongrEquiv σ := rfl end DomDomLcongr /-- The results of applying `domDomCongr` to two maps are equal if and only if those maps are. -/ @[simp] theorem domDomCongr_eq_iff (σ : ι ≃ ι') (f g : M [⋀^ι]→ₗ[R] N) : f.domDomCongr σ = g.domDomCongr σ ↔ f = g := (domDomCongrEquiv σ : _ ≃+ M [⋀^ι']→ₗ[R] N).apply_eq_iff_eq @[simp] theorem domDomCongr_eq_zero_iff (σ : ι ≃ ι') (f : M [⋀^ι]→ₗ[R] N) : f.domDomCongr σ = 0 ↔ f = 0 := (domDomCongrEquiv σ : M [⋀^ι]→ₗ[R] N ≃+ M [⋀^ι']→ₗ[R] N).map_eq_zero_iff theorem domDomCongr_perm [Fintype ι] [DecidableEq ι] (σ : Equiv.Perm ι) : g.domDomCongr σ = Equiv.Perm.sign σ • g := AlternatingMap.ext fun v => g.map_perm v σ @[norm_cast] theorem coe_domDomCongr (σ : ι ≃ ι') : ↑(f.domDomCongr σ) = (f : MultilinearMap R (fun _ : ι => M) N).domDomCongr σ := MultilinearMap.ext fun _ => rfl end DomDomCongr /-- If the arguments are linearly dependent then the result is `0`. -/ theorem map_linearDependent {K : Type*} [Ring K] {M : Type*} [AddCommGroup M] [Module K M] {N : Type*} [AddCommGroup N] [Module K N] [NoZeroSMulDivisors K N] (f : M [⋀^ι]→ₗ[K] N) (v : ι → M) (h : ¬LinearIndependent K v) : f v = 0 := by obtain ⟨s, g, h, i, hi, hz⟩ := not_linearIndependent_iff.mp h letI := Classical.decEq ι suffices f (update v i (g i • v i)) = 0 by rw [f.map_update_smul, Function.update_eq_self, smul_eq_zero] at this exact Or.resolve_left this hz rw [← Finset.insert_erase hi, Finset.sum_insert (s.notMem_erase i), add_eq_zero_iff_eq_neg] at h rw [h, f.map_update_neg, f.map_update_sum, neg_eq_zero] apply Finset.sum_eq_zero intro j hj obtain ⟨hij, _⟩ := Finset.mem_erase.mp hj rw [f.map_update_smul, f.map_update_self _ hij.symm, smul_zero] section Fin open Fin /-- A version of `MultilinearMap.cons_add` for `AlternatingMap`. -/ theorem map_vecCons_add {n : ℕ} (f : M [⋀^Fin n.succ]→ₗ[R] N) (m : Fin n → M) (x y : M) : f (Matrix.vecCons (x + y) m) = f (Matrix.vecCons x m) + f (Matrix.vecCons y m) := f.toMultilinearMap.cons_add _ _ _ /-- A version of `MultilinearMap.cons_smul` for `AlternatingMap`. -/ theorem map_vecCons_smul {n : ℕ} (f : M [⋀^Fin n.succ]→ₗ[R] N) (m : Fin n → M) (c : R) (x : M) : f (Matrix.vecCons (c • x) m) = c • f (Matrix.vecCons x m) := f.toMultilinearMap.cons_smul _ _ _ end Fin end AlternatingMap namespace MultilinearMap open Equiv variable [Fintype ι] [DecidableEq ι] private theorem alternization_map_eq_zero_of_eq_aux (m : MultilinearMap R (fun _ : ι => M) N') (v : ι → M) (i j : ι) (i_ne_j : i ≠ j) (hv : v i = v j) : (∑ σ : Perm ι, Equiv.Perm.sign σ • m.domDomCongr σ) v = 0 := by rw [sum_apply] exact Finset.sum_involution (fun σ _ => swap i j * σ) (fun σ _ => by simp [Perm.sign_swap i_ne_j, apply_swap_eq_self hv]) (fun σ _ _ => (not_congr swap_mul_eq_iff).mpr i_ne_j) (fun σ _ => Finset.mem_univ _) fun σ _ => swap_mul_involutive i j σ /-- Produce an `AlternatingMap` out of a `MultilinearMap`, by summing over all argument permutations. -/ def alternatization : MultilinearMap R (fun _ : ι => M) N' →+ M [⋀^ι]→ₗ[R] N' where toFun m := { ∑ σ : Perm ι, Equiv.Perm.sign σ • m.domDomCongr σ with toFun := ⇑(∑ σ : Perm ι, Equiv.Perm.sign σ • m.domDomCongr σ) map_eq_zero_of_eq' := fun v i j hvij hij => alternization_map_eq_zero_of_eq_aux m v i j hij hvij } map_add' a b := by ext simp only [mk_coe, AlternatingMap.coe_mk, sum_apply, smul_apply, domDomCongr_apply, add_apply, smul_add, Finset.sum_add_distrib, AlternatingMap.add_apply] map_zero' := by ext simp only [mk_coe, AlternatingMap.coe_mk, sum_apply, smul_apply, domDomCongr_apply, zero_apply, smul_zero, Finset.sum_const_zero, AlternatingMap.zero_apply] theorem alternatization_def (m : MultilinearMap R (fun _ : ι => M) N') : ⇑(alternatization m) = (∑ σ : Perm ι, Equiv.Perm.sign σ • m.domDomCongr σ :) := rfl theorem alternatization_coe (m : MultilinearMap R (fun _ : ι => M) N') : ↑(alternatization m) = (∑ σ : Perm ι, Equiv.Perm.sign σ • m.domDomCongr σ :) := coe_injective rfl theorem alternatization_apply (m : MultilinearMap R (fun _ : ι => M) N') (v : ι → M) : alternatization m v = ∑ σ : Perm ι, Equiv.Perm.sign σ • m.domDomCongr σ v := by simp only [alternatization_def, smul_apply, sum_apply] end MultilinearMap namespace AlternatingMap /-- Alternatizing a multilinear map that is already alternating results in a scale factor of `n!`, where `n` is the number of inputs. -/ theorem coe_alternatization [DecidableEq ι] [Fintype ι] (a : M [⋀^ι]→ₗ[R] N') : MultilinearMap.alternatization (a : MultilinearMap R (fun _ => M) N') = Nat.factorial (Fintype.card ι) • a := by apply AlternatingMap.coe_injective simp_rw [MultilinearMap.alternatization_def, ← coe_domDomCongr, domDomCongr_perm, coe_smul, smul_smul, Int.units_mul_self, one_smul, Finset.sum_const, Finset.card_univ, Fintype.card_perm, ← coe_multilinearMap, coe_smul] end AlternatingMap namespace LinearMap variable {N'₂ : Type*} [AddCommGroup N'₂] [Module R N'₂] [DecidableEq ι] [Fintype ι] /-- Composition with a linear map before and after alternatization are equivalent. -/ theorem compMultilinearMap_alternatization (g : N' →ₗ[R] N'₂) (f : MultilinearMap R (fun _ : ι => M) N') : MultilinearMap.alternatization (g.compMultilinearMap f) = g.compAlternatingMap (MultilinearMap.alternatization f) := by ext simp [MultilinearMap.alternatization_def] end LinearMap section Basis open AlternatingMap variable {ι₁ : Type*} [Finite ι] variable {R' : Type*} {N₁ N₂ : Type*} [CommSemiring R'] [AddCommMonoid N₁] [AddCommMonoid N₂] variable [Module R' N₁] [Module R' N₂] /-- Two alternating maps indexed by a `Fintype` are equal if they are equal when all arguments are distinct basis vectors. -/ theorem Module.Basis.ext_alternating {f g : N₁ [⋀^ι]→ₗ[R'] N₂} (e : Basis ι₁ R' N₁) (h : ∀ v : ι → ι₁, Function.Injective v → (f fun i => e (v i)) = g fun i => e (v i)) : f = g := by refine AlternatingMap.coe_multilinearMap_injective (Basis.ext_multilinear (fun _ ↦ e) fun v => ?_) by_cases hi : Function.Injective v · exact h v hi · have : ¬Function.Injective fun i => e (v i) := hi.imp Function.Injective.of_comp rw [coe_multilinearMap, coe_multilinearMap, f.map_eq_zero_of_not_injective _ this, g.map_eq_zero_of_not_injective _ this] end Basis variable {R' : Type*} {M'' M₂'' N'' N₂'' : Type*} [CommSemiring R'] [AddCommMonoid M''] [AddCommMonoid M₂''] [AddCommMonoid N''] [AddCommMonoid N₂''] [Module R' M''] [Module R' M₂''] [Module R' N''] [Module R' N₂''] /-- An isomorphism of multilinear maps given an isomorphism between their codomains. This is `Linear.compAlternatingMap` as an isomorphism, and the alternating version of `LinearEquiv.multilinearMapCongrRight`. -/ @[simps!] def LinearEquiv.alternatingMapCongrRight (e : N'' ≃ₗ[R'] N₂'') : M''[⋀^ι]→ₗ[R'] N'' ≃ₗ[R'] (M'' [⋀^ι]→ₗ[R'] N₂'') where toFun f := e.compAlternatingMap f invFun f := e.symm.compAlternatingMap f map_add' _ _ := by ext; simp map_smul' _ _ := by ext; simp left_inv _ := by ext; simp right_inv _ := by ext; simp /-- The space of constant maps is equivalent to the space of maps that are alternating with respect to an empty family. -/ @[simps] def AlternatingMap.constLinearEquivOfIsEmpty [IsEmpty ι] : N'' ≃ₗ[R'] (M'' [⋀^ι]→ₗ[R'] N'') where toFun := AlternatingMap.constOfIsEmpty R' M'' ι map_add' _ _ := rfl map_smul' _ _ := rfl invFun f := f 0 right_inv f := ext fun _ => AlternatingMap.congr_arg f <| Subsingleton.elim _ _
.lake/packages/mathlib/Mathlib/LinearAlgebra/Alternating/Uncurry/Fin.lean
import Mathlib.LinearAlgebra.Alternating.Curry import Mathlib.GroupTheory.Perm.Fin import Mathlib.Data.Fin.Parity /-! # Uncurrying alternating maps Given a function `f` which is linear in the first argument and is alternating form in the other `n` arguments, this file defines an alternating form `AlternatingMap.alternatizeUncurryFin f` in `n + 1` arguments. This function is given by ``` AlternatingMap.alternatizeUncurryFin f v = ∑ i : Fin (n + 1), (-1) ^ (i : ℕ) • f (v i) (removeNth i v) ``` Given an alternating map `f` of `n + 1` arguments, each term in the sum above written for `f.curryLeft` equals the original map, thus `f.curryLeft.alternatizeUncurryFin = (n + 1) • f`. We do not multiply the result of `alternatizeUncurryFin` by `(n + 1)⁻¹` so that the construction works for `R`-multilinear maps over any commutative ring `R`, not only a field of characteristic zero. ## Main results - `AlternatingMap.alternatizeUncurryFin_curryLeft`: the round-trip formula for currying/uncurrying, see above. - `AlternatingMap.alternatizeUncurryFin_alternatizeUncurryFinLM_comp_of_symmetric`: If `f` is a symmetric bilinear map taking values in the space of alternating maps, then the twice uncurried `f` is zero. A version of the latter theorem for continuous alternating maps will be used to prove that the second exterior derivative of a differential form is zero. -/ open Fin Function namespace AlternatingMap variable {R : Type*} {M M₂ N N₂ : Type*} [CommRing R] [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup N] [AddCommGroup N₂] [Module R M] [Module R M₂] [Module R N] [Module R N₂] {n : ℕ} /-- If `f` is a `(n + 1)`-multilinear alternating map, `x` is an element of the domain, and `v` is an `n`-vector, then the value of `f` at `v` with `x` inserted at the `p`th place equals `(-1) ^ p` times the value of `f` at `v` with `x` prepended. -/ theorem map_insertNth (f : M [⋀^Fin (n + 1)]→ₗ[R] N) (p : Fin (n + 1)) (x : M) (v : Fin n → M) : f (p.insertNth x v) = (-1) ^ (p : ℕ) • f (Matrix.vecCons x v) := by rw [← cons_comp_cycleRange, map_perm, Matrix.vecCons] simp [Units.smul_def] theorem neg_one_pow_smul_map_insertNth (f : M [⋀^Fin (n + 1)]→ₗ[R] N) (p : Fin (n + 1)) (x : M) (v : Fin n → M) : (-1) ^ (p : ℕ) • f (p.insertNth x v) = f (Matrix.vecCons x v) := by rw [map_insertNth, smul_smul, ← pow_add, Even.neg_one_pow, one_smul] use p /-- Let `v` be an `(n + 1)`-tuple with two equal elements `v i = v j`, `i ≠ j`. Let `w i` (resp., `w j`) be the vector `v` with `i`th (resp., `j`th) element removed. Then `(-1) ^ i • f (w i) + (-1) ^ j • f (w j) = 0`. This follows from the fact that these two vectors differ by a permutation of sign `(-1) ^ (i + j)`. These are the only two nonzero terms in the proof of `map_eq_zero_of_eq` in the definition of `alternatizeUncurryFin` below. -/ theorem neg_one_pow_smul_map_removeNth_add_eq_zero_of_eq (f : M [⋀^Fin n]→ₗ[R] N) {v : Fin (n + 1) → M} {i j : Fin (n + 1)} (hvij : v i = v j) (hij : i ≠ j) : (-1) ^ (i : ℕ) • f (i.removeNth v) + (-1) ^ (j : ℕ) • f (j.removeNth v) = 0 := by rcases exists_succAbove_eq hij with ⟨i, rfl⟩ obtain ⟨m, rfl⟩ : ∃ m, m + 1 = n := by simp [i.pos] rw [← (i.predAbove j).insertNth_self_removeNth (removeNth _ _), ← removeNth_removeNth_eq_swap, removeNth, succAbove_succAbove_predAbove, map_insertNth, ← neg_one_pow_smul_map_insertNth, insertNth_removeNth, update_eq_self_iff.2, smul_smul, ← pow_add, neg_one_pow_succAbove_add_predAbove, neg_smul, pow_add, mul_smul, smul_smul (_ ^ i.val), ← sq, ← pow_mul, pow_mul', neg_one_pow_two, one_pow, one_smul, neg_add_cancel] exact hvij.symm /-- Given a function which is linear in the first argument and is alternating in the other `n` arguments, build an alternating form in `n + 1` arguments. The function is given by ``` alternatizeUncurryFin f v = ∑ i : Fin (n + 1), (-1) ^ (i : ℕ) • f (v i) (removeNth i v) ``` Note that the round-trip with `curryFin` multiplies the form by `n + 1`, since we want to avoid division in this definition. -/ def alternatizeUncurryFin (f : M →ₗ[R] M [⋀^Fin n]→ₗ[R] N) : M [⋀^Fin (n + 1)]→ₗ[R] N where toMultilinearMap := ∑ p : Fin (n + 1), (-1) ^ (p : ℕ) • LinearMap.uncurryMid p (toMultilinearMapLM ∘ₗ f) map_eq_zero_of_eq' := by intro v i j hvij hij suffices ∑ k : Fin (n + 1), (-1) ^ (k : ℕ) • f (v k) (k.removeNth v) = 0 by simpa calc _ = (-1) ^ (i : ℕ) • f (v i) (i.removeNth v) + (-1) ^ (j : ℕ) • f (v j) (j.removeNth v) := by refine Fintype.sum_eq_add _ _ hij fun k ⟨hki, hkj⟩ ↦ ?_ rcases exists_succAbove_eq hki.symm with ⟨i, rfl⟩ rcases exists_succAbove_eq hkj.symm with ⟨j, rfl⟩ rw [(f (v k)).map_eq_zero_of_eq _ hvij (ne_of_apply_ne _ hij), smul_zero] _ = 0 := by rw [hvij, neg_one_pow_smul_map_removeNth_add_eq_zero_of_eq] <;> assumption @[deprecated (since := "2025-09-30")] alias uncurryFin := alternatizeUncurryFin theorem alternatizeUncurryFin_apply (f : M →ₗ[R] M [⋀^Fin n]→ₗ[R] N) (v : Fin (n + 1) → M) : alternatizeUncurryFin f v = ∑ i : Fin (n + 1), (-1) ^ (i : ℕ) • f (v i) (removeNth i v) := by simp [alternatizeUncurryFin] @[deprecated (since := "2025-09-30")] alias uncurryFin_apply := alternatizeUncurryFin_apply @[simp] theorem alternatizeUncurryFin_add (f g : M →ₗ[R] M [⋀^Fin n]→ₗ[R] N) : alternatizeUncurryFin (f + g) = alternatizeUncurryFin f + alternatizeUncurryFin g := by ext simp [alternatizeUncurryFin_apply, Finset.sum_add_distrib] @[deprecated (since := "2025-09-30")] alias uncurryFin_add := alternatizeUncurryFin_add @[simp] lemma alternatizeUncurryFin_curryLeft (f : M [⋀^Fin (n + 1)]→ₗ[R] N) : alternatizeUncurryFin (curryLeft f) = (n + 1) • f := by ext v simp [alternatizeUncurryFin_apply, ← map_insertNth] @[deprecated (since := "2025-09-30")] alias uncurryFin_curryLeft := alternatizeUncurryFin_curryLeft variable {S : Type*} [Monoid S] [DistribMulAction S N] [SMulCommClass R S N] @[simp] theorem alternatizeUncurryFin_smul (c : S) (f : M →ₗ[R] M [⋀^Fin n]→ₗ[R] N) : alternatizeUncurryFin (c • f) = c • alternatizeUncurryFin f := by ext v simp [alternatizeUncurryFin_apply, smul_comm _ c, Finset.smul_sum] @[deprecated (since := "2025-09-30")] alias uncurryFin_smul := alternatizeUncurryFin_smul /-- `AlternatingMap.alternatizeUncurryFin` as a linear map. -/ @[simps! apply] def alternatizeUncurryFinLM : (M →ₗ[R] M [⋀^Fin n]→ₗ[R] N) →ₗ[R] M [⋀^Fin (n + 1)]→ₗ[R] N where toFun := alternatizeUncurryFin map_add' := alternatizeUncurryFin_add map_smul' := alternatizeUncurryFin_smul @[deprecated (since := "2025-09-30")] alias uncurryFinLM := alternatizeUncurryFinLM /-- If `f` is a bilinear map taking values in the space of alternating maps, then evaluation of the twice uncurried `f` on a tuple of vectors `v` can be represented as a sum of $$ f(v_i, v_j; v_0, \dots, \hat{v_i}, \dots, \hat{v_j}-) - f(v_j, v_i; v_0, \dots, \hat{v_i}, \dots, \hat{v_j}-) $$ over all `(i j : Fin (n + 2))`, `i < j`, taken with appropriate signs. Here $$\hat{v_i}$$ and $$\hat{v_j}$$ mean that these vectors are removed from the tuple. We use pairs of `i j : Fin (n + 1)`, `i ≤ j`, to encode pairs `(i.castSucc : Fin (n + 1), j.succ : Fin (n + 1))`, so the power of `-1` is off by one compared to the informal texts. In particular, if `f` is symmetric in the first two arguments, then the resulting alternating map is zero, see `alternatizeUncurryFin_alternatizeUncurryFinLM_comp_of_symmetric` below. -/ theorem alternatizeUncurryFin_alternatizeUncurryFinLM_comp_apply (f : M →ₗ[R] M →ₗ[R] M [⋀^Fin n]→ₗ[R] N) (v : Fin (n + 2) → M) : alternatizeUncurryFin (alternatizeUncurryFinLM ∘ₗ f) v = ∑ (i : Fin (n + 1)), ∑ j ≥ i, (-1 : ℤ) ^ (i + j : ℕ) • (f (v i.castSucc) (v j.succ) (j.removeNth <| i.castSucc.removeNth v) - f (v j.succ) (v i.castSucc) (j.removeNth <| i.castSucc.removeNth v)) := by simp? [alternatizeUncurryFin_apply, Finset.smul_sum, sum_sum_eq_sum_triangle_add] says simp only [alternatizeUncurryFin_apply, Int.reduceNeg, LinearMap.coe_comp, comp_apply, alternatizeUncurryFinLM_apply, Finset.smul_sum, sum_sum_eq_sum_triangle_add, coe_castSucc, val_succ] refine Fintype.sum_congr _ _ fun i ↦ Finset.sum_congr rfl fun j hj ↦ ?_ rw [Finset.mem_Ici] at hj have H₁ : i.castSucc.removeNth v j = v j.succ := by simp [Fin.removeNth_apply, Fin.succAbove_of_le_castSucc, hj] have H₂ : j.succ.removeNth v i = v i.castSucc := by simp [Fin.removeNth_apply, Fin.succAbove_of_castSucc_lt, hj] simp only [pow_add, mul_smul, pow_one, neg_one_smul, smul_neg, smul_sub, ← sub_eq_add_neg, smul_comm ((-1 : ℤ) ^ (j : ℕ)), H₁, H₂] congr 4 rw [removeNth_removeNth_eq_swap] simp [Fin.predAbove, hj, Fin.succAbove] /-- If `f` is a symmetric bilinear map taking values in the space of alternating maps, then the twice uncurried `f` is zero. See also `alternatizeUncurryFin_alternatizeUncurryFinLM_comp_apply` for a formula that does not assume `f` to be symmetric. -/ theorem alternatizeUncurryFin_alternatizeUncurryFinLM_comp_of_symmetric {f : M →ₗ[R] M →ₗ[R] M [⋀^Fin n]→ₗ[R] N} (hf : ∀ x y, f x y = f y x) : alternatizeUncurryFin (alternatizeUncurryFinLM ∘ₗ f) = 0 := by ext v simp [alternatizeUncurryFin_alternatizeUncurryFinLM_comp_apply, hf (v <| .castSucc _)] @[deprecated (since := "2025-09-30")] alias uncurryFin_uncurryFinLM_comp_of_symmetric := alternatizeUncurryFin_alternatizeUncurryFinLM_comp_of_symmetric end AlternatingMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeProduct/Basic.lean
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. ## 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)] {motive : (⨁ i, M i) → Prop} (x : ⨁ i, M i) (zero : motive 0) (lof : ∀ i (x : M i), motive (lof R ι M i x)) (add : ∀ (x y : ⨁ i, M i), motive x → motive y → motive (x + y)) : motive x := by induction x using DirectSum.induction_on with | zero => exact zero | of => exact lof _ _ | add x y hx hy => exact add x y hx hy end DirectSum namespace RingQuot universe uS uA uB open scoped Function -- required for scoped `on` notation /-- 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 algEquivQuotAlgEquiv {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 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 equivQuotEquiv {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) algEquivQuotAlgEquiv 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 powerAlgebraEquivFreeTensorAlgebra : PowerAlgebra R A ≃ₐ[R] FreeTensorAlgebra R A := TensorAlgebra.equivDirectSum.symm @[deprecated (since := "2025-05-05")] alias powerAlgebra_equiv_freeAlgebra := powerAlgebraEquivFreeTensorAlgebra /-- 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₂)) open scoped Function /-- 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 asPowers := RingQuot <| FreeProduct.rel' R A @[deprecated (since := "2025-05-01")] alias _root_.LinearAlgebra.FreeProductOfPowers := asPowers /-- The `R`-algebra equivalence relating `FreeProduct` and `FreeProduct.asPowers`. -/ noncomputable def asPowersEquiv : asPowers R A ≃ₐ[R] FreeProduct R A := RingQuot.algEquivQuotAlgEquiv (powerAlgebraEquivFreeTensorAlgebra R A |>.symm) (FreeProduct.rel R A) |>.symm @[deprecated (since := "2025-05-01")] alias equivPowerAlgebra := asPowersEquiv 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 simp /-- 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`. -/ @[simp↓] theorem lift_comp_ι : lift R A maps ∘ₐ ι R A i = maps := by ext a simp [lift_apply, ι] @[simp↓] theorem lift_algebraMap (r : R) : lift R A maps (algebraMap R _ r) = algebraMap R _ r := by rw [lift_apply, AlgHom.commutes] @[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
.lake/packages/mathlib/Mathlib/LinearAlgebra/Dual/Lemmas.lean
import Mathlib.Algebra.Module.LinearMap.DivisionRing import Mathlib.LinearAlgebra.Basis.Basic import Mathlib.LinearAlgebra.Dimension.ErdosKaplansky import Mathlib.LinearAlgebra.Dual.Basis import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.LinearAlgebra.Matrix.InvariantBasisNumber import Mathlib.LinearAlgebra.Projection import Mathlib.LinearAlgebra.SesquilinearForm.Basic import Mathlib.RingTheory.Finiteness.Projective import Mathlib.RingTheory.LocalRing.Basic import Mathlib.RingTheory.TensorProduct.Maps /-! # Dual vector spaces The dual space of an $R$-module $M$ is the $R$-module of $R$-linear maps $M \to R$. This file contains basic results on dual vector spaces. ## Main definitions * Submodules: * `Submodule.dualRestrict_comap W'` is the dual annihilator of `W' : Submodule R (Dual R M)`, pulled back along `Module.Dual.eval R M`. * `Submodule.dualCopairing W` is the canonical pairing between `W.dualAnnihilator` and `M ⧸ W`. It is nondegenerate for vector spaces (`subspace.dualCopairing_nondegenerate`). * Vector spaces: * `Subspace.dualLift W` is an arbitrary section (using choice) of `Submodule.dualRestrict W`. ## Main results * Annihilators: * `LinearMap.ker_dual_map_eq_dualAnnihilator_range` says that `f.dual_map.ker = f.range.dualAnnihilator` * `LinearMap.range_dual_map_eq_dualAnnihilator_ker_of_subtype_range_surjective` says that `f.dual_map.range = f.ker.dualAnnihilator`; this is specialized to vector spaces in `LinearMap.range_dual_map_eq_dualAnnihilator_ker`. * `Submodule.dualQuotEquivDualAnnihilator` is the equivalence `Dual R (M ⧸ W) ≃ₗ[R] W.dualAnnihilator` * `Submodule.quotDualCoannihilatorToDual` is the nondegenerate pairing `M ⧸ W.dualCoannihilator →ₗ[R] Dual R W`. It is an perfect pairing when `R` is a field and `W` is finite-dimensional. * Vector spaces: * `Subspace.dualAnnihilator_dualCoannihilator_eq` says that the double dual annihilator, pulled back ground `Module.Dual.eval`, is the original submodule. * `Subspace.dualAnnihilator_gci` says that `module.dualAnnihilator_gc R M` is an antitone Galois coinsertion. * `Subspace.quotAnnihilatorEquiv` is the equivalence `Dual K V ⧸ W.dualAnnihilator ≃ₗ[K] Dual K W`. * `LinearMap.dualPairing_nondegenerate` says that `Module.dualPairing` is nondegenerate. * `Subspace.is_compl_dualAnnihilator` says that the dual annihilator carries complementary subspaces to complementary subspaces. * Finite-dimensional vector spaces: * `Subspace.orderIsoFiniteCodimDim` is the antitone order isomorphism between finite-codimensional subspaces of `V` and finite-dimensional subspaces of `Dual K V`. * `Subspace.orderIsoFiniteDimensional` is the antitone order isomorphism between subspaces of a finite-dimensional vector space `V` and subspaces of its dual. * `Subspace.quotDualEquivAnnihilator W` is the equivalence `(Dual K V ⧸ W.dualLift.range) ≃ₗ[K] W.dualAnnihilator`, where `W.dualLift.range` is a copy of `Dual K W` inside `Dual K V`. * `Subspace.quotEquivAnnihilator W` is the equivalence `(V ⧸ W) ≃ₗ[K] W.dualAnnihilator` * `Subspace.dualQuotDistrib W` is an equivalence `Dual K (V₁ ⧸ W) ≃ₗ[K] Dual K V₁ ⧸ W.dualLift.range` from an arbitrary choice of splitting of `V₁`. -/ open Module Submodule noncomputable section namespace Module variable (R A M : Type*) variable [CommSemiring R] [AddCommMonoid M] [Module R M] section Prod variable (M' : Type*) [AddCommMonoid M'] [Module R M'] /-- Taking duals distributes over products. -/ @[simps!] def dualProdDualEquivDual : (Module.Dual R M × Module.Dual R M') ≃ₗ[R] Module.Dual R (M × M') := LinearMap.coprodEquiv R @[simp] theorem dualProdDualEquivDual_apply (φ : Module.Dual R M) (ψ : Module.Dual R M') : dualProdDualEquivDual R M M' (φ, ψ) = φ.coprod ψ := rfl end Prod end Module section open Module Module.Dual Submodule LinearMap Cardinal Function universe uR uM uK uV uι variable {R : Type uR} {M : Type uM} {K : Type uK} {V : Type uV} {ι : Type uι} section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] section Finite variable [Finite ι] -- Not sure whether this is true for free modules over a commutative ring /-- A vector space over a field is isomorphic to its dual if and only if it is finite-dimensional: a consequence of the Erdős-Kaplansky theorem. -/ theorem Basis.linearEquiv_dual_iff_finiteDimensional [Field K] [AddCommGroup V] [Module K V] : Nonempty (V ≃ₗ[K] Dual K V) ↔ FiniteDimensional K V := by refine ⟨fun ⟨e⟩ ↦ ?_, fun h ↦ ⟨(Module.Free.chooseBasis K V).toDualEquiv⟩⟩ rw [FiniteDimensional, ← Module.rank_lt_aleph0_iff] by_contra! apply (lift_rank_lt_rank_dual this).ne have := e.lift_rank_eq rwa [lift_umax, lift_id'.{uV}] at this theorem Module.Basis.dual_rank_eq (b : Basis ι R M) : Module.rank R (Dual R M) = Cardinal.lift.{uR,uM} (Module.rank R M) := by classical rw [← lift_umax.{uM,uR}, b.toDualEquiv.lift_rank_eq, lift_id'.{uM,uR}] end Finite namespace Module variable [Module.Finite R M] instance dual_free [Free R M] : Free R (Dual R M) := Free.of_basis (Free.chooseBasis R M).dualBasis instance dual_projective [Projective R M] : Projective R (Dual R M) := have ⟨_, f, g, _, _, hfg⟩ := Finite.exists_comp_eq_id_of_projective R M .of_split f.dualMap g.dualMap (congr_arg dualMap hfg) instance dual_finite [Projective R M] : Module.Finite R (Dual R M) := have ⟨n, f, g, _, _, hfg⟩ := Finite.exists_comp_eq_id_of_projective R M have := Finite.of_basis (Free.chooseBasis R <| Fin n → R).dualBasis .of_surjective _ (surjective_of_comp_eq_id f.dualMap g.dualMap <| congr_arg dualMap hfg) end Module end CommSemiring end namespace Module universe uK uV variable {K : Type uK} {V : Type uV} variable [CommSemiring K] [AddCommMonoid V] [Module K V] [Projective K V] open Module Module.Dual Submodule LinearMap Cardinal Basis Module section variable (K) theorem eval_apply_injective : Function.Injective (eval K V) := have ⟨s, hs⟩ := Module.projective_def'.mp ‹Projective K V› .of_comp (f := s.dualMap.dualMap) (Finsupp.basisSingleOne.eval_injective.comp <| injective_of_comp_eq_id s _ hs) variable (V) theorem eval_ker : LinearMap.ker (eval K V) = ⊥ := ker_eq_bot_of_injective (eval_apply_injective K) theorem map_eval_injective : (Submodule.map (eval K V)).Injective := Submodule.map_injective_of_injective (eval_apply_injective K) theorem comap_eval_surjective : (Submodule.comap (eval K V)).Surjective := Submodule.comap_surjective_of_injective (eval_apply_injective K) end section variable (K) theorem eval_apply_eq_zero_iff (v : V) : (eval K V) v = 0 ↔ v = 0 := SetLike.ext_iff.mp (eval_ker K V) v theorem forall_dual_apply_eq_zero_iff (v : V) : (∀ φ : Module.Dual K V, φ v = 0) ↔ v = 0 := by rw [← eval_apply_eq_zero_iff K v, LinearMap.ext_iff] simp only [eval_apply, zero_apply] @[simp] theorem subsingleton_dual_iff : Subsingleton (Dual K V) ↔ Subsingleton V := ⟨fun _ ↦ ⟨fun _ _ ↦ eval_apply_injective K (Subsingleton.elim ..)⟩, fun _ ↦ inferInstance⟩ @[simp] theorem nontrivial_dual_iff : Nontrivial (Dual K V) ↔ Nontrivial V := by rw [← not_iff_not, not_nontrivial_iff_subsingleton, not_nontrivial_iff_subsingleton, subsingleton_dual_iff] instance instNontrivialDual [Nontrivial V] : Nontrivial (Dual K V) := (nontrivial_dual_iff K).mpr inferInstance omit [Projective K V] in /-- For an example of a non-free projective `K`-module `V` for which the forward implication fails, see https://stacks.math.columbia.edu/tag/05WG#comment-9913. -/ theorem finite_dual_iff [Free K V] : Module.Finite K (Dual K V) ↔ Module.Finite K V := by refine ⟨fun h ↦ ?_, fun _ ↦ inferInstance⟩ have ⟨⟨ι, b⟩⟩ := Free.exists_basis (R := K) (M := V) cases finite_or_infinite ι · exact .of_basis b nontriviality K have ⟨n, hn⟩ := Module.Finite.exists_nat_not_surjective K (Dual K V) let g := Finsupp.llift K K K ι ≪≫ₗ b.repr.dualMap exact hn (LinearMap.funLeft K K (Fin.valEmbedding.trans (Infinite.natEmbedding ι)) ∘ₗ _) ((Function.Embedding.injective _).surjective_comp_right.comp g.symm.surjective) |>.elim end omit [Projective K V] theorem dual_rank_eq [Free K V] [Module.Finite K V] : Module.rank K (Dual K V) = Cardinal.lift.{uK,uV} (Module.rank K V) := (Free.chooseBasis K V).dual_rank_eq section IsReflexive open Function variable (R M N : Type*) variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] /-- See also `Module.instFiniteDimensionalOfIsReflexive` for the converse over a field. -/ instance (priority := 900) IsReflexive.of_finite_of_free [Module.Finite R M] [Free R M] : IsReflexive R M where bijective_dual_eval'.left := (Free.chooseBasis R M).eval_injective bijective_dual_eval'.right := range_eq_top.mp (Free.chooseBasis R M).eval_range variable [IsReflexive R M] instance (priority := 900) [Module.Finite R N] [Projective R N] : IsReflexive R N := have ⟨_, f, hf⟩ := Finite.exists_fin' R N have ⟨g, H⟩ := projective_lifting_property f .id hf .of_split g f H instance _root_.Prod.instModuleIsReflexive [IsReflexive R N] : IsReflexive R (M × N) where bijective_dual_eval' := by let e : Dual R (Dual R (M × N)) ≃ₗ[R] Dual R (Dual R M) × Dual R (Dual R N) := (dualProdDualEquivDual R M N).dualMap.trans (dualProdDualEquivDual R (Dual R M) (Dual R N)).symm have : Dual.eval R (M × N) = e.symm.comp ((Dual.eval R M).prodMap (Dual.eval R N)) := by ext m f <;> simp [e] simp only [this, coe_comp, LinearEquiv.coe_coe, EquivLike.comp_bijective] exact (bijective_dual_eval R M).prodMap (bijective_dual_eval R N) instance _root_.ULift.instModuleIsReflexive.{w} : IsReflexive R (ULift.{w} M) := equiv ULift.moduleEquiv.symm instance instFiniteDimensionalOfIsReflexive (K V : Type*) [Field K] [AddCommGroup V] [Module K V] [IsReflexive K V] : FiniteDimensional K V := by rw [FiniteDimensional, ← rank_lt_aleph0_iff] by_contra! contra suffices lift (Module.rank K V) < Module.rank K (Dual K (Dual K V)) by have heq := lift_rank_eq_of_equiv_equiv (R := K) (R' := K) (M := V) (M' := Dual K (Dual K V)) (ZeroHom.id K) (evalEquiv K V) bijective_id (fun r v ↦ (evalEquiv K V).map_smul _ _) rw [← lift_umax, heq, lift_id'] at this exact lt_irrefl _ this have h₁ : lift (Module.rank K V) < Module.rank K (Dual K V) := lift_rank_lt_rank_dual contra have h₂ : Module.rank K (Dual K V) < Module.rank K (Dual K (Dual K V)) := by convert lift_rank_lt_rank_dual <| le_trans (by simpa) h₁.le rw [lift_id'] exact lt_trans h₁ h₂ end IsReflexive end Module namespace Submodule open Module variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {p : Submodule R M} @[simp] theorem dualCoannihilator_top [Projective R M] : (⊤ : Submodule R (Module.Dual R M)).dualCoannihilator = ⊥ := by rw [dualCoannihilator, dualAnnihilator_top, comap_bot, Module.eval_ker] theorem exists_dual_map_eq_bot_of_notMem {x : M} (hx : x ∉ p) (hp' : Free R (M ⧸ p)) : ∃ f : Dual R M, f x ≠ 0 ∧ p.map f = ⊥ := by suffices ∃ f : Dual R (M ⧸ p), f (p.mkQ x) ≠ 0 by obtain ⟨f, hf⟩ := this; exact ⟨f.comp p.mkQ, hf, by simp [Submodule.map_comp]⟩ rwa [← Submodule.Quotient.mk_eq_zero, ← Submodule.mkQ_apply, ← forall_dual_apply_eq_zero_iff (K := R), not_forall] at hx @[deprecated (since := "2025-05-24")] alias exists_dual_map_eq_bot_of_nmem := exists_dual_map_eq_bot_of_notMem theorem exists_dual_map_eq_bot_of_lt_top (hp : p < ⊤) (hp' : Free R (M ⧸ p)) : ∃ f : Dual R M, f ≠ 0 ∧ p.map f = ⊥ := by obtain ⟨x, hx⟩ : ∃ x : M, x ∉ p := by rw [lt_top_iff_ne_top] at hp; contrapose! hp; ext; simp [hp] obtain ⟨f, hf, hf'⟩ := p.exists_dual_map_eq_bot_of_notMem hx hp' exact ⟨f, by aesop, hf'⟩ /-- Consider a reflexive module and a set `s` of linear forms. If for any `z ≠ 0` there exists `f ∈ s` such that `f z ≠ 0`, then `s` spans the whole dual space. -/ theorem span_eq_top_of_ne_zero [IsReflexive R M] {s : Set (M →ₗ[R] R)} [Free R ((M →ₗ[R] R) ⧸ (span R s))] (h : ∀ z ≠ 0, ∃ f ∈ s, f z ≠ 0) : span R s = ⊤ := by by_contra! hn obtain ⟨φ, φne, hφ⟩ := exists_dual_map_eq_bot_of_lt_top hn.lt_top inferInstance let φs := (evalEquiv R M).symm φ have this f (hf : f ∈ s) : f φs = 0 := by rw [← mem_bot R, ← hφ, mem_map] exact ⟨f, subset_span hf, (apply_evalEquiv_symm_apply R M f φ).symm⟩ obtain ⟨x, xs, hx⟩ := h φs (by simp [φne, φs]) exact hx <| this x xs variable {ι 𝕜 E : Type*} [Field 𝕜] [AddCommGroup E] [Module 𝕜 E] open LinearMap Set FiniteDimensional theorem _root_.FiniteDimensional.mem_span_of_iInf_ker_le_ker [FiniteDimensional 𝕜 E] {L : ι → E →ₗ[𝕜] 𝕜} {K : E →ₗ[𝕜] 𝕜} (h : ⨅ i, LinearMap.ker (L i) ≤ ker K) : K ∈ span 𝕜 (range L) := by by_contra hK rcases exists_dual_map_eq_bot_of_notMem hK inferInstance with ⟨φ, φne, hφ⟩ let φs := (Module.evalEquiv 𝕜 E).symm φ have : K φs = 0 := by refine h <| (Submodule.mem_iInf _).2 fun i ↦ (mem_bot 𝕜).1 ?_ rw [← hφ, Submodule.mem_map] exact ⟨L i, Submodule.subset_span ⟨i, rfl⟩, (apply_evalEquiv_symm_apply 𝕜 E _ φ).symm⟩ simp only [apply_evalEquiv_symm_apply, φs, φne] at this /-- Given some linear forms $L_1, ..., L_n, K$ over a vector space $E$, if $\bigcap_{i=1}^n \mathrm{ker}(L_i) \subseteq \mathrm{ker}(K)$, then $K$ is in the space generated by $L_1, ..., L_n$. -/ theorem _root_.mem_span_of_iInf_ker_le_ker [Finite ι] {L : ι → E →ₗ[𝕜] 𝕜} {K : E →ₗ[𝕜] 𝕜} (h : ⨅ i, ker (L i) ≤ ker K) : K ∈ span 𝕜 (range L) := by have _ := Fintype.ofFinite ι let φ : E →ₗ[𝕜] ι → 𝕜 := LinearMap.pi L let p := ⨅ i, ker (L i) have p_eq : p = ker φ := (ker_pi L).symm let ψ : (E ⧸ p) →ₗ[𝕜] ι → 𝕜 := p.liftQ φ p_eq.le have _ : FiniteDimensional 𝕜 (E ⧸ p) := of_injective ψ (ker_eq_bot.1 (ker_liftQ_eq_bot' p φ p_eq)) let L' i : (E ⧸ p) →ₗ[𝕜] 𝕜 := p.liftQ (L i) (iInf_le _ i) let K' : (E ⧸ p) →ₗ[𝕜] 𝕜 := p.liftQ K h have : ⨅ i, ker (L' i) ≤ ker K' := by simp_rw +zetaDelta [← ker_pi, pi_liftQ_eq_liftQ_pi, ker_liftQ_eq_bot' p φ p_eq] exact bot_le obtain ⟨c, hK'⟩ := (mem_span_range_iff_exists_fun 𝕜).1 (FiniteDimensional.mem_span_of_iInf_ker_le_ker this) refine (mem_span_range_iff_exists_fun 𝕜).2 ⟨c, ?_⟩ conv_lhs => enter [2]; intro i; rw [← p.liftQ_mkQ (L i) (iInf_le _ i)] rw [← p.liftQ_mkQ K h] ext x convert LinearMap.congr_fun hK' (p.mkQ x) simp only [L',coeFn_sum, Finset.sum_apply, smul_apply, coe_comp, Function.comp_apply, smul_eq_mul] end Submodule namespace Subspace open Submodule LinearMap -- We work in vector spaces because `exists_isCompl` only hold for vector spaces variable {K V : Type*} [Field K] [AddCommGroup V] [Module K V] @[simp] theorem dualAnnihilator_dualCoannihilator_eq {W : Subspace K V} : W.dualAnnihilator.dualCoannihilator = W := by refine le_antisymm (fun v ↦ Function.mtr ?_) (le_dualAnnihilator_dualCoannihilator _) simp only [mem_dualAnnihilator, mem_dualCoannihilator] rw [← Quotient.mk_eq_zero W, ← Module.forall_dual_apply_eq_zero_iff K] push_neg refine fun ⟨φ, hφ⟩ ↦ ⟨φ.comp W.mkQ, fun w hw ↦ ?_, hφ⟩ rw [comp_apply, mkQ_apply, (Quotient.mk_eq_zero W).mpr hw, φ.map_zero] -- exact elaborates slowly theorem forall_mem_dualAnnihilator_apply_eq_zero_iff (W : Subspace K V) (v : V) : (∀ φ : Module.Dual K V, φ ∈ W.dualAnnihilator → φ v = 0) ↔ v ∈ W := by rw [← SetLike.ext_iff.mp dualAnnihilator_dualCoannihilator_eq v, mem_dualCoannihilator] theorem comap_dualAnnihilator_dualAnnihilator (W : Subspace K V) : W.dualAnnihilator.dualAnnihilator.comap (Module.Dual.eval K V) = W := by ext; rw [Iff.comm, ← forall_mem_dualAnnihilator_apply_eq_zero_iff]; simp theorem map_le_dualAnnihilator_dualAnnihilator (W : Subspace K V) : W.map (Module.Dual.eval K V) ≤ W.dualAnnihilator.dualAnnihilator := map_le_iff_le_comap.mpr (comap_dualAnnihilator_dualAnnihilator W).ge /-- `Submodule.dualAnnihilator` and `Submodule.dualCoannihilator` form a Galois coinsertion. -/ def dualAnnihilatorGci (K V : Type*) [Field K] [AddCommGroup V] [Module K V] : GaloisCoinsertion (OrderDual.toDual ∘ (dualAnnihilator : Subspace K V → Subspace K (Module.Dual K V))) (dualCoannihilator ∘ OrderDual.ofDual) where choice W _ := dualCoannihilator W gc := dualAnnihilator_gc K V u_l_le _ := dualAnnihilator_dualCoannihilator_eq.le choice_eq _ _ := rfl theorem dualAnnihilator_le_dualAnnihilator_iff {W W' : Subspace K V} : W.dualAnnihilator ≤ W'.dualAnnihilator ↔ W' ≤ W := (dualAnnihilatorGci K V).l_le_l_iff theorem dualAnnihilator_inj {W W' : Subspace K V} : W.dualAnnihilator = W'.dualAnnihilator ↔ W = W' := ⟨fun h ↦ (dualAnnihilatorGci K V).l_injective h, congr_arg _⟩ /-- Given a subspace `W` of `V` and an element of its dual `φ`, `dualLift W φ` is an arbitrary extension of `φ` to an element of the dual of `V`. That is, `dualLift W φ` sends `w ∈ W` to `φ x` and `x` in a chosen complement of `W` to `0`. -/ noncomputable def dualLift (W : Subspace K V) : Module.Dual K W →ₗ[K] Module.Dual K V := (Classical.choose <| W.subtype.exists_leftInverse_of_injective W.ker_subtype).dualMap variable {W : Subspace K V} @[simp] theorem dualLift_of_subtype {φ : Module.Dual K W} (w : W) : W.dualLift φ (w : V) = φ w := congr_arg φ <| DFunLike.congr_fun (Classical.choose_spec <| W.subtype.exists_leftInverse_of_injective W.ker_subtype) w theorem dualLift_of_mem {φ : Module.Dual K W} {w : V} (hw : w ∈ W) : W.dualLift φ w = φ ⟨w, hw⟩ := dualLift_of_subtype ⟨w, hw⟩ @[simp] theorem dualRestrict_comp_dualLift (W : Subspace K V) : W.dualRestrict.comp W.dualLift = 1 := by ext φ x simp theorem dualRestrict_leftInverse (W : Subspace K V) : Function.LeftInverse W.dualRestrict W.dualLift := fun x => by rw [← LinearMap.comp_apply, dualRestrict_comp_dualLift, End.one_apply] theorem dualLift_rightInverse (W : Subspace K V) : Function.RightInverse W.dualLift W.dualRestrict := W.dualRestrict_leftInverse theorem dualRestrict_surjective : Function.Surjective W.dualRestrict := W.dualLift_rightInverse.surjective theorem dualLift_injective : Function.Injective W.dualLift := W.dualRestrict_leftInverse.injective /-- The quotient by the `dualAnnihilator` of a subspace is isomorphic to the dual of that subspace. -/ noncomputable def quotAnnihilatorEquiv (W : Subspace K V) : (Module.Dual K V ⧸ W.dualAnnihilator) ≃ₗ[K] Module.Dual K W := (quotEquivOfEq _ _ W.dualRestrict_ker_eq_dualAnnihilator).symm.trans <| W.dualRestrict.quotKerEquivOfSurjective dualRestrict_surjective @[simp] theorem quotAnnihilatorEquiv_apply (W : Subspace K V) (φ : Module.Dual K V) : W.quotAnnihilatorEquiv (Submodule.Quotient.mk φ) = W.dualRestrict φ := by ext rfl /-- The natural isomorphism from the dual of a subspace `W` to `W.dualLift.range`. -/ noncomputable def dualEquivDual (W : Subspace K V) : Module.Dual K W ≃ₗ[K] LinearMap.range W.dualLift := LinearEquiv.ofInjective _ dualLift_injective theorem dualEquivDual_def (W : Subspace K V) : W.dualEquivDual.toLinearMap = W.dualLift.rangeRestrict := rfl @[simp] theorem dualEquivDual_apply (φ : Module.Dual K W) : W.dualEquivDual φ = ⟨W.dualLift φ, mem_range.2 ⟨φ, rfl⟩⟩ := rfl section open FiniteDimensional Module instance instModuleDualFiniteDimensional [FiniteDimensional K V] : FiniteDimensional K (Module.Dual K V) := by infer_instance @[simp] theorem dual_finrank_eq : finrank K (Module.Dual K V) = finrank K V := by by_cases h : FiniteDimensional K V · classical exact LinearEquiv.finrank_eq (Basis.ofVectorSpace K V).toDualEquiv.symm rw [finrank_eq_zero_of_basis_imp_false, finrank_eq_zero_of_basis_imp_false] · exact fun _ b ↦ h (Module.Finite.of_basis b) · exact fun _ b ↦ h ((Module.finite_dual_iff K).mp <| Module.Finite.of_basis b) variable [FiniteDimensional K V] theorem dualAnnihilator_dualAnnihilator_eq (W : Subspace K V) : W.dualAnnihilator.dualAnnihilator = Module.mapEvalEquiv K V W := by have : _ = W := Subspace.dualAnnihilator_dualCoannihilator_eq rw [dualCoannihilator, ← Module.mapEvalEquiv_symm_apply] at this rwa [← OrderIso.symm_apply_eq] /-- The quotient by the dual is isomorphic to its dual annihilator. -/ noncomputable def quotDualEquivAnnihilator (W : Subspace K V) : (Module.Dual K V ⧸ LinearMap.range W.dualLift) ≃ₗ[K] W.dualAnnihilator := LinearEquiv.quotEquivOfQuotEquiv <| LinearEquiv.trans W.quotAnnihilatorEquiv W.dualEquivDual open scoped Classical in /-- The quotient by a subspace is isomorphic to its dual annihilator. -/ noncomputable def quotEquivAnnihilator (W : Subspace K V) : (V ⧸ W) ≃ₗ[K] W.dualAnnihilator := let φ := (Basis.ofVectorSpace K W).toDualEquiv.trans W.dualEquivDual let ψ := LinearEquiv.quotEquivOfEquiv φ (Basis.ofVectorSpace K V).toDualEquiv ψ ≪≫ₗ W.quotDualEquivAnnihilator open Module theorem finrank_add_finrank_dualAnnihilator_eq (W : Subspace K V) : finrank K W + finrank K W.dualAnnihilator = finrank K V := by rw [← W.quotEquivAnnihilator.finrank_eq, add_comm, Submodule.finrank_quotient_add_finrank] @[simp] theorem finrank_dualCoannihilator_eq {Φ : Subspace K (Module.Dual K V)} : finrank K Φ.dualCoannihilator = finrank K Φ.dualAnnihilator := by rw [Submodule.dualCoannihilator, ← Module.evalEquiv_toLinearMap] exact LinearEquiv.finrank_eq (LinearEquiv.ofSubmodule' _ _) theorem finrank_add_finrank_dualCoannihilator_eq (W : Subspace K (Module.Dual K V)) : finrank K W + finrank K W.dualCoannihilator = finrank K V := by rw [finrank_dualCoannihilator_eq, finrank_add_finrank_dualAnnihilator_eq, dual_finrank_eq] end end Subspace open Module section CommRing variable {R M M' : Type*} variable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup M'] [Module R M'] namespace Submodule /-- Given a submodule, corestrict to the pairing on `M ⧸ W` by simultaneously restricting to `W.dualAnnihilator`. See `Subspace.dualCopairing_nondegenerate`. -/ def dualCopairing (W : Submodule R M) : W.dualAnnihilator →ₗ[R] M ⧸ W →ₗ[R] R := LinearMap.flip <| W.liftQ ((Module.dualPairing R M).domRestrict W.dualAnnihilator).flip (by intro w hw ext ⟨φ, hφ⟩ exact (mem_dualAnnihilator φ).mp hφ w hw) instance (W : Submodule R M) : FunLike (W.dualAnnihilator) M R where coe φ := φ.val coe_injective' φ ψ h := by ext simp only [funext_iff] at h exact h _ @[simp] theorem dualCopairing_apply {W : Submodule R M} (φ : W.dualAnnihilator) (x : M) : W.dualCopairing φ (Quotient.mk x) = φ x := rfl /-- Given a submodule, restrict to the pairing on `W` by simultaneously corestricting to `Module.Dual R M ⧸ W.dualAnnihilator`. This is `Submodule.dualRestrict` factored through the quotient by its kernel (which is `W.dualAnnihilator` by definition). See `Subspace.dualPairing_nondegenerate`. -/ def dualPairing (W : Submodule R M) : Module.Dual R M ⧸ W.dualAnnihilator →ₗ[R] W →ₗ[R] R := W.dualAnnihilator.liftQ W.dualRestrict le_rfl @[simp] theorem dualPairing_apply {W : Submodule R M} (φ : Module.Dual R M) (x : W) : W.dualPairing (Quotient.mk φ) x = φ x := rfl /-- That $\operatorname{im}(q^* : (V/W)^* \to V^*) = \operatorname{ann}(W)$. -/ theorem range_dualMap_mkQ_eq (W : Submodule R M) : LinearMap.range W.mkQ.dualMap = W.dualAnnihilator := by ext φ rw [LinearMap.mem_range] constructor · rintro ⟨ψ, rfl⟩ have := LinearMap.mem_range_self W.mkQ.dualMap ψ simpa only [ker_mkQ] using W.mkQ.range_dualMap_le_dualAnnihilator_ker this · intro hφ exists W.dualCopairing ⟨φ, hφ⟩ /-- Equivalence $(M/W)^* \cong \operatorname{ann}(W)$. That is, there is a one-to-one correspondence between the dual of `M ⧸ W` and those elements of the dual of `M` that vanish on `W`. The inverse of this is `Submodule.dualCopairing`. -/ def dualQuotEquivDualAnnihilator (W : Submodule R M) : Module.Dual R (M ⧸ W) ≃ₗ[R] W.dualAnnihilator := LinearEquiv.ofLinear (W.mkQ.dualMap.codRestrict W.dualAnnihilator fun φ => W.range_dualMap_mkQ_eq ▸ LinearMap.mem_range_self W.mkQ.dualMap φ) W.dualCopairing (by ext; rfl) (by ext; rfl) @[simp] theorem dualQuotEquivDualAnnihilator_apply (W : Submodule R M) (φ : Module.Dual R (M ⧸ W)) (x : M) : dualQuotEquivDualAnnihilator W φ x = φ (Quotient.mk x) := rfl theorem dualCopairing_eq (W : Submodule R M) : W.dualCopairing = (dualQuotEquivDualAnnihilator W).symm.toLinearMap := rfl @[simp] theorem dualQuotEquivDualAnnihilator_symm_apply_mk (W : Submodule R M) (φ : W.dualAnnihilator) (x : M) : (dualQuotEquivDualAnnihilator W).symm φ (Quotient.mk x) = φ x := rfl theorem finite_dualAnnihilator_iff {W : Submodule R M} [Free R (M ⧸ W)] : Module.Finite R W.dualAnnihilator ↔ Module.Finite R (M ⧸ W) := (Finite.equiv_iff W.dualQuotEquivDualAnnihilator.symm).trans (finite_dual_iff R) lemma dualAnnihilator_eq_bot_iff' {W : Submodule R M} : W.dualAnnihilator = ⊥ ↔ Subsingleton (Dual R (M ⧸ W)) := by rw [W.dualQuotEquivDualAnnihilator.toEquiv.subsingleton_congr, subsingleton_iff_eq_bot] @[simp] lemma dualAnnihilator_eq_bot_iff {W : Submodule R M} [Projective R (M ⧸ W)] : W.dualAnnihilator = ⊥ ↔ W = ⊤ := by rw [dualAnnihilator_eq_bot_iff', subsingleton_dual_iff, subsingleton_quotient_iff_eq_top] @[simp] lemma dualAnnihilator_eq_top_iff {W : Submodule R M} [Projective R M] : W.dualAnnihilator = ⊤ ↔ W = ⊥ := by refine ⟨fun h ↦ ?_, fun h ↦ h ▸ dualAnnihilator_bot⟩ refine W.eq_bot_iff.mpr fun v hv ↦ (forall_dual_apply_eq_zero_iff R v).mp fun f ↦ ?_ refine (mem_dualAnnihilator f).mp ?_ v hv simp [h] open LinearMap in /-- The pairing between a submodule `W` of a dual module `Dual R M` and the quotient of `M` by the coannihilator of `W`, which is always nondegenerate. -/ def quotDualCoannihilatorToDual (W : Submodule R (Dual R M)) : M ⧸ W.dualCoannihilator →ₗ[R] Dual R W := liftQ _ (flip <| Submodule.subtype _) le_rfl @[simp] theorem quotDualCoannihilatorToDual_apply (W : Submodule R (Dual R M)) (m : M) (w : W) : W.quotDualCoannihilatorToDual (Quotient.mk m) w = w.1 m := rfl theorem quotDualCoannihilatorToDual_injective (W : Submodule R (Dual R M)) : Function.Injective W.quotDualCoannihilatorToDual := LinearMap.ker_eq_bot.mp (ker_liftQ_eq_bot _ _ _ le_rfl) theorem flip_quotDualCoannihilatorToDual_injective (W : Submodule R (Dual R M)) : Function.Injective W.quotDualCoannihilatorToDual.flip := fun _ _ he ↦ Subtype.ext <| LinearMap.ext fun m ↦ DFunLike.congr_fun he ⟦m⟧ open LinearMap in theorem quotDualCoannihilatorToDual_nondegenerate (W : Submodule R (Dual R M)) : W.quotDualCoannihilatorToDual.Nondegenerate := by rw [Nondegenerate, separatingLeft_iff_ker_eq_bot, separatingRight_iff_flip_ker_eq_bot] letI : AddCommGroup W := inferInstance simp_rw [ker_eq_bot] exact ⟨W.quotDualCoannihilatorToDual_injective, W.flip_quotDualCoannihilatorToDual_injective⟩ end Submodule namespace LinearMap open Submodule theorem range_dualMap_eq_dualAnnihilator_ker_of_surjective (f : M →ₗ[R] M') (hf : Function.Surjective f) : LinearMap.range f.dualMap = (LinearMap.ker f).dualAnnihilator := ((f.quotKerEquivOfSurjective hf).dualMap.range_comp _).trans (LinearMap.ker f).range_dualMap_mkQ_eq -- Note, this can be specialized to the case where `R` is an injective `R`-module, or when -- `f.coker` is a projective `R`-module. theorem range_dualMap_eq_dualAnnihilator_ker_of_subtype_range_surjective (f : M →ₗ[R] M') (hf : Function.Surjective (range f).subtype.dualMap) : LinearMap.range f.dualMap = (ker f).dualAnnihilator := by have rr_surj : Function.Surjective f.rangeRestrict := by rw [← range_eq_top, range_rangeRestrict] have := range_dualMap_eq_dualAnnihilator_ker_of_surjective f.rangeRestrict rr_surj convert this using 1 · calc _ = range ((range f).subtype.comp f.rangeRestrict).dualMap := by simp _ = _ := ?_ rw [← dualMap_comp_dualMap, range_comp_of_range_eq_top] rwa [range_eq_top] · apply congr_arg exact (ker_rangeRestrict f).symm end LinearMap end CommRing section VectorSpace variable {K V₁ V₂ : Type*} [Field K] variable [AddCommGroup V₁] [Module K V₁] [AddCommGroup V₂] [Module K V₂] namespace Module.Dual variable {f : Module.Dual K V₁} section variable (hf : f ≠ 0) lemma range_eq_top_of_ne_zero {K V₁ : Type*} [Semifield K] [AddCommMonoid V₁] [Module K V₁] {f : Module.Dual K V₁} (hf : f ≠ 0) : LinearMap.range f = ⊤ := LinearMap.range_eq_top.mpr (LinearMap.surjective hf) variable [FiniteDimensional K V₁] include hf lemma finrank_ker_add_one_of_ne_zero : finrank K (LinearMap.ker f) + 1 = finrank K V₁ := by suffices finrank K (LinearMap.range f) = 1 by rw [← (LinearMap.ker f).finrank_quotient_add_finrank, add_comm, add_left_inj, f.quotKerEquivRange.finrank_eq, this] rw [range_eq_top_of_ne_zero hf, finrank_top, finrank_self] lemma isCompl_ker_of_disjoint_of_ne_bot {p : Submodule K V₁} (hpf : Disjoint (LinearMap.ker f) p) (hp : p ≠ ⊥) : IsCompl (LinearMap.ker f) p := by refine ⟨hpf, codisjoint_iff.mpr <| eq_of_le_of_finrank_le le_top ?_⟩ have : finrank K ↑(LinearMap.ker f ⊔ p) = finrank K (LinearMap.ker f) + finrank K p := by simp [← Submodule.finrank_sup_add_finrank_inf_eq (LinearMap.ker f) p, hpf.eq_bot] rwa [finrank_top, this, ← finrank_ker_add_one_of_ne_zero hf, add_le_add_iff_left, Submodule.one_le_finrank_iff] end lemma eq_of_ker_eq_of_apply_eq [FiniteDimensional K V₁] {f g : Module.Dual K V₁} (x : V₁) (h : LinearMap.ker f = LinearMap.ker g) (h' : f x = g x) (hx : f x ≠ 0) : f = g := by let p := K ∙ x have hp : p ≠ ⊥ := by aesop have hpf : Disjoint (LinearMap.ker f) p := by rw [disjoint_iff, Submodule.eq_bot_iff] rintro y ⟨hfy : f y = 0, hpy : y ∈ p⟩ obtain ⟨t, rfl⟩ := Submodule.mem_span_singleton.mp hpy have ht : t = 0 := by simpa [hx] using hfy simp [ht] have hf : f ≠ 0 := by aesop ext v obtain ⟨y, hy, z, hz, rfl⟩ : ∃ᵉ (y ∈ LinearMap.ker f) (z ∈ p), y + z = v := by have : v ∈ (⊤ : Submodule K V₁) := Submodule.mem_top rwa [← (isCompl_ker_of_disjoint_of_ne_bot hf hpf hp).sup_eq_top, Submodule.mem_sup] at this have hy' : g y = 0 := by rwa [← LinearMap.mem_ker, ← h] replace hy : f y = 0 := by rwa [LinearMap.mem_ker] at hy obtain ⟨t, rfl⟩ := Submodule.mem_span_singleton.mp hz simp [h', hy, hy'] end Module.Dual namespace LinearMap theorem dualPairing_nondegenerate : (dualPairing K V₁).Nondegenerate := ⟨separatingLeft_iff_ker_eq_bot.mpr ker_id, fun x => (forall_dual_apply_eq_zero_iff K x).mp⟩ theorem dualMap_surjective_of_injective {f : V₁ →ₗ[K] V₂} (hf : Function.Injective f) : Function.Surjective f.dualMap := fun φ ↦ have ⟨f', hf'⟩ := f.exists_leftInverse_of_injective (ker_eq_bot.mpr hf) ⟨φ.comp f', ext fun x ↦ congr(φ <| $hf' x)⟩ theorem range_dualMap_eq_dualAnnihilator_ker (f : V₁ →ₗ[K] V₂) : LinearMap.range f.dualMap = (LinearMap.ker f).dualAnnihilator := range_dualMap_eq_dualAnnihilator_ker_of_subtype_range_surjective f <| dualMap_surjective_of_injective (range f).injective_subtype /-- For vector spaces, `f.dualMap` is surjective if and only if `f` is injective -/ @[simp] theorem dualMap_surjective_iff {f : V₁ →ₗ[K] V₂} : Function.Surjective f.dualMap ↔ Function.Injective f := by rw [← LinearMap.range_eq_top, range_dualMap_eq_dualAnnihilator_ker, ← Submodule.dualAnnihilator_bot, Subspace.dualAnnihilator_inj, LinearMap.ker_eq_bot] end LinearMap namespace Subspace open Submodule theorem dualPairing_eq (W : Subspace K V₁) : W.dualPairing = W.quotAnnihilatorEquiv.toLinearMap := by ext rfl theorem dualPairing_nondegenerate (W : Subspace K V₁) : W.dualPairing.Nondegenerate := by constructor · rw [LinearMap.separatingLeft_iff_ker_eq_bot, dualPairing_eq] apply LinearEquiv.ker · intro x h rw [← forall_dual_apply_eq_zero_iff K x] intro φ simpa only [Submodule.dualPairing_apply, dualLift_of_subtype] using h (Submodule.Quotient.mk (W.dualLift φ)) theorem dualCopairing_nondegenerate (W : Subspace K V₁) : W.dualCopairing.Nondegenerate := by constructor · rw [LinearMap.separatingLeft_iff_ker_eq_bot, dualCopairing_eq] apply LinearEquiv.ker · rintro ⟨x⟩ simp only [Quotient.quot_mk_eq_mk, dualCopairing_apply, Quotient.mk_eq_zero] rw [← forall_mem_dualAnnihilator_apply_eq_zero_iff, SetLike.forall] exact id -- Argument from https://math.stackexchange.com/a/2423263/172988 theorem dualAnnihilator_inf_eq (W W' : Subspace K V₁) : (W ⊓ W').dualAnnihilator = W.dualAnnihilator ⊔ W'.dualAnnihilator := by refine le_antisymm ?_ (sup_dualAnnihilator_le_inf W W') let F : V₁ →ₗ[K] (V₁ ⧸ W) × V₁ ⧸ W' := (Submodule.mkQ W).prod (Submodule.mkQ W') have : LinearMap.ker F = W ⊓ W' := by simp only [F, LinearMap.ker_prod, ker_mkQ] rw [← this, ← LinearMap.range_dualMap_eq_dualAnnihilator_ker] intro φ rw [LinearMap.mem_range] rintro ⟨x, rfl⟩ rw [Submodule.mem_sup] obtain ⟨⟨a, b⟩, rfl⟩ := (dualProdDualEquivDual K (V₁ ⧸ W) (V₁ ⧸ W')).surjective x obtain ⟨a', rfl⟩ := (dualQuotEquivDualAnnihilator W).symm.surjective a obtain ⟨b', rfl⟩ := (dualQuotEquivDualAnnihilator W').symm.surjective b use a', a'.property, b', b'.property rfl -- This is also true if `V₁` is finite dimensional since one can restrict `ι` to some subtype -- for which the infimum and supremum are the same. -- The obstruction to the `dualAnnihilator_inf_eq` argument carrying through is that we need -- for `Module.Dual R (Π (i : ι), V ⧸ W i) ≃ₗ[K] Π (i : ι), Module.Dual R (V ⧸ W i)`, which is not -- true for infinite `ι`. One would need to add additional hypothesis on `W` (for example, it might -- be true when the family is inf-closed). -- TODO: generalize to `Sort` theorem dualAnnihilator_iInf_eq {ι : Type*} [Finite ι] (W : ι → Subspace K V₁) : (⨅ i : ι, W i).dualAnnihilator = ⨆ i : ι, (W i).dualAnnihilator := by revert ι apply Finite.induction_empty_option · intro α β h hyp W rw [← h.iInf_comp, hyp _, ← h.iSup_comp] · intro W rw [iSup_of_empty', iInf_of_isEmpty, sInf_empty, sSup_empty, dualAnnihilator_top] · intro α _ h W rw [iInf_option, iSup_option, dualAnnihilator_inf_eq, h] /-- For vector spaces, dual annihilators carry direct sum decompositions to direct sum decompositions. -/ theorem isCompl_dualAnnihilator {W W' : Subspace K V₁} (h : IsCompl W W') : IsCompl W.dualAnnihilator W'.dualAnnihilator := by rw [isCompl_iff, disjoint_iff, codisjoint_iff] at h ⊢ rw [← dualAnnihilator_inf_eq, ← dualAnnihilator_sup_eq, h.1, h.2, dualAnnihilator_top, dualAnnihilator_bot] exact ⟨rfl, rfl⟩ /-- For finite-dimensional vector spaces, one can distribute duals over quotients by identifying `W.dualLift.range` with `W`. Note that this depends on a choice of splitting of `V₁`. -/ def dualQuotDistrib [FiniteDimensional K V₁] (W : Subspace K V₁) : Module.Dual K (V₁ ⧸ W) ≃ₗ[K] Module.Dual K V₁ ⧸ LinearMap.range W.dualLift := W.dualQuotEquivDualAnnihilator.trans W.quotDualEquivAnnihilator.symm end Subspace section FiniteDimensional open Module LinearMap namespace LinearMap @[simp] theorem finrank_range_dualMap_eq_finrank_range (f : V₁ →ₗ[K] V₂) : finrank K (LinearMap.range f.dualMap) = finrank K (LinearMap.range f) := by rw [congr_arg dualMap (show f = (range f).subtype.comp f.rangeRestrict by rfl), ← dualMap_comp_dualMap, range_comp, range_eq_top.mpr (dualMap_surjective_of_injective (range f).injective_subtype), Submodule.map_top, finrank_range_of_inj, Subspace.dual_finrank_eq] exact dualMap_injective_of_surjective (range_eq_top.mp f.range_rangeRestrict) /-- `f.dualMap` is injective if and only if `f` is surjective -/ @[simp] theorem dualMap_injective_iff {f : V₁ →ₗ[K] V₂} : Function.Injective f.dualMap ↔ Function.Surjective f := by refine ⟨Function.mtr fun not_surj inj ↦ ?_, dualMap_injective_of_surjective⟩ rw [← range_eq_top, ← Ne, ← lt_top_iff_ne_top] at not_surj obtain ⟨φ, φ0, range_le_ker⟩ := (range f).exists_le_ker_of_lt_top not_surj exact φ0 (inj <| ext fun x ↦ range_le_ker ⟨x, rfl⟩) /-- `f.dualMap` is bijective if and only if `f` is -/ @[simp] theorem dualMap_bijective_iff {f : V₁ →ₗ[K] V₂} : Function.Bijective f.dualMap ↔ Function.Bijective f := by simp_rw [Function.Bijective, dualMap_surjective_iff, dualMap_injective_iff, and_comm] variable {B : V₁ →ₗ[K] V₂ →ₗ[K] K} @[simp] lemma dualAnnihilator_ker_eq_range_flip [IsReflexive K V₂] : (ker B).dualAnnihilator = range B.flip := by change _ = range (B.dualMap.comp (Module.evalEquiv K V₂).toLinearMap) rw [← range_dualMap_eq_dualAnnihilator_ker, range_comp_of_range_eq_top _ (LinearEquiv.range _)] open Function theorem flip_injective_iff₁ [FiniteDimensional K V₁] : Injective B.flip ↔ Surjective B := by rw [← dualMap_surjective_iff, ← (evalEquiv K V₁).toEquiv.surjective_comp]; rfl theorem flip_injective_iff₂ [FiniteDimensional K V₂] : Injective B.flip ↔ Surjective B := by rw [← dualMap_injective_iff]; exact (evalEquiv K V₂).toEquiv.injective_comp B.dualMap theorem flip_surjective_iff₁ [FiniteDimensional K V₁] : Surjective B.flip ↔ Injective B := flip_injective_iff₂.symm theorem flip_surjective_iff₂ [FiniteDimensional K V₂] : Surjective B.flip ↔ Injective B := flip_injective_iff₁.symm theorem flip_bijective_iff₁ [FiniteDimensional K V₁] : Bijective B.flip ↔ Bijective B := by simp_rw [Bijective, flip_injective_iff₁, flip_surjective_iff₁, and_comm] theorem flip_bijective_iff₂ [FiniteDimensional K V₂] : Bijective B.flip ↔ Bijective B := flip_bijective_iff₁.symm end LinearMap namespace Subspace variable {K V : Type*} [Field K] [AddCommGroup V] [Module K V] theorem quotDualCoannihilatorToDual_bijective (W : Subspace K (Dual K V)) [FiniteDimensional K W] : Function.Bijective W.quotDualCoannihilatorToDual := ⟨W.quotDualCoannihilatorToDual_injective, letI : AddCommGroup W := inferInstance flip_injective_iff₂.mp W.flip_quotDualCoannihilatorToDual_injective⟩ theorem flip_quotDualCoannihilatorToDual_bijective (W : Subspace K (Dual K V)) [FiniteDimensional K W] : Function.Bijective W.quotDualCoannihilatorToDual.flip := letI : AddCommGroup W := inferInstance flip_bijective_iff₂.mpr W.quotDualCoannihilatorToDual_bijective theorem dualCoannihilator_dualAnnihilator_eq {W : Subspace K (Dual K V)} [FiniteDimensional K W] : W.dualCoannihilator.dualAnnihilator = W := let e := (LinearEquiv.ofBijective _ W.flip_quotDualCoannihilatorToDual_bijective).trans (Submodule.dualQuotEquivDualAnnihilator _) letI : AddCommGroup W := inferInstance haveI : FiniteDimensional K W.dualCoannihilator.dualAnnihilator := LinearEquiv.finiteDimensional e (eq_of_le_of_finrank_eq W.le_dualCoannihilator_dualAnnihilator e.finrank_eq).symm theorem finiteDimensional_quot_dualCoannihilator_iff {W : Submodule K (Dual K V)} : FiniteDimensional K (V ⧸ W.dualCoannihilator) ↔ FiniteDimensional K W := ⟨fun _ ↦ FiniteDimensional.of_injective _ W.flip_quotDualCoannihilatorToDual_injective, fun _ ↦ FiniteDimensional.of_injective _ W.quotDualCoannihilatorToDual_injective⟩ open OrderDual in /-- For any vector space, `dualAnnihilator` and `dualCoannihilator` gives an antitone order isomorphism between the finite-codimensional subspaces in the vector space and the finite-dimensional subspaces in its dual. -/ def orderIsoFiniteCodimDim : {W : Subspace K V // FiniteDimensional K (V ⧸ W)} ≃o {W : Subspace K (Dual K V) // FiniteDimensional K W}ᵒᵈ where toFun W := toDual ⟨W.1.dualAnnihilator, Submodule.finite_dualAnnihilator_iff.mpr W.2⟩ invFun W := ⟨(ofDual W).1.dualCoannihilator, finiteDimensional_quot_dualCoannihilator_iff.mpr (ofDual W).2⟩ left_inv _ := Subtype.ext dualAnnihilator_dualCoannihilator_eq right_inv W := have := (ofDual W).2; Subtype.ext dualCoannihilator_dualAnnihilator_eq map_rel_iff' := dualAnnihilator_le_dualAnnihilator_iff open OrderDual in /-- For any finite-dimensional vector space, `dualAnnihilator` and `dualCoannihilator` give an antitone order isomorphism between the subspaces in the vector space and the subspaces in its dual. -/ def orderIsoFiniteDimensional [FiniteDimensional K V] : Subspace K V ≃o (Subspace K (Dual K V))ᵒᵈ where toFun W := toDual W.dualAnnihilator invFun W := (ofDual W).dualCoannihilator left_inv _ := dualAnnihilator_dualCoannihilator_eq right_inv _ := dualCoannihilator_dualAnnihilator_eq map_rel_iff' := dualAnnihilator_le_dualAnnihilator_iff open Submodule in theorem dualAnnihilator_dualAnnihilator_eq_map (W : Subspace K V) [FiniteDimensional K W] : W.dualAnnihilator.dualAnnihilator = W.map (Dual.eval K V) := by let e1 := (Free.chooseBasis K W).toDualEquiv ≪≫ₗ W.quotAnnihilatorEquiv.symm haveI := e1.finiteDimensional let e2 := (Free.chooseBasis K _).toDualEquiv ≪≫ₗ W.dualAnnihilator.dualQuotEquivDualAnnihilator haveI := LinearEquiv.finiteDimensional (V₂ := W.dualAnnihilator.dualAnnihilator) e2 rw [eq_of_le_of_finrank_eq (map_le_dualAnnihilator_dualAnnihilator W)] rw [← (equivMapOfInjective _ (eval_apply_injective K (V := V)) W).finrank_eq, e1.finrank_eq] exact e2.finrank_eq theorem map_dualCoannihilator (W : Subspace K (Dual K V)) [FiniteDimensional K V] : W.dualCoannihilator.map (Dual.eval K V) = W.dualAnnihilator := by rw [← dualAnnihilator_dualAnnihilator_eq_map, dualCoannihilator_dualAnnihilator_eq] end Subspace end FiniteDimensional end VectorSpace theorem span_flip_eq_top_iff_linearIndependent {ι α F} [Finite ι] [Field F] {f : ι → α → F} : span F (Set.range <| flip f) = ⊤ ↔ LinearIndependent F f := by rw [linearIndependent_iff_ker, ← Submodule.map_eq_top_iff (e := Finsupp.llift F F F ι), ← Subspace.dualCoannihilator_dualAnnihilator_eq (W := map ..), dualAnnihilator_eq_top_iff] congr! rw [SetLike.ext'_iff, map_span, Submodule.coe_dualCoannihilator_span, ← Set.range_comp] ext simp [funext_iff, Finsupp.linearCombination, Finsupp.sum, Finset.sum_apply, flip] namespace TensorProduct variable (R A : Type*) (M : Type*) (N : Type*) variable {ι κ : Type*} variable [DecidableEq ι] [DecidableEq κ] variable [Fintype ι] [Fintype κ] open TensorProduct attribute [local ext] TensorProduct.ext open TensorProduct open LinearMap section variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] variable [Module R M] [Module R N] /-- The canonical linear map from `Dual M ⊗ Dual N` to `Dual (M ⊗ N)`, sending `f ⊗ g` to the composition of `TensorProduct.map f g` with the natural isomorphism `R ⊗ R ≃ R`. -/ def dualDistrib : Dual R M ⊗[R] Dual R N →ₗ[R] Dual R (M ⊗[R] N) := compRight _ (TensorProduct.lid R R) ∘ₗ homTensorHomMap (.id R) M N R R variable {R M N} @[simp] theorem dualDistrib_apply (f : Dual R M) (g : Dual R N) (m : M) (n : N) : dualDistrib R M N (f ⊗ₜ g) (m ⊗ₜ n) = f m * g n := rfl end namespace AlgebraTensorModule variable [CommSemiring R] [CommSemiring A] [Algebra R A] [AddCommMonoid M] [AddCommMonoid N] variable [Module R M] [Module A M] [Module R N] [IsScalarTower R A M] /-- Heterobasic version of `TensorProduct.dualDistrib` -/ def dualDistrib : Dual A M ⊗[R] Dual R N →ₗ[A] Dual A (M ⊗[R] N) := compRight _ (Algebra.TensorProduct.rid R A A).toLinearMap ∘ₗ homTensorHomMap R A A M N A R variable {R M N} @[simp] theorem dualDistrib_apply (f : Dual A M) (g : Dual R N) (m : M) (n : N) : dualDistrib R A M N (f ⊗ₜ g) (m ⊗ₜ n) = g n • f m := rfl end AlgebraTensorModule variable {R M N} variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] variable [Module R M] [Module R N] /-- An inverse to `TensorProduct.dualDistrib` given bases. -/ noncomputable def dualDistribInvOfBasis (b : Basis ι R M) (c : Basis κ R N) : Dual R (M ⊗[R] N) →ₗ[R] Dual R M ⊗[R] Dual R N := ∑ i, ∑ j, (ringLmapEquivSelf R ℕ _).symm (b.dualBasis i ⊗ₜ c.dualBasis j) ∘ₗ applyₗ (c j) ∘ₗ applyₗ (b i) ∘ₗ lcurry (.id R) M N R @[simp] theorem dualDistribInvOfBasis_apply (b : Basis ι R M) (c : Basis κ R N) (f : Dual R (M ⊗[R] N)) : dualDistribInvOfBasis b c f = ∑ i, ∑ j, f (b i ⊗ₜ c j) • b.dualBasis i ⊗ₜ c.dualBasis j := by simp [dualDistribInvOfBasis] theorem dualDistrib_dualDistribInvOfBasis_left_inverse (b : Basis ι R M) (c : Basis κ R N) : comp (dualDistrib R M N) (dualDistribInvOfBasis b c) = LinearMap.id := by apply (b.tensorProduct c).dualBasis.ext rintro ⟨i, j⟩ apply (b.tensorProduct c).ext rintro ⟨i', j'⟩ simp only [dualDistrib, Basis.coe_dualBasis, coe_comp, Function.comp_apply, dualDistribInvOfBasis_apply, Basis.coord_apply, Basis.tensorProduct_repr_tmul_apply, Basis.repr_self, _root_.map_sum, map_smul, homTensorHomMap_apply, compRight_apply, Basis.tensorProduct_apply, coeFn_sum, Finset.sum_apply, smul_apply, LinearEquiv.coe_coe, map_tmul, lid_tmul, smul_eq_mul, id_coe, id_eq] rw [Finset.sum_eq_single i, Finset.sum_eq_single j] · simpa using mul_comm _ _ all_goals { intros; simp [*] at * } theorem dualDistrib_dualDistribInvOfBasis_right_inverse (b : Basis ι R M) (c : Basis κ R N) : comp (dualDistribInvOfBasis b c) (dualDistrib R M N) = LinearMap.id := by apply (b.dualBasis.tensorProduct c.dualBasis).ext rintro ⟨i, j⟩ simp only [Basis.tensorProduct_apply, Basis.coe_dualBasis, coe_comp, Function.comp_apply, dualDistribInvOfBasis_apply, dualDistrib_apply, Basis.coord_apply, Basis.repr_self, id_coe, id_eq] rw [Finset.sum_eq_single i, Finset.sum_eq_single j] · simp all_goals { intros; simp [*] at * } /-- A linear equivalence between `Dual M ⊗ Dual N` and `Dual (M ⊗ N)` given bases for `M` and `N`. It sends `f ⊗ g` to the composition of `TensorProduct.map f g` with the natural isomorphism `R ⊗ R ≃ R`. -/ @[simps!] noncomputable def dualDistribEquivOfBasis (b : Basis ι R M) (c : Basis κ R N) : Dual R M ⊗[R] Dual R N ≃ₗ[R] Dual R (M ⊗[R] N) := by refine LinearEquiv.ofLinear (dualDistrib R M N) (dualDistribInvOfBasis b c) ?_ ?_ · exact dualDistrib_dualDistribInvOfBasis_left_inverse _ _ · exact dualDistrib_dualDistribInvOfBasis_right_inverse _ _ variable (R M N) variable [Module.Finite R M] [Module.Finite R N] [Module.Free R M] [Module.Free R N] /-- A linear equivalence between `Dual M ⊗ Dual N` and `Dual (M ⊗ N)` when `M` and `N` are finite free modules. It sends `f ⊗ g` to the composition of `TensorProduct.map f g` with the natural isomorphism `R ⊗ R ≃ R`. -/ @[simp] noncomputable def dualDistribEquiv : Dual R M ⊗[R] Dual R N ≃ₗ[R] Dual R (M ⊗[R] N) := dualDistribEquivOfBasis (Module.Free.chooseBasis R M) (Module.Free.chooseBasis R N) end TensorProduct
.lake/packages/mathlib/Mathlib/LinearAlgebra/Dual/Defs.lean
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.LinearAlgebra.BilinearMap import Mathlib.LinearAlgebra.Span.Defs /-! # Dual vector spaces The dual space of an $R$-module $M$ is the $R$-module of $R$-linear maps $M \to R$. ## Main definitions * Duals and transposes: * `Module.Dual R M` defines the dual space of the `R`-module `M`, as `M →ₗ[R] R`. * `Module.dualPairing R M` is the canonical pairing between `Dual R M` and `M`. * `Module.Dual.eval R M : M →ₗ[R] Dual R (Dual R)` is the canonical map to the double dual. * `Module.Dual.transpose` is the linear map from `M →ₗ[R] M'` to `Dual R M' →ₗ[R] Dual R M`. * `LinearMap.dualMap` is `Module.Dual.transpose` of a given linear map, for dot notation. * `LinearEquiv.dualMap` is for the dual of an equivalence. * Submodules: * `Submodule.dualRestrict W` is the transpose `Dual R M →ₗ[R] Dual R W` of the inclusion map. * `Submodule.dualAnnihilator W` is the kernel of `W.dualRestrict`. That is, it is the submodule of `dual R M` whose elements all annihilate `W`. * `Submodule.dualPairing W` is the canonical pairing between `Dual R M ⧸ W.dualAnnihilator` and `W`. It is nondegenerate for vector spaces (`Subspace.dualPairing_nondegenerate`). ## Main results * Annihilators: * `Module.dualAnnihilator_gc R M` is the antitone Galois correspondence between `Submodule.dualAnnihilator` and `Submodule.dualCoannihilator`. * Finite-dimensional vector spaces: * `Module.evalEquiv` is the equivalence `V ≃ₗ[K] Dual K (Dual K V)` * `Module.mapEvalEquiv` is the order isomorphism between subspaces of `V` and subspaces of `Dual K (Dual K V)`. -/ open Module Submodule noncomputable section namespace Module variable (R A M : Type*) variable [CommSemiring R] [AddCommMonoid M] [Module R M] /-- The left dual space of an R-module M is the R-module of linear maps `M → R`. -/ abbrev Dual (R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] := M →ₗ[R] R /-- The canonical pairing of a vector space and its algebraic dual. -/ def dualPairing (R M) [CommSemiring R] [AddCommMonoid M] [Module R M] : Module.Dual R M →ₗ[R] M →ₗ[R] R := LinearMap.id @[simp] theorem dualPairing_apply (v x) : dualPairing R M v x = v x := rfl namespace Dual instance (R : Type*) [Semiring R] [Module R M] : Inhabited (Dual R M) := ⟨0⟩ /-- Maps a module M to the dual of the dual of M. See `Module.erange_coe` and `Module.evalEquiv`. -/ def eval : M →ₗ[R] Dual R (Dual R M) := LinearMap.flip LinearMap.id @[simp] theorem eval_apply (v : M) (a : Dual R M) : eval R M v a = a v := rfl variable {R M} {M' : Type*} variable [AddCommMonoid M'] [Module R M'] /-- The transposition of linear maps, as a linear map from `M →ₗ[R] M'` to `Dual R M' →ₗ[R] Dual R M`. -/ def transpose : (M →ₗ[R] M') →ₗ[R] Dual R M' →ₗ[R] Dual R M := (LinearMap.llcomp R M M' R).flip theorem transpose_apply (u : M →ₗ[R] M') (l : Dual R M') : transpose u l = l.comp u := rfl variable {M'' : Type*} [AddCommMonoid M''] [Module R M''] theorem transpose_comp (u : M' →ₗ[R] M'') (v : M →ₗ[R] M') : transpose (u.comp v) = (transpose v).comp (transpose u) := rfl end Dual end Module section DualMap open Module variable {R M₁ M₂ : Type*} [CommSemiring R] variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] /-- Given a linear map `f : M₁ →ₗ[R] M₂`, `f.dualMap` is the linear map between the dual of `M₂` and `M₁` such that it maps the functional `φ` to `φ ∘ f`. -/ def LinearMap.dualMap (f : M₁ →ₗ[R] M₂) : Dual R M₂ →ₗ[R] Dual R M₁ := Module.Dual.transpose f lemma LinearMap.dualMap_eq_lcomp (f : M₁ →ₗ[R] M₂) : f.dualMap = f.lcomp R R := rfl theorem LinearMap.dualMap_def (f : M₁ →ₗ[R] M₂) : f.dualMap = Module.Dual.transpose f := rfl theorem LinearMap.dualMap_apply' (f : M₁ →ₗ[R] M₂) (g : Dual R M₂) : f.dualMap g = g.comp f := rfl @[simp] theorem LinearMap.dualMap_apply (f : M₁ →ₗ[R] M₂) (g : Dual R M₂) (x : M₁) : f.dualMap g x = g (f x) := rfl @[simp] theorem LinearMap.dualMap_id : (LinearMap.id : M₁ →ₗ[R] M₁).dualMap = LinearMap.id := by ext rfl theorem LinearMap.dualMap_comp_dualMap {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (f : M₁ →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : f.dualMap.comp g.dualMap = (g.comp f).dualMap := rfl /-- If a linear map is surjective, then its dual is injective. -/ theorem LinearMap.dualMap_injective_of_surjective {f : M₁ →ₗ[R] M₂} (hf : Function.Surjective f) : Function.Injective f.dualMap := by intro φ ψ h ext x obtain ⟨y, rfl⟩ := hf x exact congr_arg (fun g : Module.Dual R M₁ => g y) h /-- The `LinearEquiv` version of `LinearMap.dualMap`. -/ def LinearEquiv.dualMap (f : M₁ ≃ₗ[R] M₂) : Dual R M₂ ≃ₗ[R] Dual R M₁ where __ := f.toLinearMap.dualMap invFun := f.symm.toLinearMap.dualMap left_inv φ := LinearMap.ext fun x ↦ congr_arg φ (f.right_inv x) right_inv φ := LinearMap.ext fun x ↦ congr_arg φ (f.left_inv x) @[simp] theorem LinearEquiv.dualMap_apply (f : M₁ ≃ₗ[R] M₂) (g : Dual R M₂) (x : M₁) : f.dualMap g x = g (f x) := rfl @[simp] theorem LinearEquiv.dualMap_refl : (LinearEquiv.refl R M₁).dualMap = LinearEquiv.refl R (Dual R M₁) := by ext rfl @[simp] theorem LinearEquiv.dualMap_symm {f : M₁ ≃ₗ[R] M₂} : (LinearEquiv.dualMap f).symm = LinearEquiv.dualMap f.symm := rfl theorem LinearEquiv.dualMap_trans {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (f : M₁ ≃ₗ[R] M₂) (g : M₂ ≃ₗ[R] M₃) : g.dualMap.trans f.dualMap = (f.trans g).dualMap := rfl theorem Module.Dual.eval_naturality (f : M₁ →ₗ[R] M₂) : f.dualMap.dualMap ∘ₗ eval R M₁ = eval R M₂ ∘ₗ f := by rfl @[simp] lemma Dual.apply_one_mul_eq (f : Dual R R) (r : R) : f 1 * r = f r := by conv_rhs => rw [← mul_one r, ← smul_eq_mul] rw [map_smul, smul_eq_mul, mul_comm] @[simp] lemma LinearMap.range_dualMap_dual_eq_span_singleton (f : Dual R M₁) : range f.dualMap = R ∙ f := by ext m rw [Submodule.mem_span_singleton] refine ⟨fun ⟨r, hr⟩ ↦ ⟨r 1, ?_⟩, fun ⟨r, hr⟩ ↦ ⟨r • LinearMap.id, ?_⟩⟩ · ext; simp [dualMap_apply', ← hr] · ext; simp [dualMap_apply', ← hr] end DualMap namespace Module variable {K V : Type*} variable [CommSemiring K] [AddCommMonoid V] [Module K V] open Module Module.Dual Submodule LinearMap Module section IsReflexive open Function variable (R M N : Type*) variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] /-- A reflexive module is one for which the natural map to its double dual is a bijection. Any finitely-generated projective module (and thus any finite-dimensional vector space) is reflexive. See `Module.instIsReflexiveOfFiniteOfProjective`. -/ class IsReflexive : Prop where /-- A reflexive module is one for which the natural map to its double dual is a bijection. -/ bijective_dual_eval' : Bijective (Dual.eval R M) lemma bijective_dual_eval [IsReflexive R M] : Bijective (Dual.eval R M) := IsReflexive.bijective_dual_eval' variable [IsReflexive R M] theorem erange_coe : LinearMap.range (eval R M) = ⊤ := range_eq_top.mpr (bijective_dual_eval _ _).2 /-- The bijection between a reflexive module and its double dual, bundled as a `LinearEquiv`. -/ def evalEquiv : M ≃ₗ[R] Dual R (Dual R M) := LinearEquiv.ofBijective _ (bijective_dual_eval R M) @[simp] lemma evalEquiv_toLinearMap : evalEquiv R M = Dual.eval R M := rfl @[simp] lemma evalEquiv_apply (m : M) : evalEquiv R M m = Dual.eval R M m := rfl @[simp] lemma apply_evalEquiv_symm_apply (f : Dual R M) (g : Dual R (Dual R M)) : f ((evalEquiv R M).symm g) = g f := by set m := (evalEquiv R M).symm g rw [← (evalEquiv R M).apply_symm_apply g, evalEquiv_apply, Dual.eval_apply] @[simp] lemma symm_dualMap_evalEquiv : (evalEquiv R M).symm.dualMap = Dual.eval R (Dual R M) := by ext; simp @[simp] lemma Dual.eval_comp_comp_evalEquiv_eq {M' : Type*} [AddCommMonoid M'] [Module R M'] {f : M →ₗ[R] M'} : Dual.eval R M' ∘ₗ f ∘ₗ (evalEquiv R M).symm = f.dualMap.dualMap := by rw [← LinearMap.comp_assoc, LinearEquiv.comp_toLinearMap_symm_eq, evalEquiv_toLinearMap, eval_naturality] lemma dualMap_dualMap_eq_iff_of_injective {M' : Type*} [AddCommMonoid M'] [Module R M'] {f g : M →ₗ[R] M'} (h : Injective (Dual.eval R M')) : f.dualMap.dualMap = g.dualMap.dualMap ↔ f = g := by simp only [← Dual.eval_comp_comp_evalEquiv_eq] refine ⟨fun hfg => ?_, fun a ↦ congrArg (Dual.eval R M').comp (congrFun (congrArg LinearMap.comp a) (evalEquiv R M).symm.toLinearMap)⟩ rw [propext (cancel_left h), LinearEquiv.eq_comp_toLinearMap_iff] at hfg exact hfg @[simp] lemma dualMap_dualMap_eq_iff {M' : Type*} [AddCommMonoid M'] [Module R M'] [IsReflexive R M'] {f g : M →ₗ[R] M'} : f.dualMap.dualMap = g.dualMap.dualMap ↔ f = g := dualMap_dualMap_eq_iff_of_injective _ _ (bijective_dual_eval R M').injective /-- The dual of a reflexive module is reflexive. -/ instance Dual.instIsReflecive : IsReflexive R (Dual R M) := ⟨by simpa only [← symm_dualMap_evalEquiv] using (evalEquiv R M).dualMap.symm.bijective⟩ variable {R M N} in /-- A direct summand of a reflexive module is reflexive. -/ lemma IsReflexive.of_split (i : N →ₗ[R] M) (s : M →ₗ[R] N) (H : s ∘ₗ i = .id) : IsReflexive R N where bijective_dual_eval' := ⟨.of_comp (f := i.dualMap.dualMap) <| (bijective_dual_eval R M).1.comp (injective_of_comp_eq_id i _ H), .of_comp (g := s) <| (surjective_of_comp_eq_id i.dualMap.dualMap s.dualMap.dualMap <| congr_arg (dualMap ∘ dualMap) H).comp (bijective_dual_eval R M).2⟩ /-- The isomorphism `Module.evalEquiv` induces an order isomorphism on subspaces. -/ def mapEvalEquiv : Submodule R M ≃o Submodule R (Dual R (Dual R M)) := Submodule.orderIsoMapComap (evalEquiv R M) @[simp] theorem mapEvalEquiv_apply (W : Submodule R M) : mapEvalEquiv R M W = W.map (Dual.eval R M) := rfl @[simp] theorem mapEvalEquiv_symm_apply (W'' : Submodule R (Dual R (Dual R M))) : (mapEvalEquiv R M).symm W'' = W''.comap (Dual.eval R M) := rfl variable {R M N} in lemma equiv (e : M ≃ₗ[R] N) : IsReflexive R N where bijective_dual_eval' := by let ed : Dual R (Dual R N) ≃ₗ[R] Dual R (Dual R M) := e.symm.dualMap.dualMap have : Dual.eval R N = ed.symm.comp ((Dual.eval R M).comp e.symm.toLinearMap) := by ext m f exact DFunLike.congr_arg f (e.apply_symm_apply m).symm simp only [this, coe_comp, LinearEquiv.coe_coe, EquivLike.comp_bijective] exact Bijective.comp (bijective_dual_eval R M) (LinearEquiv.bijective _) instance _root_.MulOpposite.instModuleIsReflexive : IsReflexive R (MulOpposite M) := equiv <| MulOpposite.opLinearEquiv _ -- see Note [lower instance priority] instance (priority := 100) [IsDomain R] : NoZeroSMulDivisors R M := by refine (noZeroSMulDivisors_iff R M).mpr ?_ intro r m hrm rw [or_iff_not_imp_left] intro hr suffices Dual.eval R M m = Dual.eval R M 0 from (bijective_dual_eval R M).injective this ext n simp only [Dual.eval_apply, map_zero, LinearMap.zero_apply] suffices r • n m = 0 from eq_zero_of_ne_zero_of_mul_left_eq_zero hr this rw [← LinearMap.map_smul_of_tower, hrm, LinearMap.map_zero] end IsReflexive end Module namespace Submodule variable {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] variable {W : Submodule R M} /-- The `dualRestrict` of a submodule `W` of `M` is the linear map from the dual of `M` to the dual of `W` such that the domain of each linear map is restricted to `W`. -/ def dualRestrict (W : Submodule R M) : Module.Dual R M →ₗ[R] Module.Dual R W := LinearMap.domRestrict' W theorem dualRestrict_def (W : Submodule R M) : W.dualRestrict = W.subtype.dualMap := rfl @[simp] theorem dualRestrict_apply (W : Submodule R M) (φ : Module.Dual R M) (x : W) : W.dualRestrict φ x = φ (x : M) := rfl /-- The `dualAnnihilator` of a submodule `W` is the set of linear maps `φ` such that `φ w = 0` for all `w ∈ W`. -/ def dualAnnihilator {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] (W : Submodule R M) : Submodule R <| Module.Dual R M := LinearMap.ker W.dualRestrict @[simp] theorem mem_dualAnnihilator (φ : Module.Dual R M) : φ ∈ W.dualAnnihilator ↔ ∀ w ∈ W, φ w = 0 := by simp_rw [dualAnnihilator, LinearMap.mem_ker, LinearMap.ext_iff, dualRestrict_apply, Subtype.forall, LinearMap.zero_apply] /-- That $\operatorname{ker}(\iota^* : V^* \to W^*) = \operatorname{ann}(W)$. This is the definition of the dual annihilator of the submodule $W$. -/ theorem dualRestrict_ker_eq_dualAnnihilator (W : Submodule R M) : LinearMap.ker W.dualRestrict = W.dualAnnihilator := rfl /-- The `dualAnnihilator` of a submodule of the dual space pulled back along the evaluation map `Module.Dual.eval`. -/ def dualCoannihilator (Φ : Submodule R (Module.Dual R M)) : Submodule R M := Φ.dualAnnihilator.comap (Module.Dual.eval R M) @[simp] theorem mem_dualCoannihilator {Φ : Submodule R (Module.Dual R M)} (x : M) : x ∈ Φ.dualCoannihilator ↔ ∀ φ ∈ Φ, (φ x : R) = 0 := by simp_rw [dualCoannihilator, mem_comap, mem_dualAnnihilator, Module.Dual.eval_apply] lemma dualAnnihilator_map_dualMap_le {N : Type*} [AddCommMonoid N] [Module R N] (W : Submodule R M) (f : N →ₗ[R] M) : W.dualAnnihilator.map f.dualMap ≤ (W.comap f).dualAnnihilator := by intro; aesop theorem comap_dualAnnihilator (Φ : Submodule R (Module.Dual R M)) : Φ.dualAnnihilator.comap (Module.Dual.eval R M) = Φ.dualCoannihilator := rfl theorem map_dualCoannihilator_le (Φ : Submodule R (Module.Dual R M)) : Φ.dualCoannihilator.map (Module.Dual.eval R M) ≤ Φ.dualAnnihilator := map_le_iff_le_comap.mpr (comap_dualAnnihilator Φ).le variable (R M) in theorem dualAnnihilator_gc : GaloisConnection (OrderDual.toDual ∘ (dualAnnihilator : Submodule R M → Submodule R (Module.Dual R M))) (dualCoannihilator ∘ OrderDual.ofDual) := by intro a b induction b using OrderDual.rec simp only [Function.comp_apply, OrderDual.toDual_le_toDual, OrderDual.ofDual_toDual, SetLike.le_def, mem_dualAnnihilator, mem_dualCoannihilator] grind theorem le_dualAnnihilator_iff_le_dualCoannihilator {U : Submodule R (Module.Dual R M)} {V : Submodule R M} : U ≤ V.dualAnnihilator ↔ V ≤ U.dualCoannihilator := (dualAnnihilator_gc R M).le_iff_le @[simp] theorem dualAnnihilator_bot : (⊥ : Submodule R M).dualAnnihilator = ⊤ := (dualAnnihilator_gc R M).l_bot @[simp] theorem dualAnnihilator_top : (⊤ : Submodule R M).dualAnnihilator = ⊥ := by simp [eq_bot_iff, SetLike.le_def, LinearMap.ext_iff] @[simp] theorem dualCoannihilator_bot : (⊥ : Submodule R (Module.Dual R M)).dualCoannihilator = ⊤ := (dualAnnihilator_gc R M).u_top @[mono] theorem dualAnnihilator_anti {U V : Submodule R M} (hUV : U ≤ V) : V.dualAnnihilator ≤ U.dualAnnihilator := (dualAnnihilator_gc R M).monotone_l hUV @[mono] theorem dualCoannihilator_anti {U V : Submodule R (Module.Dual R M)} (hUV : U ≤ V) : V.dualCoannihilator ≤ U.dualCoannihilator := (dualAnnihilator_gc R M).monotone_u hUV theorem le_dualAnnihilator_dualCoannihilator (U : Submodule R M) : U ≤ U.dualAnnihilator.dualCoannihilator := (dualAnnihilator_gc R M).le_u_l U theorem le_dualCoannihilator_dualAnnihilator (U : Submodule R (Module.Dual R M)) : U ≤ U.dualCoannihilator.dualAnnihilator := (dualAnnihilator_gc R M).l_u_le U theorem dualAnnihilator_dualCoannihilator_dualAnnihilator (U : Submodule R M) : U.dualAnnihilator.dualCoannihilator.dualAnnihilator = U.dualAnnihilator := (dualAnnihilator_gc R M).l_u_l_eq_l U theorem dualCoannihilator_dualAnnihilator_dualCoannihilator (U : Submodule R (Module.Dual R M)) : U.dualCoannihilator.dualAnnihilator.dualCoannihilator = U.dualCoannihilator := (dualAnnihilator_gc R M).u_l_u_eq_u U theorem dualAnnihilator_sup_eq (U V : Submodule R M) : (U ⊔ V).dualAnnihilator = U.dualAnnihilator ⊓ V.dualAnnihilator := (dualAnnihilator_gc R M).l_sup theorem dualCoannihilator_sup_eq (U V : Submodule R (Module.Dual R M)) : (U ⊔ V).dualCoannihilator = U.dualCoannihilator ⊓ V.dualCoannihilator := (dualAnnihilator_gc R M).u_inf theorem dualAnnihilator_iSup_eq {ι : Sort*} (U : ι → Submodule R M) : (⨆ i : ι, U i).dualAnnihilator = ⨅ i : ι, (U i).dualAnnihilator := (dualAnnihilator_gc R M).l_iSup theorem dualCoannihilator_iSup_eq {ι : Sort*} (U : ι → Submodule R (Module.Dual R M)) : (⨆ i : ι, U i).dualCoannihilator = ⨅ i : ι, (U i).dualCoannihilator := (dualAnnihilator_gc R M).u_iInf /-- See also `Subspace.dualAnnihilator_inf_eq` for vector subspaces. -/ theorem sup_dualAnnihilator_le_inf (U V : Submodule R M) : U.dualAnnihilator ⊔ V.dualAnnihilator ≤ (U ⊓ V).dualAnnihilator := by rw [le_dualAnnihilator_iff_le_dualCoannihilator, dualCoannihilator_sup_eq] apply inf_le_inf <;> exact le_dualAnnihilator_dualCoannihilator _ /-- See also `Subspace.dualAnnihilator_iInf_eq` for vector subspaces when `ι` is finite. -/ theorem iSup_dualAnnihilator_le_iInf {ι : Sort*} (U : ι → Submodule R M) : ⨆ i : ι, (U i).dualAnnihilator ≤ (⨅ i : ι, U i).dualAnnihilator := by rw [le_dualAnnihilator_iff_le_dualCoannihilator, dualCoannihilator_iSup_eq] apply iInf_mono exact fun i : ι => le_dualAnnihilator_dualCoannihilator (U i) @[simp] lemma coe_dualAnnihilator_span (s : Set M) : ((span R s).dualAnnihilator : Set (Module.Dual R M)) = {f | s ⊆ LinearMap.ker f} := by ext f simp only [SetLike.mem_coe, mem_dualAnnihilator, Set.mem_setOf_eq, ← LinearMap.mem_ker] exact span_le @[simp] lemma coe_dualCoannihilator_span (s : Set (Module.Dual R M)) : ((span R s).dualCoannihilator : Set M) = {x | ∀ f ∈ s, f x = 0} := by ext x have (φ : _) : x ∈ LinearMap.ker φ ↔ φ ∈ LinearMap.ker (Module.Dual.eval R M x) := by simp simp only [SetLike.mem_coe, mem_dualCoannihilator, Set.mem_setOf_eq, ← LinearMap.mem_ker, this] exact span_le end Submodule open Module namespace LinearMap variable {R M₁ M₂ : Type*} [CommSemiring R] variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] variable (f : M₁ →ₗ[R] M₂) theorem ker_dualMap_eq_dualAnnihilator_range : LinearMap.ker f.dualMap = (range f).dualAnnihilator := by ext simp_rw [mem_ker, LinearMap.ext_iff, Submodule.mem_dualAnnihilator, ← SetLike.mem_coe, coe_range, Set.forall_mem_range, dualMap_apply, zero_apply] theorem range_dualMap_le_dualAnnihilator_ker : LinearMap.range f.dualMap ≤ (ker f).dualAnnihilator := by rintro _ ⟨ψ, rfl⟩ simp +contextual end LinearMap section CommSemiring variable {R M M' : Type*} variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M'] namespace LinearMap open Submodule theorem ker_dualMap_eq_dualCoannihilator_range (f : M →ₗ[R] M') : LinearMap.ker f.dualMap = (range (Dual.eval R M' ∘ₗ f)).dualCoannihilator := by ext x; simp [LinearMap.ext_iff (f := dualMap f x)] @[simp] lemma dualCoannihilator_range_eq_ker_flip (B : M →ₗ[R] M' →ₗ[R] R) : (range B).dualCoannihilator = LinearMap.ker B.flip := by ext x; simp [LinearMap.ext_iff (f := B.flip x)] end LinearMap end CommSemiring
.lake/packages/mathlib/Mathlib/LinearAlgebra/Dual/Basis.lean
import Mathlib.LinearAlgebra.Basis.Defs import Mathlib.LinearAlgebra.Dual.Defs /-! # Bases of dual vector spaces The dual space of an $R$-module $M$ is the $R$-module of $R$-linear maps $M \to R$. This file concerns bases on dual vector spaces. ## Main definitions * Bases: * `Basis.toDual` produces the map `M →ₗ[R] Dual R M` associated to a basis for an `R`-module `M`. * `Basis.toDualEquiv` is the equivalence `M ≃ₗ[R] Dual R M` associated to a finite basis. * `Basis.dualBasis` is a basis for `Dual R M` given a finite basis for `M`. * `Module.DualBases e ε` is the proposition that the families `e` of vectors and `ε` of dual vectors have the characteristic properties of a basis and a dual. ## Main results * Bases: * `Module.DualBases.basis` and `Module.DualBases.coe_basis`: if `e` and `ε` form a dual pair, then `e` is a basis. * `Module.DualBases.coe_dualBasis`: if `e` and `ε` form a dual pair, then `ε` is a basis. -/ open Module Dual Submodule LinearMap Function noncomputable section namespace Module.Basis universe u v w uR uM uK uV uι variable {R : Type uR} {M : Type uM} {K : Type uK} {V : Type uV} {ι : Type uι} section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [DecidableEq ι] variable (b : Basis ι R M) /-- The linear map from a vector space equipped with basis to its dual vector space, taking basis elements to corresponding dual basis elements. -/ def toDual : M →ₗ[R] Module.Dual R M := b.constr ℕ fun v => b.constr ℕ fun w => if w = v then (1 : R) else 0 theorem toDual_apply (i j : ι) : b.toDual (b i) (b j) = if i = j then 1 else 0 := by rw [toDual, constr_basis b, constr_basis b] simp only [eq_comm] @[simp] theorem toDual_linearCombination_left (f : ι →₀ R) (i : ι) : b.toDual (Finsupp.linearCombination R b f) (b i) = f i := by rw [Finsupp.linearCombination_apply, Finsupp.sum, map_sum, LinearMap.sum_apply] simp_rw [LinearMap.map_smul, LinearMap.smul_apply, toDual_apply, smul_eq_mul, mul_boole, Finset.sum_ite_eq', Finsupp.if_mem_support] @[simp] theorem toDual_linearCombination_right (f : ι →₀ R) (i : ι) : b.toDual (b i) (Finsupp.linearCombination R b f) = f i := by rw [Finsupp.linearCombination_apply, Finsupp.sum, map_sum] simp_rw [LinearMap.map_smul, toDual_apply, smul_eq_mul, mul_boole, Finset.sum_ite_eq, Finsupp.if_mem_support] theorem toDual_apply_left (m : M) (i : ι) : b.toDual m (b i) = b.repr m i := by rw [← b.toDual_linearCombination_left, b.linearCombination_repr] theorem toDual_apply_right (i : ι) (m : M) : b.toDual (b i) m = b.repr m i := by rw [← b.toDual_linearCombination_right, b.linearCombination_repr] theorem coe_toDual_self (i : ι) : b.toDual (b i) = b.coord i := by ext apply toDual_apply_right /-- `h.toDualFlip v` is the linear map sending `w` to `h.toDual w v`. -/ def toDualFlip (m : M) : M →ₗ[R] R := b.toDual.flip m theorem toDualFlip_apply (m₁ m₂ : M) : b.toDualFlip m₁ m₂ = b.toDual m₂ m₁ := rfl theorem toDual_eq_repr (m : M) (i : ι) : b.toDual m (b i) = b.repr m i := b.toDual_apply_left m i theorem toDual_eq_equivFun [Finite ι] (m : M) (i : ι) : b.toDual m (b i) = b.equivFun m i := by rw [b.equivFun_apply, toDual_eq_repr] theorem toDual_injective : Injective b.toDual := fun x y h ↦ b.ext_elem_iff.mpr fun i ↦ by simp_rw [← toDual_eq_repr]; exact DFunLike.congr_fun h _ theorem toDual_inj (m : M) (a : b.toDual m = 0) : m = 0 := b.toDual_injective (by rwa [map_zero]) theorem toDual_ker : LinearMap.ker b.toDual = ⊥ := ker_eq_bot'.mpr b.toDual_inj theorem toDual_range [Finite ι] : LinearMap.range b.toDual = ⊤ := by refine eq_top_iff'.2 fun f => ?_ refine ⟨Finsupp.linearCombination R b (Finsupp.equivFunOnFinite.symm fun i => f (b i)), b.ext fun i => ?_⟩ rw [b.toDual_eq_repr _ i, repr_linearCombination b, Finsupp.equivFunOnFinite_symm_apply_toFun] omit [DecidableEq ι] in @[simp] theorem sum_dual_apply_smul_coord [Fintype ι] (f : Module.Dual R M) : (∑ x, f (b x) • b.coord x) = f := by ext m simp_rw [LinearMap.sum_apply, LinearMap.smul_apply, smul_eq_mul, mul_comm (f _), ← smul_eq_mul, ← f.map_smul, ← map_sum, Basis.coord_apply, Basis.sum_repr] section Finite variable [Finite ι] /-- A vector space is linearly equivalent to its dual space. -/ def toDualEquiv : M ≃ₗ[R] Dual R M := .ofBijective b.toDual ⟨b.toDual_injective, range_eq_top.mp b.toDual_range⟩ -- `simps` times out when generating this @[simp] theorem toDualEquiv_apply (m : M) : b.toDualEquiv m = b.toDual m := rfl /-- Maps a basis for `V` to a basis for the dual space. -/ def dualBasis : Basis ι R (Dual R M) := b.map b.toDualEquiv -- We use `j = i` to match `Basis.repr_self` theorem dualBasis_apply_self (i j : ι) : b.dualBasis i (b j) = if j = i then 1 else 0 := by convert b.toDual_apply i j using 2 rw [@eq_comm _ j i] theorem linearCombination_dualBasis (f : ι →₀ R) (i : ι) : Finsupp.linearCombination R b.dualBasis f (b i) = f i := by cases nonempty_fintype ι rw [Finsupp.linearCombination_apply, Finsupp.sum_fintype, LinearMap.sum_apply] · simp_rw [LinearMap.smul_apply, smul_eq_mul, dualBasis_apply_self, mul_boole, Finset.sum_ite_eq, if_pos (Finset.mem_univ i)] · intro rw [zero_smul] @[simp] theorem dualBasis_repr (l : Dual R M) (i : ι) : b.dualBasis.repr l i = l (b i) := by rw [← linearCombination_dualBasis b, Basis.linearCombination_repr b.dualBasis l] theorem dualBasis_apply (i : ι) (m : M) : b.dualBasis i m = b.repr m i := b.toDual_apply_right i m @[simp] theorem coe_dualBasis : ⇑b.dualBasis = b.coord := by ext i x apply dualBasis_apply @[simp] theorem toDual_toDual : b.dualBasis.toDual.comp b.toDual = Dual.eval R M := by refine b.ext fun i => b.dualBasis.ext fun j => ?_ rw [LinearMap.comp_apply, toDual_apply_left, coe_toDual_self, ← coe_dualBasis, Dual.eval_apply, Basis.repr_self, Finsupp.single_apply, dualBasis_apply_self] end Finite theorem dualBasis_equivFun [Finite ι] (l : Dual R M) (i : ι) : b.dualBasis.equivFun l i = l (b i) := by rw [Basis.equivFun_apply, dualBasis_repr] theorem eval_injective {ι : Type*} (b : Basis ι R M) : Function.Injective (Dual.eval R M) := by intro m m' eq simp_rw [LinearMap.ext_iff, Dual.eval_apply] at eq exact b.ext_elem fun i ↦ eq (b.coord i) theorem eval_ker {ι : Type*} (b : Basis ι R M) : LinearMap.ker (Dual.eval R M) = ⊥ := ker_eq_bot_of_injective (eval_injective b) theorem eval_range {ι : Type*} [Finite ι] (b : Basis ι R M) : LinearMap.range (Dual.eval R M) = ⊤ := by classical cases nonempty_fintype ι rw [← b.toDual_toDual, range_comp, b.toDual_range, Submodule.map_top, toDual_range _] lemma dualBasis_coord_toDualEquiv_apply [Finite ι] (i : ι) (f : M) : b.dualBasis.coord i (b.toDualEquiv f) = b.coord i f := by simp [-toDualEquiv_apply, Basis.dualBasis] lemma coord_toDualEquiv_symm_apply [Finite ι] (i : ι) (f : Module.Dual R M) : b.coord i (b.toDualEquiv.symm f) = b.dualBasis.coord i f := by simp [Basis.dualBasis] omit [DecidableEq ι] /-- `simp` normal form version of `linearCombination_dualBasis` -/ @[simp] theorem linearCombination_coord [Finite ι] (b : Basis ι R M) (f : ι →₀ R) (i : ι) : Finsupp.linearCombination R b.coord f (b i) = f i := by haveI := Classical.decEq ι rw [← coe_dualBasis, linearCombination_dualBasis] end CommSemiring end Module.Basis section DualBases variable {R M ι : Type*} variable [CommSemiring R] [AddCommMonoid M] [Module R M] open Lean.Elab.Tactic in /-- Try using `Set.toFinite` to dispatch a `Set.Finite` goal. -/ def evalUseFiniteInstance : TacticM Unit := do evalTactic (← `(tactic| intros; apply Set.toFinite)) elab "use_finite_instance" : tactic => evalUseFiniteInstance /-- `e` and `ε` have characteristic properties of a basis and its dual -/ structure Module.DualBases (e : ι → M) (ε : ι → Dual R M) : Prop where eval_same : ∀ i, ε i (e i) = 1 eval_of_ne : Pairwise fun i j ↦ ε i (e j) = 0 protected total : ∀ {m₁ m₂ : M}, (∀ i, ε i m₁ = ε i m₂) → m₁ = m₂ protected finite : ∀ m : M, {i | ε i m ≠ 0}.Finite := by use_finite_instance end DualBases namespace Module.DualBases open LinearMap Function variable {R M ι : Type*} variable [CommSemiring R] [AddCommMonoid M] [Module R M] variable {e : ι → M} {ε : ι → Dual R M} /-- The coefficients of `v` on the basis `e` -/ def coeffs (h : DualBases e ε) (m : M) : ι →₀ R where toFun i := ε i m support := (h.finite m).toFinset mem_support_toFun i := by rw [Set.Finite.mem_toFinset, Set.mem_setOf_eq] @[simp] theorem coeffs_apply (h : DualBases e ε) (m : M) (i : ι) : h.coeffs m i = ε i m := rfl /-- linear combinations of elements of `e`. This is a convenient abbreviation for `Finsupp.linearCombination R e l` -/ def lc {ι} (e : ι → M) (l : ι →₀ R) : M := l.sum fun (i : ι) (a : R) => a • e i theorem lc_def (e : ι → M) (l : ι →₀ R) : lc e l = Finsupp.linearCombination R e l := rfl open Module variable (h : DualBases e ε) include h theorem dual_lc (l : ι →₀ R) (i : ι) : ε i (DualBases.lc e l) = l i := by rw [lc, map_finsuppSum, Finsupp.sum_eq_single i (g := fun a b ↦ (ε i) (b • e a))] · simp [h.eval_same, smul_eq_mul] · intro q _ q_ne simp [h.eval_of_ne q_ne.symm, smul_eq_mul] · simp @[simp] theorem coeffs_lc (l : ι →₀ R) : h.coeffs (DualBases.lc e l) = l := by ext i rw [h.coeffs_apply, h.dual_lc] /-- For any m : M n, \sum_{p ∈ Q n} (ε p m) • e p = m -/ @[simp] theorem lc_coeffs (m : M) : DualBases.lc e (h.coeffs m) = m := h.total <| by simp [h.dual_lc] /-- `(h : DualBases e ε).basis` shows the family of vectors `e` forms a basis. -/ @[simps repr_apply, simps -isSimp repr_symm_apply] def basis : Basis ι R M := Basis.ofRepr { toFun := coeffs h invFun := lc e left_inv := lc_coeffs h right_inv := coeffs_lc h map_add' := fun v w => by ext i exact (ε i).map_add v w map_smul' := fun c v => by ext i exact (ε i).map_smul c v } @[simp] theorem coe_basis : ⇑h.basis = e := by ext i rw [Basis.apply_eq_iff] ext j rcases eq_or_ne i j with rfl | hne · simp [h.eval_same] · simp [hne, h.eval_of_ne hne.symm] theorem mem_of_mem_span {H : Set ι} {x : M} (hmem : x ∈ Submodule.span R (e '' H)) : ∀ i : ι, ε i x ≠ 0 → i ∈ H := by intro i hi rcases (Finsupp.mem_span_image_iff_linearCombination _).mp hmem with ⟨l, supp_l, rfl⟩ apply not_imp_comm.mp ((Finsupp.mem_supported' _ _).mp supp_l i) rwa [← lc_def, h.dual_lc] at hi theorem coe_dualBasis [DecidableEq ι] [Finite ι] : ⇑h.basis.dualBasis = ε := funext fun i => h.basis.ext fun j => by simp end Module.DualBases
.lake/packages/mathlib/Mathlib/LinearAlgebra/Quotient/Card.lean
import Mathlib.LinearAlgebra.Quotient.Defs import Mathlib.SetTheory.Cardinal.Finite import Mathlib.GroupTheory.Coset.Basic /-! Results about the cardinality of a quotient module. -/ namespace Submodule open LinearMap QuotientAddGroup variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] theorem card_eq_card_quotient_mul_card (S : Submodule R M) : Nat.card M = Nat.card S * Nat.card (M ⧸ S) := by rw [mul_comm, ← Nat.card_prod] exact Nat.card_congr AddSubgroup.addGroupEquivQuotientProdAddSubgroup end Submodule
.lake/packages/mathlib/Mathlib/LinearAlgebra/Quotient/Pi.lean
import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Quotient.Basic /-! # Submodule quotients and direct sums This file contains some results on the quotient of a module by a direct sum of submodules, and the direct sum of quotients of modules by submodules. ## Main definitions * `Submodule.piQuotientLift`: create a map out of the direct sum of quotients * `Submodule.quotientPiLift`: create a map out of the quotient of a direct sum * `Submodule.quotientPi`: the quotient of a direct sum is the direct sum of quotients. -/ namespace Submodule open LinearMap variable {ι R : Type*} [CommRing R] variable {Ms : ι → Type*} [∀ i, AddCommGroup (Ms i)] [∀ i, Module R (Ms i)] variable {N : Type*} [AddCommGroup N] [Module R N] variable {Ns : ι → Type*} [∀ i, AddCommGroup (Ns i)] [∀ i, Module R (Ns i)] /-- Lift a family of maps to the direct sum of quotients. -/ def piQuotientLift [Fintype ι] [DecidableEq ι] (p : ∀ i, Submodule R (Ms i)) (q : Submodule R N) (f : ∀ i, Ms i →ₗ[R] N) (hf : ∀ i, p i ≤ q.comap (f i)) : (∀ i, Ms i ⧸ p i) →ₗ[R] N ⧸ q := lsum R (fun i => Ms i ⧸ p i) R fun i => (p i).mapQ q (f i) (hf i) @[simp] theorem piQuotientLift_mk [Fintype ι] [DecidableEq ι] (p : ∀ i, Submodule R (Ms i)) (q : Submodule R N) (f : ∀ i, Ms i →ₗ[R] N) (hf : ∀ i, p i ≤ q.comap (f i)) (x : ∀ i, Ms i) : (piQuotientLift p q f hf fun i => Quotient.mk (x i)) = Quotient.mk (lsum _ _ R f x) := by rw [piQuotientLift, lsum_apply, sum_apply, ← mkQ_apply, lsum_apply, sum_apply, _root_.map_sum] simp only [coe_proj, mapQ_apply, mkQ_apply, comp_apply] @[simp] theorem piQuotientLift_single [Fintype ι] [DecidableEq ι] (p : ∀ i, Submodule R (Ms i)) (q : Submodule R N) (f : ∀ i, Ms i →ₗ[R] N) (hf : ∀ i, p i ≤ q.comap (f i)) (i) (x : Ms i ⧸ p i) : piQuotientLift p q f hf (Pi.single i x) = mapQ _ _ (f i) (hf i) x := by simp_rw [piQuotientLift, lsum_apply, sum_apply, comp_apply, proj_apply] rw [Finset.sum_eq_single i] · rw [Pi.single_eq_same] · rintro j - hj rw [Pi.single_eq_of_ne hj, map_zero] · intros have := Finset.mem_univ i contradiction /-- Lift a family of maps to a quotient of direct sums. -/ def quotientPiLift (p : ∀ i, Submodule R (Ms i)) (f : ∀ i, Ms i →ₗ[R] Ns i) (hf : ∀ i, p i ≤ ker (f i)) : (∀ i, Ms i) ⧸ pi Set.univ p →ₗ[R] ∀ i, Ns i := (pi Set.univ p).liftQ (LinearMap.pi fun i => (f i).comp (proj i)) fun x hx => mem_ker.mpr <| by ext i simpa using hf i (mem_pi.mp hx i (Set.mem_univ i)) @[simp] theorem quotientPiLift_mk (p : ∀ i, Submodule R (Ms i)) (f : ∀ i, Ms i →ₗ[R] Ns i) (hf : ∀ i, p i ≤ ker (f i)) (x : ∀ i, Ms i) : quotientPiLift p f hf (Quotient.mk x) = fun i => f i (x i) := rfl namespace quotientPi_aux variable (p : ∀ i, Submodule R (Ms i)) @[simp] def toFun : ((∀ i, Ms i) ⧸ pi Set.univ p) → ∀ i, Ms i ⧸ p i := quotientPiLift p (fun i => (p i).mkQ) fun i => (ker_mkQ (p i)).ge theorem map_add (x y : ((i : ι) → Ms i) ⧸ pi Set.univ p) : toFun p (x + y) = toFun p x + toFun p y := LinearMap.map_add (quotientPiLift p (fun i => (p i).mkQ) fun i => (ker_mkQ (p i)).ge) x y theorem map_smul (r : R) (x : ((i : ι) → Ms i) ⧸ pi Set.univ p) : toFun p (r • x) = (RingHom.id R r) • toFun p x := LinearMap.map_smul (quotientPiLift p (fun i => (p i).mkQ) fun i => (ker_mkQ (p i)).ge) r x variable [Fintype ι] [DecidableEq ι] @[simp] def invFun : (∀ i, Ms i ⧸ p i) → (∀ i, Ms i) ⧸ pi Set.univ p := piQuotientLift p (pi Set.univ p) _ fun _ => le_comap_single_pi p theorem left_inv : Function.LeftInverse (invFun p) (toFun p) := fun x => Submodule.Quotient.induction_on _ x fun x' => by dsimp only [toFun, invFun] rw [quotientPiLift_mk p, funext fun i => (mkQ_apply (p i) (x' i)), piQuotientLift_mk p, lsum_single, id_apply] theorem right_inv : Function.RightInverse (invFun p) (toFun p) := by dsimp only [toFun, invFun] rw [Function.rightInverse_iff_comp, ← coe_comp, ← @id_coe R] refine congr_arg _ (pi_ext fun i x => Submodule.Quotient.induction_on _ x fun x' => funext fun j => ?_) rw [comp_apply, piQuotientLift_single, mapQ_apply, quotientPiLift_mk, id_apply] by_cases hij : i = j <;> simp only [mkQ_apply, coe_single] · subst hij rw [Pi.single_eq_same, Pi.single_eq_same] · rw [Pi.single_eq_of_ne (Ne.symm hij), Pi.single_eq_of_ne (Ne.symm hij), Quotient.mk_zero] end quotientPi_aux open quotientPi_aux in /-- The quotient of a direct sum is the direct sum of quotients. -/ @[simps!] def quotientPi [Fintype ι] [DecidableEq ι] (p : ∀ i, Submodule R (Ms i)) : ((∀ i, Ms i) ⧸ pi Set.univ p) ≃ₗ[R] ∀ i, Ms i ⧸ p i where toFun := toFun p invFun := invFun p map_add' := map_add p map_smul' := quotientPi_aux.map_smul p left_inv := left_inv p right_inv := right_inv p end Submodule
.lake/packages/mathlib/Mathlib/LinearAlgebra/Quotient/Basic.lean
import Mathlib.Algebra.Module.Equiv.Basic import Mathlib.GroupTheory.QuotientGroup.Basic import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Quotient.Defs import Mathlib.LinearAlgebra.Span.Basic /-! # Quotients by submodules * If `p` is a submodule of `M`, `M ⧸ p` is the quotient of `M` with respect to `p`: that is, elements of `M` are identified if their difference is in `p`. This is itself a module. ## Main definitions * `Submodule.Quotient.restrictScalarsEquiv`: The quotient of `P` as an `S`-submodule is the same as the quotient of `P` as an `R`-submodule, * `Submodule.liftQ`: lift a map `M → M₂` to a map `M ⧸ p → M₂` if the kernel is contained in `p` * `Submodule.mapQ`: lift a map `M → M₂` to a map `M ⧸ p → M₂ ⧸ q` if the image of `p` is contained in `q` -/ assert_not_exists Cardinal -- For most of this file we work over a noncommutative ring section Ring namespace Submodule variable {R M : Type*} {r : R} {x y : M} [Ring R] [AddCommGroup M] [Module R M] variable (p p' p'' : Submodule R M) open LinearMap QuotientAddGroup namespace Quotient section Module variable (S : Type*) /-- The quotient of `P` as an `S`-submodule is the same as the quotient of `P` as an `R`-submodule, where `P : Submodule R M`. -/ def restrictScalarsEquiv [Ring S] [SMul S R] [Module S M] [IsScalarTower S R M] (P : Submodule R M) : (M ⧸ P.restrictScalars S) ≃ₗ[S] M ⧸ P := { Quotient.congrRight fun _ _ => Iff.rfl with map_add' := fun x y => Quotient.inductionOn₂' x y fun _x' _y' => rfl map_smul' := fun _c x => Submodule.Quotient.induction_on _ x fun _x' => rfl } @[simp] theorem restrictScalarsEquiv_mk [Ring S] [SMul S R] [Module S M] [IsScalarTower S R M] (P : Submodule R M) (x : M) : restrictScalarsEquiv S P (mk x) = mk x := rfl @[simp] theorem restrictScalarsEquiv_symm_mk [Ring S] [SMul S R] [Module S M] [IsScalarTower S R M] (P : Submodule R M) (x : M) : (restrictScalarsEquiv S P).symm (mk x) = mk x := rfl end Module theorem nontrivial_of_lt_top (h : p < ⊤) : Nontrivial (M ⧸ p) := by obtain ⟨x, _, notMem_s⟩ := SetLike.exists_of_lt h refine ⟨⟨mk x, 0, ?_⟩⟩ simpa using notMem_s theorem nontrivial_of_ne_top (h : p ≠ ⊤) : Nontrivial (M ⧸ p) := nontrivial_of_lt_top p h.lt_top end Quotient instance QuotientBot.infinite [Infinite M] : Infinite (M ⧸ (⊥ : Submodule R M)) := Infinite.of_injective Submodule.Quotient.mk fun _x _y h => sub_eq_zero.mp <| (Submodule.Quotient.eq ⊥).mp h instance QuotientTop.unique : Unique (M ⧸ (⊤ : Submodule R M)) where default := 0 uniq x := Submodule.Quotient.induction_on _ x fun _x => (Submodule.Quotient.eq ⊤).mpr Submodule.mem_top instance QuotientTop.fintype : Fintype (M ⧸ (⊤ : Submodule R M)) := Fintype.ofSubsingleton 0 variable {p} theorem subsingleton_quotient_iff_eq_top : Subsingleton (M ⧸ p) ↔ p = ⊤ := by constructor · rintro h refine eq_top_iff.mpr fun x _ => ?_ have : x - 0 ∈ p := (Submodule.Quotient.eq p).mp (Subsingleton.elim _ _) rwa [sub_zero] at this · rintro rfl infer_instance instance [Subsingleton M] : Subsingleton (M ⧸ p) := Submodule.subsingleton_quotient_iff_eq_top.mpr (Subsingleton.elim _ _) theorem unique_quotient_iff_eq_top : Nonempty (Unique (M ⧸ p)) ↔ p = ⊤ := ⟨fun ⟨h⟩ => subsingleton_quotient_iff_eq_top.mp (@Unique.instSubsingleton _ h), by rintro rfl; exact ⟨QuotientTop.unique⟩⟩ variable (p) noncomputable instance Quotient.fintype [Fintype M] (S : Submodule R M) : Fintype (M ⧸ S) := @_root_.Quotient.fintype _ _ _ fun _ _ => Classical.dec _ section variable {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] theorem strictMono_comap_prod_map : StrictMono fun m : Submodule R M ↦ (m.comap p.subtype, m.map p.mkQ) := fun m₁ m₂ ↦ QuotientAddGroup.strictMono_comap_prod_map p.toAddSubgroup (a := m₁.toAddSubgroup) (b := m₂.toAddSubgroup) end variable {R₂ M₂ : Type*} [Ring R₂] [AddCommGroup M₂] [Module R₂ M₂] {τ₁₂ : R →+* R₂} /-- The map from the quotient of `M` by a submodule `p` to `M₂` induced by a linear map `f : M → M₂` vanishing on `p`, as a linear map. -/ def liftQ (f : M →ₛₗ[τ₁₂] M₂) (h : p ≤ ker f) : M ⧸ p →ₛₗ[τ₁₂] M₂ := { QuotientAddGroup.lift p.toAddSubgroup f.toAddMonoidHom h with map_smul' := by rintro a ⟨x⟩; exact f.map_smulₛₗ a x } @[simp] theorem liftQ_apply (f : M →ₛₗ[τ₁₂] M₂) {h} (x : M) : p.liftQ f h (Quotient.mk x) = f x := rfl @[simp] theorem liftQ_mkQ (f : M →ₛₗ[τ₁₂] M₂) (h) : (p.liftQ f h).comp p.mkQ = f := by ext; rfl theorem pi_liftQ_eq_liftQ_pi {ι : Type*} {N : ι → Type*} [∀ i, AddCommGroup (N i)] [∀ i, Module R (N i)] (f : (i : ι) → M →ₗ[R] (N i)) {p : Submodule R M} (h : ∀ i, p ≤ ker (f i)) : LinearMap.pi (fun i ↦ p.liftQ (f i) (h i)) = p.liftQ (LinearMap.pi f) (LinearMap.ker_pi f ▸ le_iInf h) := by ext x i simp /-- Special case of `submodule.liftQ` when `p` is the span of `x`. In this case, the condition on `f` simply becomes vanishing at `x`. -/ def liftQSpanSingleton (x : M) (f : M →ₛₗ[τ₁₂] M₂) (h : f x = 0) : (M ⧸ R ∙ x) →ₛₗ[τ₁₂] M₂ := (R ∙ x).liftQ f <| by rw [span_singleton_le_iff_mem, LinearMap.mem_ker, h] @[simp] theorem liftQSpanSingleton_apply (x : M) (f : M →ₛₗ[τ₁₂] M₂) (h : f x = 0) (y : M) : liftQSpanSingleton x f h (Quotient.mk y) = f y := rfl @[simp] theorem range_mkQ : range p.mkQ = ⊤ := eq_top_iff'.2 <| by rintro ⟨x⟩; exact ⟨x, rfl⟩ @[simp] theorem ker_mkQ : ker p.mkQ = p := by ext; simp theorem le_comap_mkQ (p' : Submodule R (M ⧸ p)) : p ≤ comap p.mkQ p' := by simpa using (comap_mono bot_le : ker p.mkQ ≤ comap p.mkQ p') @[simp] theorem mkQ_map_self : map p.mkQ p = ⊥ := by rw [eq_bot_iff, map_le_iff_le_comap, comap_bot, ker_mkQ] @[simp] theorem comap_map_mkQ : comap p.mkQ (map p.mkQ p') = p ⊔ p' := by simp [comap_map_eq, sup_comm] @[simp] theorem map_mkQ_eq_top : map p.mkQ p' = ⊤ ↔ p ⊔ p' = ⊤ := by simp only [LinearMap.map_eq_top_iff p.range_mkQ, sup_comm, ker_mkQ] variable (q : Submodule R₂ M₂) /-- The map from the quotient of `M` by submodule `p` to the quotient of `M₂` by submodule `q` along `f : M → M₂` is linear. -/ def mapQ (f : M →ₛₗ[τ₁₂] M₂) (h : p ≤ comap f q) : M ⧸ p →ₛₗ[τ₁₂] M₂ ⧸ q := p.liftQ (q.mkQ.comp f) <| by simpa [ker_comp] using h @[simp] theorem mapQ_apply (f : M →ₛₗ[τ₁₂] M₂) {h} (x : M) : mapQ p q f h (Quotient.mk x) = Quotient.mk (f x) := rfl theorem mapQ_mkQ (f : M →ₛₗ[τ₁₂] M₂) {h} : (mapQ p q f h).comp p.mkQ = q.mkQ.comp f := by ext x; rfl @[simp] theorem mapQ_zero (h : p ≤ q.comap (0 : M →ₛₗ[τ₁₂] M₂) := (by simp)) : p.mapQ q (0 : M →ₛₗ[τ₁₂] M₂) h = 0 := by ext simp /-- Given submodules `p ⊆ M`, `p₂ ⊆ M₂`, `p₃ ⊆ M₃` and maps `f : M → M₂`, `g : M₂ → M₃` inducing `mapQ f : M ⧸ p → M₂ ⧸ p₂` and `mapQ g : M₂ ⧸ p₂ → M₃ ⧸ p₃` then `mapQ (g ∘ f) = (mapQ g) ∘ (mapQ f)`. -/ theorem mapQ_comp {R₃ M₃ : Type*} [Ring R₃] [AddCommGroup M₃] [Module R₃ M₃] (p₂ : Submodule R₂ M₂) (p₃ : Submodule R₃ M₃) {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) (hf : p ≤ p₂.comap f) (hg : p₂ ≤ p₃.comap g) (h := hf.trans (comap_mono hg)) : p.mapQ p₃ (g.comp f) h = (p₂.mapQ p₃ g hg).comp (p.mapQ p₂ f hf) := by ext simp @[simp] theorem mapQ_id (h : p ≤ p.comap LinearMap.id := (by rw [comap_id])) : p.mapQ p LinearMap.id h = LinearMap.id := by ext simp theorem mapQ_pow {f : M →ₗ[R] M} (h : p ≤ p.comap f) (k : ℕ) (h' : p ≤ p.comap (f ^ k) := p.le_comap_pow_of_le_comap h k) : p.mapQ p (f ^ k) h' = p.mapQ p f h ^ k := by induction k with | zero => simp [Module.End.one_eq_id] | succ k ih => simp only [Module.End.iterate_succ] rw [mapQ_comp, ih] exact p.le_comap_pow_of_le_comap h k theorem comap_liftQ (f : M →ₛₗ[τ₁₂] M₂) (h) : q.comap (p.liftQ f h) = (q.comap f).map (mkQ p) := le_antisymm (by rintro ⟨x⟩ hx; exact ⟨_, hx, rfl⟩) (by rw [map_le_iff_le_comap, ← comap_comp, liftQ_mkQ]) theorem map_liftQ [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) (h) (q : Submodule R (M ⧸ p)) : q.map (p.liftQ f h) = (q.comap p.mkQ).map f := le_antisymm (by rintro _ ⟨⟨x⟩, hxq, rfl⟩; exact ⟨x, hxq, rfl⟩) (by rintro _ ⟨x, hxq, rfl⟩; exact ⟨Quotient.mk x, hxq, rfl⟩) theorem ker_liftQ (f : M →ₛₗ[τ₁₂] M₂) (h) : ker (p.liftQ f h) = (ker f).map (mkQ p) := comap_liftQ _ _ _ _ theorem range_liftQ [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) (h) : range (p.liftQ f h) = range f := by simpa only [range_eq_map] using map_liftQ _ _ _ _ theorem ker_liftQ_eq_bot (f : M →ₛₗ[τ₁₂] M₂) (h) (h' : ker f ≤ p) : ker (p.liftQ f h) = ⊥ := by rw [ker_liftQ, le_antisymm h h', mkQ_map_self] theorem ker_liftQ_eq_bot' (f : M →ₛₗ[τ₁₂] M₂) (h : p = ker f) : ker (p.liftQ f (le_of_eq h)) = ⊥ := ker_liftQ_eq_bot p f h.le h.ge section variable {p p' p''} /-- The linear map from the quotient by a smaller submodule to the quotient by a larger submodule. This is the `Submodule.Quotient` version of `Quot.Factor` When the two submodules are of the form `I ^ m • ⊤` and `I ^ n • ⊤` and `n ≤ m`, please refer to the dedicated version `Submodule.factorPow`. -/ abbrev factor (H : p ≤ p') : M ⧸ p →ₗ[R] M ⧸ p' := mapQ _ _ LinearMap.id H @[simp] theorem factor_mk (H : p ≤ p') (x : M) : factor H (mkQ p x) = mkQ p' x := rfl @[simp] theorem factor_comp_mk (H : p ≤ p') : (factor H).comp (mkQ p) = mkQ p' := by ext x rw [LinearMap.comp_apply, factor_mk] @[simp] theorem factor_comp (H1 : p ≤ p') (H2 : p' ≤ p'') : (factor H2).comp (factor H1) = factor (H1.trans H2) := by ext simp @[simp] theorem factor_comp_apply (H1 : p ≤ p') (H2 : p' ≤ p'') (x : M ⧸ p) : factor H2 (factor H1 x) = factor (H1.trans H2) x := by rw [← comp_apply] simp lemma factor_surjective (H : p ≤ p') : Function.Surjective (factor H) := by intro x use Quotient.mk x.out exact Quotient.out_eq x end /-- The correspondence theorem for modules: there is an order isomorphism between submodules of the quotient of `M` by `p`, and submodules of `M` larger than `p`. -/ def comapMkQRelIso : Submodule R (M ⧸ p) ≃o Set.Ici p where toFun p' := ⟨comap p.mkQ p', le_comap_mkQ p _⟩ invFun q := map p.mkQ q left_inv p' := map_comap_eq_self <| by simp right_inv := fun ⟨q, hq⟩ => Subtype.ext <| by simpa [comap_map_mkQ p] map_rel_iff' := comap_le_comap_iff <| range_mkQ _ /-- The ordering on submodules of the quotient of `M` by `p` embeds into the ordering on submodules of `M`. -/ def comapMkQOrderEmbedding : Submodule R (M ⧸ p) ↪o Submodule R M := (RelIso.toRelEmbedding <| comapMkQRelIso p).trans (Subtype.relEmbedding (· ≤ ·) _) @[simp] theorem comapMkQOrderEmbedding_eq (p' : Submodule R (M ⧸ p)) : comapMkQOrderEmbedding p p' = comap p.mkQ p' := rfl theorem span_preimage_eq [RingHomSurjective τ₁₂] {f : M →ₛₗ[τ₁₂] M₂} {s : Set M₂} (h₀ : s.Nonempty) (h₁ : s ⊆ range f) : span R (f ⁻¹' s) = (span R₂ s).comap f := by suffices (span R₂ s).comap f ≤ span R (f ⁻¹' s) by exact le_antisymm (span_preimage_le f s) this have hk : ker f ≤ span R (f ⁻¹' s) := by let y := Classical.choose h₀ have hy : y ∈ s := Classical.choose_spec h₀ rw [ker_le_iff] use y, h₁ hy rw [← Set.singleton_subset_iff] at hy exact Set.Subset.trans subset_span (span_mono (Set.preimage_mono hy)) rw [← left_eq_sup] at hk rw [coe_range f] at h₁ rw [hk, ← LinearMap.map_le_map_iff, map_span, map_comap_eq, Set.image_preimage_eq_of_subset h₁] exact inf_le_right /-- If `P` is a submodule of `M` and `Q` a submodule of `N`, and `f : M ≃ₗ N` maps `P` to `Q`, then `M ⧸ P` is equivalent to `N ⧸ Q`. -/ @[simps] def Quotient.equiv {N : Type*} [AddCommGroup N] [Module R N] (P : Submodule R M) (Q : Submodule R N) (f : M ≃ₗ[R] N) (hf : P.map f = Q) : (M ⧸ P) ≃ₗ[R] N ⧸ Q := { P.mapQ Q (f : M →ₗ[R] N) fun _ hx => hf ▸ Submodule.mem_map_of_mem hx with toFun := P.mapQ Q (f : M →ₗ[R] N) fun _ hx => hf ▸ Submodule.mem_map_of_mem hx invFun := Q.mapQ P (f.symm : N →ₗ[R] M) fun x hx => by rw [← hf, Submodule.mem_map] at hx obtain ⟨y, hy, rfl⟩ := hx simpa left_inv := fun x => Submodule.Quotient.induction_on _ x (by simp) right_inv := fun x => Submodule.Quotient.induction_on _ x (by simp) } @[simp] theorem Quotient.equiv_symm {R M N : Type*} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] (P : Submodule R M) (Q : Submodule R N) (f : M ≃ₗ[R] N) (hf : P.map f = Q) : (Quotient.equiv P Q f hf).symm = Quotient.equiv Q P f.symm ((Submodule.map_symm_eq_iff f).mpr hf) := rfl @[simp] theorem Quotient.equiv_trans {N O : Type*} [AddCommGroup N] [Module R N] [AddCommGroup O] [Module R O] (P : Submodule R M) (Q : Submodule R N) (S : Submodule R O) (e : M ≃ₗ[R] N) (f : N ≃ₗ[R] O) (he : P.map e = Q) (hf : Q.map f = S) (hef : P.map (e.trans f) = S) : Quotient.equiv P S (e.trans f) hef = (Quotient.equiv P Q e he).trans (Quotient.equiv Q S f hf) := by ext -- `simp` can deal with `hef` depending on `e` and `f` simp only [Quotient.equiv_apply, LinearEquiv.trans_apply, LinearEquiv.coe_trans] -- `rw` can deal with `mapQ_comp` needing extra hypotheses coming from the RHS rw [mapQ_comp, LinearMap.comp_apply] end Submodule open Submodule namespace LinearMap section Ring variable {R M R₂ M₂ R₃ M₃ : Type*} variable [Ring R] [Ring R₂] [Ring R₃] variable [AddCommMonoid M] [AddCommGroup M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] [RingHomSurjective τ₁₂] theorem range_mkQ_comp (f : M →ₛₗ[τ₁₂] M₂) : (range f).mkQ.comp f = 0 := LinearMap.ext fun x => by simp theorem ker_le_range_iff {f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₃] M₃} : ker g ≤ range f ↔ (range f).mkQ.comp (ker g).subtype = 0 := by rw [← range_le_ker_iff, Submodule.ker_mkQ, Submodule.range_subtype] /-- An epimorphism is surjective. -/ theorem range_eq_top_of_cancel {f : M →ₛₗ[τ₁₂] M₂} (h : ∀ u v : M₂ →ₗ[R₂] M₂ ⧸ (range f), u.comp f = v.comp f → u = v) : range f = ⊤ := by have h₁ : (0 : M₂ →ₗ[R₂] M₂ ⧸ (range f)).comp f = 0 := zero_comp _ rw [← Submodule.ker_mkQ (range f), ← h 0 (range f).mkQ (Eq.trans h₁ (range_mkQ_comp _).symm)] exact ker_zero end Ring end LinearMap open LinearMap namespace Submodule variable {R M : Type*} {r : R} {x y : M} [Ring R] [AddCommGroup M] [Module R M] variable (p p' : Submodule R M) /-- If `p = ⊥`, then `M / p ≃ₗ[R] M`. -/ def quotEquivOfEqBot (hp : p = ⊥) : (M ⧸ p) ≃ₗ[R] M := LinearEquiv.ofLinear (p.liftQ id <| hp.symm ▸ bot_le) p.mkQ (liftQ_mkQ _ _ _) <| p.quot_hom_ext _ LinearMap.id fun _ => rfl @[simp] theorem quotEquivOfEqBot_apply_mk (hp : p = ⊥) (x : M) : p.quotEquivOfEqBot hp (Quotient.mk x) = x := rfl @[simp] theorem quotEquivOfEqBot_symm_apply (hp : p = ⊥) (x : M) : (p.quotEquivOfEqBot hp).symm x = (Quotient.mk x) := rfl @[simp] theorem coe_quotEquivOfEqBot_symm (hp : p = ⊥) : ((p.quotEquivOfEqBot hp).symm : M →ₗ[R] M ⧸ p) = p.mkQ := rfl @[simp] theorem Quotient.equiv_refl (P : Submodule R M) (Q : Submodule R M) (hf : P.map (LinearEquiv.refl R M : M →ₗ[R] M) = Q) : Quotient.equiv P Q (LinearEquiv.refl R M) hf = quotEquivOfEq _ _ (by simpa using hf) := rfl end Submodule end Ring section CommRing variable {R M M₂ : Type*} {r : R} {x y : M} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup M₂] [Module R M₂] (p : Submodule R M) (q : Submodule R M₂) namespace Submodule /-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`, the natural map $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \} \to Hom(M/p, M₂/q)$ is linear. -/ def mapQLinear : compatibleMaps p q →ₗ[R] M ⧸ p →ₗ[R] M₂ ⧸ q where toFun f := mapQ _ _ f.val f.property map_add' x y := by ext rfl map_smul' c f := by ext rfl end Submodule end CommRing
.lake/packages/mathlib/Mathlib/LinearAlgebra/Quotient/Defs.lean
import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.Algebra.Module.Submodule.Defs import Mathlib.GroupTheory.QuotientGroup.Defs import Mathlib.Logic.Small.Basic /-! # Quotients by submodules * If `p` is a submodule of `M`, `M ⧸ p` is the quotient of `M` with respect to `p`: that is, elements of `M` are identified if their difference is in `p`. This is itself a module. ## Main definitions * `Submodule.Quotient.mk`: a function sending an element of `M` to `M ⧸ p` * `Submodule.Quotient.module`: `M ⧸ p` is a module * `Submodule.Quotient.mkQ`: a linear map sending an element of `M` to `M ⧸ p` * `Submodule.quotEquivOfEq`: if `p` and `p'` are equal, their quotients are equivalent -/ -- For most of this file we work over a noncommutative ring section Ring namespace Submodule variable {R M : Type*} {r : R} {x y : M} [Ring R] [AddCommGroup M] [Module R M] variable (p p' : Submodule R M) open QuotientAddGroup /-- The equivalence relation associated to a submodule `p`, defined by `x ≈ y` iff `-x + y ∈ p`. Note this is equivalent to `y - x ∈ p`, but defined this way to be defeq to the `AddSubgroup` version, where commutativity can't be assumed. -/ def quotientRel : Setoid M := QuotientAddGroup.leftRel p.toAddSubgroup theorem quotientRel_def {x y : M} : p.quotientRel x y ↔ x - y ∈ p := Iff.trans (by rw [leftRel_apply, sub_eq_add_neg, neg_add, neg_neg] rfl) neg_mem_iff /-- The quotient of a module `M` by a submodule `p ⊆ M`. -/ instance hasQuotient : HasQuotient M (Submodule R M) := ⟨fun p => Quotient (quotientRel p)⟩ namespace Quotient /-- Map associating to an element of `M` the corresponding element of `M/p`, when `p` is a submodule of `M`. -/ def mk {p : Submodule R M} : M → M ⧸ p := Quotient.mk'' theorem mk'_eq_mk' {p : Submodule R M} (x : M) : @Quotient.mk' _ (quotientRel p) x = mk x := rfl theorem mk''_eq_mk {p : Submodule R M} (x : M) : (Quotient.mk'' x : M ⧸ p) = mk x := rfl theorem quot_mk_eq_mk {p : Submodule R M} (x : M) : (Quot.mk _ x : M ⧸ p) = mk x := rfl protected theorem eq' {x y : M} : (mk x : M ⧸ p) = mk y ↔ -x + y ∈ p := QuotientAddGroup.eq protected theorem eq {x y : M} : (mk x : M ⧸ p) = mk y ↔ x - y ∈ p := (Submodule.Quotient.eq' p).trans (leftRel_apply.symm.trans p.quotientRel_def) instance : Zero (M ⧸ p) where -- Use Quotient.mk'' instead of mk here because mk is not reducible. -- This would lead to non-defeq diamonds. -- See also the same comment at the One instance for Con. zero := Quotient.mk'' 0 instance : Inhabited (M ⧸ p) := ⟨0⟩ @[simp] theorem mk_zero : mk 0 = (0 : M ⧸ p) := rfl @[simp] theorem mk_eq_zero : (mk x : M ⧸ p) = 0 ↔ x ∈ p := by simpa using (Quotient.eq' p : mk x = 0 ↔ _) instance addCommGroup : AddCommGroup (M ⧸ p) := QuotientAddGroup.Quotient.addCommGroup p.toAddSubgroup @[simp] theorem mk_add : (mk (x + y) : M ⧸ p) = mk x + mk y := rfl @[simp] theorem mk_neg : (mk (-x) : M ⧸ p) = -(mk x) := rfl @[simp] theorem mk_sub : (mk (x - y) : M ⧸ p) = mk x - mk y := rfl variable {p} in @[simp] theorem mk_out (m : M ⧸ p) : Submodule.Quotient.mk (Quotient.out m) = m := Quotient.out_eq m protected nonrec lemma «forall» {P : M ⧸ p → Prop} : (∀ a, P a) ↔ ∀ a, P (mk a) := Quotient.forall theorem subsingleton_iff : Subsingleton (M ⧸ p) ↔ ∀ x : M, x ∈ p := by rw [subsingleton_iff_forall_eq 0, Submodule.Quotient.forall] simp_rw [Submodule.Quotient.mk_eq_zero] section SMul variable {S : Type*} [SMul S R] [SMul S M] [IsScalarTower S R M] (P : Submodule R M) instance instSMul' : SMul S (M ⧸ P) := ⟨fun a => Quotient.map' (a • ·) fun x y h => leftRel_apply.mpr <| by simpa using Submodule.smul_mem P (a • (1 : R)) (leftRel_apply.mp h)⟩ /-- Shortcut to help the elaborator in the common case. -/ instance instSMul : SMul R (M ⧸ P) := Quotient.instSMul' P @[simp] theorem mk_smul (r : S) (x : M) : (mk (r • x) : M ⧸ p) = r • mk x := rfl instance smulCommClass (T : Type*) [SMul T R] [SMul T M] [IsScalarTower T R M] [SMulCommClass S T M] : SMulCommClass S T (M ⧸ P) where smul_comm _x _y := Quotient.ind' fun _z => congr_arg mk (smul_comm _ _ _) instance isScalarTower (T : Type*) [SMul T R] [SMul T M] [IsScalarTower T R M] [SMul S T] [IsScalarTower S T M] : IsScalarTower S T (M ⧸ P) where smul_assoc _x _y := Quotient.ind' fun _z => congr_arg mk (smul_assoc _ _ _) instance isCentralScalar [SMul Sᵐᵒᵖ R] [SMul Sᵐᵒᵖ M] [IsScalarTower Sᵐᵒᵖ R M] [IsCentralScalar S M] : IsCentralScalar S (M ⧸ P) where op_smul_eq_smul _x := Quotient.ind' fun _z => congr_arg mk <| op_smul_eq_smul _ _ end SMul section Module variable {S : Type*} instance mulAction' [Monoid S] [SMul S R] [MulAction S M] [IsScalarTower S R M] (P : Submodule R M) : MulAction S (M ⧸ P) := fast_instance% Function.Surjective.mulAction mk Quot.mk_surjective <| Submodule.Quotient.mk_smul P instance mulAction (P : Submodule R M) : MulAction R (M ⧸ P) := Quotient.mulAction' P instance smulZeroClass' [SMul S R] [SMulZeroClass S M] [IsScalarTower S R M] (P : Submodule R M) : SMulZeroClass S (M ⧸ P) := ZeroHom.smulZeroClass ⟨mk, mk_zero _⟩ <| Submodule.Quotient.mk_smul P instance smulZeroClass (P : Submodule R M) : SMulZeroClass R (M ⧸ P) := Quotient.smulZeroClass' P instance distribSMul' [SMul S R] [DistribSMul S M] [IsScalarTower S R M] (P : Submodule R M) : DistribSMul S (M ⧸ P) := fast_instance% Function.Surjective.distribSMul {toFun := mk, map_zero' := rfl, map_add' := fun _ _ => rfl} Quot.mk_surjective (Submodule.Quotient.mk_smul P) instance distribSMul (P : Submodule R M) : DistribSMul R (M ⧸ P) := Quotient.distribSMul' P instance distribMulAction' [Monoid S] [SMul S R] [DistribMulAction S M] [IsScalarTower S R M] (P : Submodule R M) : DistribMulAction S (M ⧸ P) := fast_instance% Function.Surjective.distribMulAction {toFun := mk, map_zero' := rfl, map_add' := fun _ _ => rfl} Quot.mk_surjective (Submodule.Quotient.mk_smul P) instance distribMulAction (P : Submodule R M) : DistribMulAction R (M ⧸ P) := Quotient.distribMulAction' P instance module' [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] (P : Submodule R M) : Module S (M ⧸ P) := fast_instance% Function.Surjective.module _ {toFun := mk, map_zero' := by rfl, map_add' := fun _ _ => by rfl} Quot.mk_surjective (Submodule.Quotient.mk_smul P) instance module (P : Submodule R M) : Module R (M ⧸ P) := Quotient.module' P end Module @[elab_as_elim] theorem induction_on {C : M ⧸ p → Prop} (x : M ⧸ p) (H : ∀ z, C (Submodule.Quotient.mk z)) : C x := Quotient.inductionOn' x H theorem mk_surjective : Function.Surjective (@mk _ _ _ _ _ p) := by rintro ⟨x⟩ exact ⟨x, rfl⟩ universe u in instance {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] {N : Submodule R M} [Small.{u} M] : Small.{u} (M ⧸ N) := small_of_surjective (Submodule.Quotient.mk_surjective _) end Quotient section variable {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] theorem quot_hom_ext (f g : (M ⧸ p) →ₗ[R] M₂) (h : ∀ x : M, f (Quotient.mk x) = g (Quotient.mk x)) : f = g := LinearMap.ext fun x => Submodule.Quotient.induction_on _ x h /-- The map from a module `M` to the quotient of `M` by a submodule `p` as a linear map. -/ def mkQ : M →ₗ[R] M ⧸ p where toFun := Quotient.mk map_add' := by simp map_smul' := by simp @[simp] theorem mkQ_apply (x : M) : p.mkQ x = Quotient.mk x := rfl theorem mkQ_surjective : Function.Surjective p.mkQ := by rintro ⟨x⟩; exact ⟨x, rfl⟩ end variable {R₂ M₂ : Type*} [Ring R₂] [AddCommGroup M₂] [Module R₂ M₂] {τ₁₂ : R →+* R₂} /-- Two `LinearMap`s from a quotient module are equal if their compositions with `submodule.mkQ` are equal. See note [partially-applied ext lemmas]. -/ @[ext high] -- Increase priority so this applies before `LinearMap.ext` theorem linearMap_qext ⦃f g : M ⧸ p →ₛₗ[τ₁₂] M₂⦄ (h : f.comp p.mkQ = g.comp p.mkQ) : f = g := LinearMap.ext fun x => Submodule.Quotient.induction_on _ x <| (LinearMap.congr_fun h :) /-- Quotienting by equal submodules gives linearly equivalent quotients. -/ def quotEquivOfEq (h : p = p') : (M ⧸ p) ≃ₗ[R] M ⧸ p' := { @Quotient.congr _ _ (quotientRel p) (quotientRel p') (Equiv.refl _) fun a b => by subst h rfl with map_add' := by rintro ⟨x⟩ ⟨y⟩ rfl map_smul' := by rintro x ⟨y⟩ rfl } @[simp] theorem quotEquivOfEq_mk (h : p = p') (x : M) : Submodule.quotEquivOfEq p p' h (Submodule.Quotient.mk x) = (Submodule.Quotient.mk x) := rfl end Submodule end Ring
.lake/packages/mathlib/Mathlib/LinearAlgebra/LinearIndependent/Lemmas.lean
import Mathlib.Data.Fin.Tuple.Reflection import Mathlib.LinearAlgebra.Finsupp.SumProd import Mathlib.LinearAlgebra.LinearIndependent.Basic import Mathlib.LinearAlgebra.Pi import Mathlib.Logic.Equiv.Fin.Rotate import Mathlib.Tactic.FinCases import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Module import Mathlib.Tactic.NoncommRing /-! # Linear independence This file collects consequences of linear (in)dependence and includes specialized tests for specific families of vectors, requiring more theory to state. ## Main statements We prove several specialized tests for linear independence of families of vectors and of sets of vectors. * `linearIndependent_option`, `linearIndependent_fin_cons`, `linearIndependent_fin_succ`: type-specific tests for linear independence of families of vector fields; * `linearIndependent_insert`, `linearIndependent_pair`: linear independence tests for set operations In many cases we additionally provide dot-style operations (e.g., `LinearIndependent.union`) to make the linear independence tests usable as `hv.insert ha` etc. We also prove that, when working over a division ring, any family of vectors includes a linear independent subfamily spanning the same subspace. ## TODO Rework proofs to hold in semirings, by avoiding the path through `ker (Finsupp.linearCombination R v) = ⊥`. ## Tags linearly dependent, linear dependence, linearly independent, linear independence -/ assert_not_exists Cardinal noncomputable section open Function Set Submodule universe u' u variable {ι : Type u'} {ι' : Type*} {R : Type*} {K : Type*} {s : Set ι} variable {M : Type*} {M' : Type*} {V : Type u} section Semiring variable {v : ι → M} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M'] variable [Module R M] [Module R M'] variable (R) (v) variable {R v} /-- A finite family of vectors `v i` is linear independent iff the linear map that sends `c : ι → R` to `∑ i, c i • v i` is injective. -/ theorem Fintype.linearIndependent_iff'ₛ [Fintype ι] [DecidableEq ι] : LinearIndependent R v ↔ Injective (LinearMap.lsum R (fun _ ↦ R) ℕ fun i ↦ LinearMap.id.smulRight (v i)) := by simp [Fintype.linearIndependent_iffₛ, Injective, funext_iff] lemma LinearIndependent.pair_iffₛ {x y : M} : LinearIndependent R ![x, y] ↔ ∀ (s t s' t' : R), s • x + t • y = s' • x + t' • y → s = s' ∧ t = t' := by simp [Fintype.linearIndependent_iffₛ, Fin.forall_fin_two, ← FinVec.forall_iff]; rfl lemma LinearIndependent.eq_of_pair {x y : M} (h : LinearIndependent R ![x, y]) {s t s' t' : R} (h' : s • x + t • y = s' • x + t' • y) : s = s' ∧ t = t' := pair_iffₛ.mp h _ _ _ _ h' lemma LinearIndependent.eq_zero_of_pair' {x y : M} (h : LinearIndependent R ![x, y]) {s t : R} (h' : s • x = t • y) : s = 0 ∧ t = 0 := by suffices H : s = 0 ∧ 0 = t from ⟨H.1, H.2.symm⟩ exact h.eq_of_pair (by simpa using h') lemma LinearIndependent.eq_zero_of_pair {x y : M} (h : LinearIndependent R ![x, y]) {s t : R} (h' : s • x + t • y = 0) : s = 0 ∧ t = 0 := by replace h := @h (.single 0 s + .single 1 t) 0 ?_ · exact ⟨by simpa using congr($h 0), by simpa using congr($h 1)⟩ simpa section Indexed theorem linearIndepOn_iUnion_of_directed {η : Type*} {s : η → Set ι} (hs : Directed (· ⊆ ·) s) (h : ∀ i, LinearIndepOn R v (s i)) : LinearIndepOn R v (⋃ i, s i) := by by_cases hη : Nonempty η · refine linearIndepOn_of_finite (⋃ i, s i) fun t ht ft => ?_ rcases finite_subset_iUnion ft ht with ⟨I, fi, hI⟩ rcases hs.finset_le fi.toFinset with ⟨i, hi⟩ exact (h i).mono (Subset.trans hI <| iUnion₂_subset fun j hj => hi j (fi.mem_toFinset.2 hj)) · refine (linearIndepOn_empty R v).mono (t := iUnion (s ·)) ?_ rintro _ ⟨_, ⟨i, _⟩, _⟩ exact hη ⟨i⟩ theorem linearIndepOn_sUnion_of_directed {s : Set (Set ι)} (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, LinearIndepOn R v a) : LinearIndepOn R v (⋃₀ s) := by rw [sUnion_eq_iUnion] exact linearIndepOn_iUnion_of_directed hs.directed_val (by simpa using h) theorem linearIndepOn_biUnion_of_directed {η} {s : Set η} {t : η → Set ι} (hs : DirectedOn (t ⁻¹'o (· ⊆ ·)) s) (h : ∀ a ∈ s, LinearIndepOn R v (t a)) : LinearIndepOn R v (⋃ a ∈ s, t a) := by rw [biUnion_eq_iUnion] exact linearIndepOn_iUnion_of_directed (directed_comp.2 <| hs.directed_val) (by simpa using h) end Indexed section repr variable (hv : LinearIndependent R v) /-- See also `iSupIndep_iff_linearIndependent_of_ne_zero`. -/ theorem LinearIndependent.iSupIndep_span_singleton (hv : LinearIndependent R v) : iSupIndep fun i => R ∙ v i := by refine iSupIndep_def.mp fun i => ?_ rw [disjoint_iff_inf_le] intro m hm simp only [mem_inf, mem_span_singleton, iSup_subtype'] at hm rw [← span_range_eq_iSup] at hm obtain ⟨⟨r, rfl⟩, hm⟩ := hm suffices r = 0 by simp [this] apply hv.eq_zero_of_smul_mem_span i convert hm ext simp end repr section union open LinearMap Finsupp theorem linearIndependent_inl_union_inr' {v : ι → M} {v' : ι' → M'} (hv : LinearIndependent R v) (hv' : LinearIndependent R v') : LinearIndependent R (Sum.elim (inl R M M' ∘ v) (inr R M M' ∘ v')) := by have : linearCombination R (Sum.elim (inl R M M' ∘ v) (inr R M M' ∘ v')) = .prodMap (linearCombination R v) (linearCombination R v') ∘ₗ (sumFinsuppLEquivProdFinsupp R).toLinearMap := by ext (_ | _) <;> simp [linearCombination_comapDomain] rw [LinearIndependent, this] simpa [LinearMap.coe_prodMap] using ⟨hv, hv'⟩ theorem LinearIndependent.inl_union_inr {s : Set M} {t : Set M'} (hs : LinearIndependent R (fun x => x : s → M)) (ht : LinearIndependent R (fun x => x : t → M')) : LinearIndependent R (fun x => x : ↥(inl R M M' '' s ∪ inr R M M' '' t) → M × M') := by nontriviality R let e : s ⊕ t ≃ ↥(inl R M M' '' s ∪ inr R M M' '' t) := .ofBijective (Sum.elim (fun i ↦ ⟨_, .inl ⟨_, i.2, rfl⟩⟩) fun i ↦ ⟨_, .inr ⟨_, i.2, rfl⟩⟩) ⟨by rintro (_ | _) (_ | _) eq <;> simp [hs.ne_zero, ht.ne_zero] at eq <;> aesop, by rintro ⟨_, ⟨_, _, rfl⟩ | ⟨_, _, rfl⟩⟩ <;> aesop⟩ refine (linearIndependent_equiv' e ?_).mp (linearIndependent_inl_union_inr' hs ht) ext (_ | _) <;> rfl end union section Maximal universe v w variable (R) /-- TODO : refactor to use `Maximal`. -/ theorem exists_maximal_linearIndepOn' (v : ι → M) : ∃ s : Set ι, (LinearIndepOn R v s) ∧ ∀ t : Set ι, s ⊆ t → (LinearIndepOn R v t) → s = t := by let indep : Set ι → Prop := fun s => LinearIndepOn R v s let X := { I : Set ι // indep I } let r : X → X → Prop := fun I J => I.1 ⊆ J.1 have key : ∀ c : Set X, IsChain r c → indep (⋃ (I : X) (_ : I ∈ c), I) := by intro c hc dsimp [indep] rw [linearIndepOn_iffₛ] intro f hfsupp g hgsupp hsum rcases eq_empty_or_nonempty c with (rfl | hn) · rw [show f = 0 by simpa using hfsupp, show g = 0 by simpa using hgsupp] haveI : IsRefl X r := ⟨fun _ => Set.Subset.refl _⟩ classical obtain ⟨I, _I_mem, hI⟩ : ∃ I ∈ c, (f.support ∪ g.support : Set ι) ⊆ I := f.support.coe_union _ ▸ hc.directedOn.exists_mem_subset_of_finset_subset_biUnion hn <| by simpa using And.intro hfsupp hgsupp exact linearIndepOn_iffₛ.mp I.2 f (subset_union_left.trans hI) g (subset_union_right.trans hI) hsum have trans : Transitive r := fun I J K => Set.Subset.trans obtain ⟨⟨I, hli : indep I⟩, hmax : ∀ a, r ⟨I, hli⟩ a → r a ⟨I, hli⟩⟩ := exists_maximal_of_chains_bounded (fun c hc => ⟨⟨⋃ I ∈ c, (I : Set ι), key c hc⟩, fun I => Set.subset_biUnion_of_mem⟩) @trans exact ⟨I, hli, fun J hsub hli => Set.Subset.antisymm hsub (hmax ⟨J, hli⟩ hsub)⟩ end Maximal lemma Submodule.codisjoint_span_image_of_codisjoint (hv : Submodule.span R (Set.range v) = ⊤) {s t : Set ι} (hst : Codisjoint s t) : Codisjoint (Submodule.span R (v '' s)) (Submodule.span R (v '' t)) := by rw [Finsupp.span_image_eq_map_linearCombination, Finsupp.span_image_eq_map_linearCombination] refine Submodule.codisjoint_map ?_ (Finsupp.codisjoint_supported_supported hst) rwa [← LinearMap.range_eq_top, Finsupp.range_linearCombination] lemma LinearIndependent.isCompl_span_image (h₁ : LinearIndependent R v) (h₂ : Submodule.span R (Set.range v) = ⊤) {s t : Set ι} (hst : IsCompl s t) : IsCompl (Submodule.span R (v '' s)) (Submodule.span R (v '' t)) := ⟨h₁.disjoint_span_image hst.1, Submodule.codisjoint_span_image_of_codisjoint h₂ hst.2⟩ end Semiring section Module variable {v : ι → M} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] variable [Module R M] [Module R M'] /-- A finite family of vectors `v i` is linear independent iff the linear map that sends `c : ι → R` to `∑ i, c i • v i` has the trivial kernel. -/ theorem Fintype.linearIndependent_iff' [Fintype ι] [DecidableEq ι] : LinearIndependent R v ↔ LinearMap.ker (LinearMap.lsum R (fun _ ↦ R) ℕ fun i ↦ LinearMap.id.smulRight (v i)) = ⊥ := by simp [Fintype.linearIndependent_iff, LinearMap.ker_eq_bot', funext_iff] /-- `linearIndepOn_pair_iff` is a simpler version over fields. -/ lemma LinearIndepOn.pair_iff {i j : ι} (f : ι → M) (hij : i ≠ j) : LinearIndepOn R f {i,j} ↔ ∀ c d : R, c • f i + d • f j = 0 → c = 0 ∧ d = 0 := by classical rw [linearIndepOn_iff''] refine ⟨fun h c d hcd ↦ ?_, fun h t g ht hg0 h0 ↦ ?_⟩ · specialize h {i, j} (Pi.single i c + Pi.single j d) simpa +contextual [Finset.sum_pair, Pi.single_apply, hij, hij.symm, hcd] using h have ht' : t ⊆ {i, j} := by simpa [← Finset.coe_subset] rw [Finset.sum_subset ht', Finset.sum_pair hij] at h0 · obtain ⟨hi0, hj0⟩ := h _ _ h0 exact fun k hkt ↦ Or.elim (ht hkt) (fun h ↦ h ▸ hi0) (fun h ↦ h ▸ hj0) simp +contextual [hg0] section Pair variable {x y : M} /-- Also see `LinearIndependent.pair_iff'` for a simpler version over fields. -/ lemma LinearIndependent.pair_iff : LinearIndependent R ![x, y] ↔ ∀ (s t : R), s • x + t • y = 0 → s = 0 ∧ t = 0 := by rw [← linearIndepOn_univ, ← Finset.coe_univ, show @Finset.univ (Fin 2) _ = {0,1} from rfl, Finset.coe_insert, Finset.coe_singleton, LinearIndepOn.pair_iff _ (by trivial)] simp lemma LinearIndependent.pair_symm_iff : LinearIndependent R ![x, y] ↔ LinearIndependent R ![y, x] := by suffices ∀ x y : M, LinearIndependent R ![x, y] → LinearIndependent R ![y, x] by tauto simp only [LinearIndependent.pair_iff] intro x y h s t specialize h t s rwa [add_comm, and_comm] @[simp] lemma LinearIndependent.pair_neg_left_iff : LinearIndependent R ![-x, y] ↔ LinearIndependent R ![x, y] := by rw [pair_iff, pair_iff] refine ⟨fun h s t hst ↦ ?_, fun h s t hst ↦ ?_⟩ <;> simpa using h (-s) t (by simpa using hst) @[simp] lemma LinearIndependent.pair_neg_right_iff : LinearIndependent R ![x, -y] ↔ LinearIndependent R ![x, y] := by rw [pair_symm_iff, pair_neg_left_iff, pair_symm_iff] variable {S : Type*} [CommRing S] [Module S R] [Module S M] [SMulCommClass S R M] [IsScalarTower S R M] [NoZeroSMulDivisors S R] (a b c d : S) lemma LinearIndependent.pair_smul_iff {u : S} (hu : u ≠ 0) : LinearIndependent R ![u • x, u • y] ↔ LinearIndependent R ![x, y] := by simp only [LinearIndependent.pair_iff] refine ⟨fun h s t hst ↦ ?_, fun h s t hst ↦ ?_⟩ · exact h s t (by rw [← smul_comm u s, ← smul_comm u t, ← smul_add, hst, smul_zero]) · specialize h (u • s) (u • t) (by rw [smul_assoc, smul_assoc, smul_comm u s, smul_comm u t, hst]) exact ⟨(smul_eq_zero_iff_right hu).mp h.1, (smul_eq_zero_iff_right hu).mp h.2⟩ private lemma LinearIndependent.pair_add_smul_add_smul_iff_aux (h : a * d ≠ b * c) (h' : LinearIndependent R ![x, y]) : LinearIndependent R ![a • x + b • y, c • x + d • y] := by simp only [LinearIndependent.pair_iff] at h' ⊢ intro s t hst specialize h' (a • s + c • t) (b • s + d • t) (by simp only [← hst, smul_add, add_smul, smul_assoc, smul_comm a s, smul_comm c t, smul_comm b s, smul_comm d t]; abel) obtain ⟨h₁, h₂⟩ := h' constructor · suffices (a * d) • s = (b * c) • s by by_contra hs; exact h (_root_.smul_left_injective S hs ‹_›) calc (a * d) • s = d • a • s := by rw [mul_comm, mul_smul] _ = - (d • c • t) := by rw [eq_neg_iff_add_eq_zero, ← smul_add, h₁, smul_zero] _ = (b * c) • s := ?_ · rw [mul_comm, mul_smul, neg_eq_iff_add_eq_zero, add_comm, smul_comm d c, ← smul_add, h₂, smul_zero] · suffices (a * d) • t = (b * c) • t by by_contra ht; exact h (_root_.smul_left_injective S ht ‹_›) calc (a * d) • t = a • d • t := by rw [mul_smul] _ = - (a • b • s) := by rw [eq_neg_iff_add_eq_zero, ← smul_add, add_comm, h₂, smul_zero] _ = (b * c) • t := ?_ · rw [mul_smul, neg_eq_iff_add_eq_zero, smul_comm a b, ← smul_add, h₁, smul_zero] @[simp] lemma LinearIndependent.pair_add_smul_add_smul_iff [Nontrivial R] : LinearIndependent R ![a • x + b • y, c • x + d • y] ↔ LinearIndependent R ![x, y] ∧ a * d ≠ b * c := by rcases eq_or_ne (a * d) (b * c) with h | h · suffices ¬ LinearIndependent R ![a • x + b • y, c • x + d • y] by simpa [h] rw [pair_iff] push_neg by_cases hbd : b = 0 ∧ d = 0 · simp only [hbd.1, hbd.2, zero_smul, add_zero] by_cases hac : a = 0 ∧ c = 0; · exact ⟨1, 0, by simp [hac.1, hac.2], by simp⟩ refine ⟨c • 1, -a • 1, ?_, by aesop⟩ simp only [smul_assoc, one_smul, neg_smul] module refine ⟨d • 1, -b • 1, ?_, by contrapose! hbd; simp_all⟩ simp only [smul_add, smul_assoc, one_smul, smul_smul, mul_comm d, h] module refine ⟨fun h' ↦ ⟨?_, h⟩, fun ⟨h₁, h₂⟩ ↦ pair_add_smul_add_smul_iff_aux _ _ _ _ h₂ h₁⟩ suffices LinearIndependent R ![(a * d - b * c) • x, (a * d - b * c) • y] by rwa [pair_smul_iff (sub_ne_zero_of_ne h)] at this convert pair_add_smul_add_smul_iff_aux d (-b) (-c) a (by simpa [mul_comm d a]) h' using 1 ext i; fin_cases i <;> simp <;> module @[simp] lemma LinearIndependent.pair_add_smul_right_iff : LinearIndependent R ![x, c • x + y] ↔ LinearIndependent R ![x, y] := by rcases subsingleton_or_nontrivial S with hS | hS; · simp [hS.elim c 0] nontriviality R simpa using pair_add_smul_add_smul_iff (x := x) (y := y) 1 0 c 1 @[simp] lemma LinearIndependent.pair_add_smul_left_iff : LinearIndependent R ![x + b • y, y] ↔ LinearIndependent R ![x, y] := by rcases subsingleton_or_nontrivial S with hS | hS; · simp [hS.elim b 0] nontriviality R simpa using pair_add_smul_add_smul_iff (x := x) (y := y) 1 b 0 1 @[simp] lemma LinearIndependent.pair_add_right_iff : LinearIndependent R ![x, x + y] ↔ LinearIndependent R ![x, y] := by suffices ∀ x y : M, LinearIndependent R ![x, x + y] → LinearIndependent R ![x, y] from ⟨this x y, fun h ↦ by simpa using this (-x) (x + y) (by simpa)⟩ simp only [LinearIndependent.pair_iff] intro x y h s t h' obtain ⟨h₁, h₂⟩ := h (s - t) t (by rw [sub_smul, smul_add, ← h']; abel) rw [h₂, sub_zero] at h₁ tauto @[simp] lemma LinearIndependent.pair_add_left_iff : LinearIndependent R ![x + y, y] ↔ LinearIndependent R ![x, y] := by rw [← pair_symm_iff, add_comm, pair_add_right_iff, pair_symm_iff] end Pair end Module /-! ### Properties which require `Ring R` -/ section Module variable {v : ι → M} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] variable [Module R M] [Module R M'] theorem linearIndepOn_id_iUnion_finite {f : ι → Set M} (hl : ∀ i, LinearIndepOn R id (f i)) (hd : ∀ i, ∀ t : Set ι, t.Finite → i ∉ t → Disjoint (span R (f i)) (⨆ i ∈ t, span R (f i))) : LinearIndepOn R id (⋃ i, f i) := by classical rw [iUnion_eq_iUnion_finset f] apply linearIndepOn_iUnion_of_directed · apply directed_of_isDirected_le exact fun t₁ t₂ ht => iUnion_mono fun i => iUnion_subset_iUnion_const fun h => ht h intro t induction t using Finset.induction_on with | empty => simp | insert i s his ih => rw [Finset.set_biUnion_insert] refine (hl _).id_union ih ?_ rw [span_iUnion₂] exact hd i s s.finite_toSet his theorem linearIndependent_iUnion_finite {η : Type*} {ιs : η → Type*} {f : ∀ j : η, ιs j → M} (hindep : ∀ j, LinearIndependent R (f j)) (hd : ∀ i, ∀ t : Set η, t.Finite → i ∉ t → Disjoint (span R (range (f i))) (⨆ i ∈ t, span R (range (f i)))) : LinearIndependent R fun ji : Σ j, ιs j => f ji.1 ji.2 := by nontriviality R apply LinearIndependent.of_linearIndepOn_id_range · rintro ⟨x₁, x₂⟩ ⟨y₁, y₂⟩ hxy by_cases h_cases : x₁ = y₁ · subst h_cases refine Sigma.eq rfl ?_ rw [LinearIndependent.injective (hindep _) hxy] · have h0 : f x₁ x₂ = 0 := by apply disjoint_def.1 (hd x₁ {y₁} (finite_singleton y₁) fun h => h_cases (eq_of_mem_singleton h)) (f x₁ x₂) (subset_span (mem_range_self _)) rw [iSup_singleton] simp only at hxy rw [hxy] exact subset_span (mem_range_self y₂) exact False.elim ((hindep x₁).ne_zero _ h0) rw [range_sigma_eq_iUnion_range] apply linearIndepOn_id_iUnion_finite (fun j => (hindep j).linearIndepOn_id) hd open LinearMap variable (R) in theorem exists_maximal_linearIndepOn (v : ι → M) : ∃ s : Set ι, (LinearIndepOn R v s) ∧ ∀ i ∉ s, ∃ a : R, a ≠ 0 ∧ a • v i ∈ span R (v '' s) := by classical rcases exists_maximal_linearIndepOn' R v with ⟨I, hIlinind, hImaximal⟩ use I, hIlinind intro i hi specialize hImaximal (I ∪ {i}) (by simp) set J := I ∪ {i} with hJ have memJ : ∀ {x}, x ∈ J ↔ x = i ∨ x ∈ I := by simp [hJ] have hiJ : i ∈ J := by simp [J] have h := by refine mt hImaximal ?_ · intro h2 rw [h2] at hi exact absurd hiJ hi obtain ⟨f, supp_f, sum_f, f_ne⟩ := linearDepOn_iff.mp h have hfi : f i ≠ 0 := by contrapose hIlinind refine linearDepOn_iff.mpr ⟨f, ?_, sum_f, f_ne⟩ simp only [Finsupp.mem_supported, hJ] at supp_f ⊢ rintro x hx refine (memJ.mp (supp_f hx)).resolve_left ?_ rintro rfl exact hIlinind (Finsupp.mem_support_iff.mp hx) use f i, hfi have hfi' : i ∈ f.support := Finsupp.mem_support_iff.mpr hfi rw [← Finset.insert_erase hfi', Finset.sum_insert (Finset.notMem_erase _ _), add_eq_zero_iff_eq_neg] at sum_f rw [sum_f] refine neg_mem (sum_mem fun c hc => smul_mem _ _ (subset_span ⟨c, ?_, rfl⟩)) exact (memJ.mp (supp_f (Finset.erase_subset _ _ hc))).resolve_left (Finset.ne_of_mem_erase hc) @[stacks 0CKM] lemma linearIndependent_algHom_toLinearMap (K M L) [CommSemiring K] [Semiring M] [Algebra K M] [CommRing L] [IsDomain L] [Algebra K L] : LinearIndependent L (AlgHom.toLinearMap : (M →ₐ[K] L) → M →ₗ[K] L) := by apply LinearIndependent.of_comp (LinearMap.ltoFun K M L) exact (linearIndependent_monoidHom M L).comp (RingHom.toMonoidHom ∘ AlgHom.toRingHom) (fun _ _ e ↦ AlgHom.ext (DFunLike.congr_fun e :)) lemma linearIndependent_algHom_toLinearMap' (K M L) [CommRing K] [Semiring M] [Algebra K M] [CommRing L] [IsDomain L] [Algebra K L] [NoZeroSMulDivisors K L] : LinearIndependent K (AlgHom.toLinearMap : (M →ₐ[K] L) → M →ₗ[K] L) := (linearIndependent_algHom_toLinearMap K M L).restrict_scalars' K lemma LinearMap.injective_of_linearIndependent {N : Type*} [AddCommGroup N] [Module R N] {f : M →ₗ[R] N} {ι : Type*} {v : ι → M} (hv : Submodule.span R (.range v) = ⊤) (hli : LinearIndependent R (f ∘ v)) : Function.Injective f := by refine (injective_iff_map_eq_zero _).mpr fun x hx ↦ ?_ have : x ∈ Submodule.span R (.range v) := by rw [hv]; exact mem_top obtain ⟨c, rfl⟩ := Finsupp.mem_span_range_iff_exists_finsupp.mp this simp only [map_finsuppSum, map_smul] at hx obtain rfl := linearIndependent_iff.mp hli c hx simp lemma LinearMap.bijective_of_linearIndependent_of_span_eq_top {N : Type*} [AddCommGroup N] [Module R N] {f : M →ₗ[R] N} {ι : Type*} {v : ι → M} (hv : Submodule.span R (Set.range v) = ⊤) (hli : LinearIndependent R (f ∘ v)) (hsp : Submodule.span R (Set.range <| f ∘ v) = ⊤) : Function.Bijective f := by refine ⟨LinearMap.injective_of_linearIndependent hv hli, ?_⟩ rw [Set.range_comp, ← Submodule.map_span, hv, Submodule.map_top] at hsp rwa [← range_eq_top] /-- Version of `LinearIndepOn.insert` that works when the scalars are not a field. -/ lemma LinearIndepOn.insert' {s : Set ι} {i : ι} (hs : LinearIndepOn R v s) (hx : ∀ r : R, r • v i ∈ Submodule.span R (v '' s) → r = 0) : LinearIndepOn R v (insert i s) := by rw [← Set.union_singleton] refine hs.union (.singleton' fun r hr ↦ hx _ <| by simp [hr]) ?_ simp +contextual [disjoint_span_singleton'', hx] /-- Version of `LinearIndepOn.id_insert` that works when the scalars are not a field. -/ lemma LinearIndepOn.id_insert' {s : Set M} {x : M} (hs : LinearIndepOn R id s) (hx : ∀ r : R, r • x ∈ Submodule.span R s → r = 0) : LinearIndepOn R id (insert x s) := hs.insert' <| by simpa end Module /-! ### Properties which require `DivisionRing K` These can be considered generalizations of properties of linear independence in vector spaces. -/ section Module variable [DivisionRing K] [AddCommGroup V] [Module K V] variable {v : ι → V} {s t : Set V} {x y : V} open Submodule /- TODO: some of the following proofs can generalized with a zero_ne_one predicate type class (instead of a data containing type class) -/ theorem mem_span_insert_exchange : x ∈ span K (insert y s) → x ∉ span K s → y ∈ span K (insert x s) := by simp only [mem_span_insert, forall_exists_index, and_imp] rintro a z hz rfl h refine ⟨a⁻¹, -a⁻¹ • z, smul_mem _ _ hz, ?_⟩ have a0 : a ≠ 0 := by rintro rfl simp_all match_scalars <;> simp [a0] protected theorem LinearIndepOn.insert {s : Set ι} {x : ι} (hs : LinearIndepOn K v s) (hx : v x ∉ span K (v '' s)) : LinearIndepOn K v (insert x s) := by rw [← union_singleton] have x0 : v x ≠ 0 := fun h => hx (h ▸ zero_mem _) apply hs.union (LinearIndepOn.singleton x0) rwa [image_singleton, disjoint_span_singleton' x0] protected theorem LinearIndepOn.id_insert (hs : LinearIndepOn K id s) (hx : x ∉ span K s) : LinearIndepOn K id (insert x s) := hs.insert ((image_id s).symm ▸ hx) theorem linearIndependent_option' : LinearIndependent K (fun o => Option.casesOn' o x v : Option ι → V) ↔ LinearIndependent K v ∧ x ∉ Submodule.span K (range v) := by -- Porting note: Explicit universe level is required in `Equiv.optionEquivSumPUnit`. rw [← linearIndependent_equiv (Equiv.optionEquivSumPUnit.{u'} ι).symm, linearIndependent_sum, @range_unique _ PUnit, @linearIndependent_unique_iff PUnit, disjoint_span_singleton] dsimp [(· ∘ ·)] refine ⟨fun h => ⟨h.1, fun hx => h.2.1 <| h.2.2 hx⟩, fun h => ⟨h.1, ?_, fun hx => (h.2 hx).elim⟩⟩ rintro rfl exact h.2 (zero_mem _) theorem LinearIndependent.option (hv : LinearIndependent K v) (hx : x ∉ Submodule.span K (range v)) : LinearIndependent K (fun o => Option.casesOn' o x v : Option ι → V) := linearIndependent_option'.2 ⟨hv, hx⟩ theorem linearIndependent_option {v : Option ι → V} : LinearIndependent K v ↔ LinearIndependent K (v ∘ (↑) : ι → V) ∧ v none ∉ Submodule.span K (range (v ∘ (↑) : ι → V)) := by simp only [← linearIndependent_option', Option.casesOn'_none_coe] theorem linearIndepOn_insert {s : Set ι} {a : ι} {f : ι → V} (has : a ∉ s) : LinearIndepOn K f (insert a s) ↔ LinearIndepOn K f s ∧ f a ∉ Submodule.span K (f '' s) := by classical rw [LinearIndepOn, LinearIndepOn, ← linearIndependent_equiv ((Equiv.optionEquivSumPUnit _).trans (Equiv.Set.insert has).symm), linearIndependent_option] simp only [comp_def] rw [range_comp'] simp theorem linearIndepOn_id_insert (hxs : x ∉ s) : LinearIndepOn K id (insert x s) ↔ LinearIndepOn K id s ∧ x ∉ Submodule.span K s := (linearIndepOn_insert (f := id) hxs).trans <| by simp theorem linearIndepOn_insert_iff {s : Set ι} {a : ι} {f : ι → V} : LinearIndepOn K f (insert a s) ↔ LinearIndepOn K f s ∧ (f a ∈ span K (f '' s) → a ∈ s) := by by_cases has : a ∈ s · simp [insert_eq_of_mem has, has] simp [linearIndepOn_insert has, has] theorem linearIndepOn_id_insert_iff {a : V} {s : Set V} : LinearIndepOn K id (insert a s) ↔ LinearIndepOn K id s ∧ (a ∈ span K s → a ∈ s) := by simpa using linearIndepOn_insert_iff (a := a) (f := id) theorem LinearIndepOn.mem_span_iff {s : Set ι} {a : ι} {f : ι → V} (h : LinearIndepOn K f s) : f a ∈ Submodule.span K (f '' s) ↔ (LinearIndepOn K f (insert a s) → a ∈ s) := by by_cases has : a ∈ s · exact iff_of_true (subset_span <| mem_image_of_mem f has) fun _ ↦ has simp [linearIndepOn_insert_iff, h, has] /-- A shortcut to a convenient form for the negation in `LinearIndepOn.mem_span_iff`. -/ theorem LinearIndepOn.notMem_span_iff {s : Set ι} {a : ι} {f : ι → V} (h : LinearIndepOn K f s) : f a ∉ Submodule.span K (f '' s) ↔ LinearIndepOn K f (insert a s) ∧ a ∉ s := by rw [h.mem_span_iff, _root_.not_imp] @[deprecated (since := "2025-05-23")] alias LinearIndepOn.not_mem_span_iff := LinearIndepOn.notMem_span_iff theorem LinearIndepOn.mem_span_iff_id {s : Set V} {a : V} (h : LinearIndepOn K id s) : a ∈ Submodule.span K s ↔ (LinearIndepOn K id (insert a s) → a ∈ s) := by simpa using h.mem_span_iff (a := a) theorem LinearIndepOn.notMem_span_iff_id {s : Set V} {a : V} (h : LinearIndepOn K id s) : a ∉ Submodule.span K s ↔ LinearIndepOn K id (insert a s) ∧ a ∉ s := by rw [h.mem_span_iff_id, _root_.not_imp] @[deprecated (since := "2025-05-23")] alias LinearIndepOn.not_mem_span_iff_id := LinearIndepOn.notMem_span_iff_id theorem linearIndepOn_id_pair {x y : V} (hx : x ≠ 0) (hy : ∀ a : K, a • x ≠ y) : LinearIndepOn K id {x, y} := by rw [pair_comm]; exact .id_insert (.singleton hx) <| by simpa [mem_span_singleton] /-- `LinearIndepOn.pair_iff` is a version that works over arbitrary rings. -/ theorem linearIndepOn_pair_iff {i j : ι} (v : ι → V) (hij : i ≠ j) (hi : v i ≠ 0) : LinearIndepOn K v {i, j} ↔ ∀ (c : K), c • v i ≠ v j := by rw [pair_comm] convert linearIndepOn_insert (s := {i}) (a := j) hij.symm simp [hi, mem_span_singleton] /-- Also see `LinearIndependent.pair_iff` for the version over arbitrary rings. -/ theorem LinearIndependent.pair_iff' {x y : V} (hx : x ≠ 0) : LinearIndependent K ![x, y] ↔ ∀ a : K, a • x ≠ y := by rw [← linearIndepOn_univ, ← Finset.coe_univ, show @Finset.univ (Fin 2) _ = {0,1} from rfl, Finset.coe_insert, Finset.coe_singleton, linearIndepOn_pair_iff _ (by simp) (by simpa)] simp theorem linearIndependent_fin_cons {n} {v : Fin n → V} : LinearIndependent K (Fin.cons x v : Fin (n + 1) → V) ↔ LinearIndependent K v ∧ x ∉ Submodule.span K (range v) := by rw [← linearIndependent_equiv (finSuccEquiv n).symm, linearIndependent_option] exact Iff.rfl theorem linearIndependent_fin_snoc {n} {v : Fin n → V} : LinearIndependent K (Fin.snoc v x : Fin (n + 1) → V) ↔ LinearIndependent K v ∧ x ∉ Submodule.span K (range v) := by rw [Fin.snoc_eq_cons_rotate, ← Function.comp_def, linearIndependent_equiv, linearIndependent_fin_cons] /-- See `LinearIndependent.fin_cons'` for an uglier version that works if you only have a module over a semiring. -/ theorem LinearIndependent.fin_cons {n} {v : Fin n → V} (hv : LinearIndependent K v) (hx : x ∉ Submodule.span K (range v)) : LinearIndependent K (Fin.cons x v : Fin (n + 1) → V) := linearIndependent_fin_cons.2 ⟨hv, hx⟩ theorem linearIndependent_fin_succ {n} {v : Fin (n + 1) → V} : LinearIndependent K v ↔ LinearIndependent K (Fin.tail v) ∧ v 0 ∉ Submodule.span K (range <| Fin.tail v) := by rw [← linearIndependent_fin_cons, Fin.cons_self_tail] theorem linearIndependent_fin_succ' {n} {v : Fin (n + 1) → V} : LinearIndependent K v ↔ LinearIndependent K (Fin.init v) ∧ v (Fin.last _) ∉ Submodule.span K (range <| Fin.init v) := by rw [← linearIndependent_fin_snoc, Fin.snoc_init_self] /-- Equivalence between `k + 1` vectors of length `n` and `k` vectors of length `n` along with a vector in the complement of their span. -/ def equiv_linearIndependent (n : ℕ) : { s : Fin (n + 1) → V // LinearIndependent K s } ≃ Σ s : { s : Fin n → V // LinearIndependent K s }, ((Submodule.span K (Set.range (s : Fin n → V)))ᶜ : Set V) where toFun s := ⟨⟨Fin.tail s.val, (linearIndependent_fin_succ.mp s.property).left⟩, ⟨s.val 0, (linearIndependent_fin_succ.mp s.property).right⟩⟩ invFun s := ⟨Fin.cons s.2.val s.1.val, linearIndependent_fin_cons.mpr ⟨s.1.property, s.2.property⟩⟩ left_inv _ := by simp only [Fin.cons_self_tail, Subtype.coe_eta] right_inv := fun ⟨_, _⟩ => by simp only [Fin.cons_zero, Subtype.coe_eta, Sigma.mk.inj_iff, Fin.tail_cons, heq_eq_eq, and_self] theorem linearIndependent_fin2 {f : Fin 2 → V} : LinearIndependent K f ↔ f 1 ≠ 0 ∧ ∀ a : K, a • f 1 ≠ f 0 := by rw [linearIndependent_fin_succ, linearIndependent_unique_iff, range_unique, mem_span_singleton, not_exists, show Fin.tail f default = f 1 by rw [← Fin.succ_zero_eq_one]; rfl] theorem exists_linearIndepOn_extension {s t : Set ι} (hs : LinearIndepOn K v s) (hst : s ⊆ t) : ∃ b ⊆ t, s ⊆ b ∧ v '' t ⊆ span K (v '' b) ∧ LinearIndepOn K v b := by obtain ⟨b, sb, h⟩ := by refine zorn_subset_nonempty { b | b ⊆ t ∧ LinearIndepOn K v b} ?_ _ ⟨hst, hs⟩ · refine fun c hc cc _c0 => ⟨⋃₀ c, ⟨?_, ?_⟩, fun x => ?_⟩ · exact sUnion_subset fun x xc => (hc xc).1 · exact linearIndepOn_sUnion_of_directed cc.directedOn fun x xc => (hc xc).2 · exact subset_sUnion_of_mem refine ⟨b, h.prop.1, sb, fun _ ⟨x, hx, hvx⟩ => by_contra fun hn ↦ hn ?_, h.prop.2⟩ subst hvx exact subset_span <| mem_image_of_mem v <| h.mem_of_prop_insert ⟨insert_subset hx h.prop.1, h.prop.2.insert hn⟩ theorem exists_linearIndepOn_id_extension (hs : LinearIndepOn K id s) (hst : s ⊆ t) : ∃ b ⊆ t, s ⊆ b ∧ t ⊆ span K b ∧ LinearIndepOn K id b := by convert exists_linearIndepOn_extension hs hst <;> simp variable (K t) theorem exists_linearIndependent : ∃ b ⊆ t, span K b = span K t ∧ LinearIndependent K ((↑) : b → V) := by obtain ⟨b, hb₁, -, hb₂, hb₃⟩ := exists_linearIndepOn_id_extension (linearIndependent_empty K V) (Set.empty_subset t) exact ⟨b, hb₁, (span_eq_of_le _ hb₂ (Submodule.span_mono hb₁)).symm, hb₃⟩ /-- Indexed version of `exists_linearIndependent`. -/ lemma exists_linearIndependent' (v : ι → V) : ∃ (κ : Type u') (a : κ → ι), Injective a ∧ Submodule.span K (Set.range (v ∘ a)) = Submodule.span K (Set.range v) ∧ LinearIndependent K (v ∘ a) := by obtain ⟨t, ht, hsp, hli⟩ := exists_linearIndependent K (Set.range v) choose f hf using ht let s : Set ι := Set.range (fun a : t ↦ f a.property) have hs {i : ι} (hi : i ∈ s) : v i ∈ t := by obtain ⟨a, rfl⟩ := hi; simp [hf] let f' (a : s) : t := ⟨v a.val, hs a.property⟩ refine ⟨s, Subtype.val, Subtype.val_injective, hsp.symm ▸ by congr; aesop, ?_⟩ · rw [← show Subtype.val ∘ f' = v ∘ Subtype.val by ext; simp [f']] apply hli.comp rintro ⟨i, x, rfl⟩ ⟨j, y, rfl⟩ hij simp only [Subtype.ext_iff, hf, f'] at hij simp [hij] variable {K} {s t : Set ι} /-- `LinearIndepOn.extend` adds vectors to a linear independent set `s ⊆ t` until it spans all elements of `t`. -/ noncomputable def LinearIndepOn.extend (hs : LinearIndepOn K v s) (hst : s ⊆ t) : Set ι := Classical.choose (exists_linearIndepOn_extension hs hst) theorem LinearIndepOn.extend_subset (hs : LinearIndepOn K v s) (hst : s ⊆ t) : hs.extend hst ⊆ t := let ⟨hbt, _hsb, _htb, _hli⟩ := Classical.choose_spec (exists_linearIndepOn_extension hs hst) hbt theorem LinearIndepOn.subset_extend (hs : LinearIndepOn K v s) (hst : s ⊆ t) : s ⊆ hs.extend hst := let ⟨_hbt, hsb, _htb, _hli⟩ := Classical.choose_spec (exists_linearIndepOn_extension hs hst) hsb theorem LinearIndepOn.image_subset_span_image_extend (hs : LinearIndepOn K v s) (hst : s ⊆ t) : v '' t ⊆ span K (v '' hs.extend hst) := let ⟨_hbt, _hsb, htb, _hli⟩ := Classical.choose_spec (exists_linearIndepOn_extension hs hst) htb theorem LinearIndepOn.subset_span_extend {s t : Set V} (hs : LinearIndepOn K id s) (hst : s ⊆ t) : t ⊆ span K (hs.extend hst) := by convert hs.image_subset_span_image_extend hst <;> simp theorem LinearIndepOn.span_image_extend_eq_span_image (hs : LinearIndepOn K v s) (hst : s ⊆ t) : span K (v '' hs.extend hst) = span K (v '' t) := le_antisymm (span_mono (image_mono (hs.extend_subset hst))) (span_le.2 (hs.image_subset_span_image_extend hst)) theorem LinearIndepOn.span_extend_eq_span {s t : Set V} (hs : LinearIndepOn K id s) (hst : s ⊆ t) : span K (hs.extend hst) = span K t := le_antisymm (span_mono (hs.extend_subset hst)) (span_le.2 (hs.subset_span_extend hst)) theorem LinearIndepOn.linearIndepOn_extend (hs : LinearIndepOn K v s) (hst : s ⊆ t) : LinearIndepOn K v (hs.extend hst) := let ⟨_hbt, _hsb, _htb, hli⟩ := Classical.choose_spec (exists_linearIndepOn_extension hs hst) hli -- TODO(Mario): rewrite? theorem exists_of_linearIndepOn_of_finite_span {s : Set V} {t : Finset V} (hs : LinearIndepOn K id s) (hst : s ⊆ (span K ↑t : Submodule K V)) : ∃ t' : Finset V, ↑t' ⊆ s ∪ ↑t ∧ s ⊆ ↑t' ∧ t'.card = t.card := by classical have : ∀ t : Finset V, ∀ s' : Finset V, ↑s' ⊆ s → s ∩ ↑t = ∅ → s ⊆ (span K ↑(s' ∪ t) : Submodule K V) → ∃ t' : Finset V, ↑t' ⊆ s ∪ ↑t ∧ s ⊆ ↑t' ∧ t'.card = (s' ∪ t).card := fun t => Finset.induction_on t (fun s' hs' _ hss' => have : s = ↑s' := eq_of_linearIndepOn_id_of_span_subtype hs hs' <| by simpa using hss' ⟨s', by simp [this]⟩) fun b₁ t hb₁t ih s' hs' hst hss' => have hb₁s : b₁ ∉ s := fun h => by have : b₁ ∈ s ∩ ↑(insert b₁ t) := ⟨h, Finset.mem_insert_self _ _⟩ rwa [hst] at this have hb₁s' : b₁ ∉ s' := fun h => hb₁s <| hs' h have hst : s ∩ ↑t = ∅ := eq_empty_of_subset_empty <| -- Porting note: `-subset_inter_iff` required. Subset.trans (by simp [inter_subset_inter, -subset_inter_iff]) (le_of_eq hst) Classical.by_cases (p := s ⊆ (span K ↑(s' ∪ t) : Submodule K V)) (fun this => let ⟨u, hust, hsu, Eq⟩ := ih _ hs' hst this have hb₁u : b₁ ∉ u := fun h => (hust h).elim hb₁s hb₁t ⟨insert b₁ u, by simp [insert_subset_insert hust], Subset.trans hsu (by simp), by simp [Eq, hb₁t, hb₁s', hb₁u]⟩) fun this => let ⟨b₂, hb₂s, hb₂t⟩ := not_subset.mp this have hb₂t' : b₂ ∉ s' ∪ t := fun h => hb₂t <| subset_span h have : s ⊆ (span K ↑(insert b₂ s' ∪ t) : Submodule K V) := fun b₃ hb₃ => by have : ↑(s' ∪ insert b₁ t) ⊆ insert b₁ (insert b₂ ↑(s' ∪ t) : Set V) := by simp only [insert_eq, union_subset_union, Subset.refl, subset_union_right, Finset.union_insert, Finset.coe_insert] have hb₃ : b₃ ∈ span K (insert b₁ (insert b₂ ↑(s' ∪ t) : Set V)) := span_mono this (hss' hb₃) have : s ⊆ (span K (insert b₁ ↑(s' ∪ t)) : Submodule K V) := by simpa [insert_eq, -singleton_union, -union_singleton] using hss' have hb₁ : b₁ ∈ span K (insert b₂ ↑(s' ∪ t)) := mem_span_insert_exchange (this hb₂s) hb₂t rw [span_insert_eq_span hb₁] at hb₃; simpa using hb₃ let ⟨u, hust, hsu, eq⟩ := ih _ (by simp [insert_subset_iff, hb₂s, hs']) hst this ⟨u, Subset.trans hust <| union_subset_union (Subset.refl _) (by simp [subset_insert]), hsu, by simp [eq, hb₂t', hb₁t, hb₁s']⟩ have eq : ((t.filter fun x => x ∈ s) ∪ t.filter fun x => x ∉ s) = t := by ext1 x by_cases x ∈ s <;> simp [*] apply Exists.elim (this (t.filter fun x => x ∉ s) (t.filter fun x => x ∈ s) (by simp [Set.subset_def]) (by simp +contextual [Set.ext_iff]) (by rwa [eq])) intro u h exact ⟨u, Subset.trans h.1 (by simp +contextual [subset_def, or_imp]), h.2.1, by simp only [h.2.2, eq]⟩ theorem exists_finite_card_le_of_finite_of_linearIndependent_of_span {s t : Set V} (ht : t.Finite) (hs : LinearIndepOn K id s) (hst : s ⊆ span K t) : ∃ h : s.Finite, h.toFinset.card ≤ ht.toFinset.card := have : s ⊆ (span K ↑ht.toFinset : Submodule K V) := by simpa let ⟨u, _hust, hsu, Eq⟩ := exists_of_linearIndepOn_of_finite_span hs this have : s.Finite := u.finite_toSet.subset hsu ⟨this, by rw [← Eq]; exact Finset.card_le_card <| Finset.coe_subset.mp <| by simp [hsu]⟩ end Module
.lake/packages/mathlib/Mathlib/LinearAlgebra/LinearIndependent/Basic.lean
import Mathlib.Algebra.BigOperators.Fin import Mathlib.LinearAlgebra.LinearIndependent.Defs /-! # Linear independence This file collects basic consequences of linear (in)dependence and includes specialized tests for specific families of vectors. ## Main statements We prove several specialized tests for linear independence of families of vectors and of sets of vectors. * `linearIndependent_empty_type`: a family indexed by an empty type is linearly independent; * `linearIndependent_unique_iff`: if `ι` is a singleton, then `LinearIndependent K v` is equivalent to `v default ≠ 0`; * `linearIndependent_sum`: type-specific test for linear independence of families of vector fields; * `linearIndependent_singleton`: linear independence tests for set operations. In many cases we additionally provide dot-style operations (e.g., `LinearIndependent.union`) to make the linear independence tests usable as `hv.insert ha` etc. ## TODO Rework proofs to hold in semirings, by avoiding the path through `ker (Finsupp.linearCombination R v) = ⊥`. ## Tags linearly dependent, linear dependence, linearly independent, linear independence -/ assert_not_exists Cardinal noncomputable section open Function Set Submodule universe u' u variable {ι : Type u'} {ι' : Type*} {R : Type*} {K : Type*} {s : Set ι} variable {M : Type*} {M' : Type*} {V : Type u} section Semiring variable {v : ι → M} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M'] variable [Module R M] [Module R M'] variable (R) (v) variable {R v} /-- A set of linearly independent vectors in a module `M` over a semiring `K` is also linearly independent over a subring `R` of `K`. See also `LinearIndependent.restrict_scalars'` for a version with more convenient typeclass assumptions. TODO : `LinearIndepOn` version. -/ theorem LinearIndependent.restrict_scalars [Semiring K] [SMulWithZero R K] [Module K M] [IsScalarTower R K M] (hinj : Injective fun r : R ↦ r • (1 : K)) (li : LinearIndependent K v) : LinearIndependent R v := by intro x y hxy let f := fun r : R => r • (1 : K) have := @li (x.mapRange f (by simp [f])) (y.mapRange f (by simp [f])) ?_ · ext i exact hinj congr($this i) simpa [Finsupp.linearCombination, f, Finsupp.sum_mapRange_index] variable (R) in theorem LinearIndependent.restrict_scalars' [Semiring K] [SMulWithZero R K] [Module K M] [IsScalarTower R K M] [FaithfulSMul R K] [IsScalarTower R K K] {v : ι → M} (li : LinearIndependent K v) : LinearIndependent R v := restrict_scalars ((faithfulSMul_iff_injective_smul_one R K).mp inferInstance) li /-- If `v` is an injective family of vectors such that `f ∘ v` is linearly independent, then `v` spans a submodule disjoint from the kernel of `f`. TODO : `LinearIndepOn` version. -/ theorem Submodule.range_ker_disjoint {f : M →ₗ[R] M'} (hv : LinearIndependent R (f ∘ v)) : Disjoint (span R (range v)) (LinearMap.ker f) := by rw [LinearIndependent, Finsupp.linearCombination_linear_comp] at hv rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_linearCombination, map_inf_eq_map_inf_comap, (LinearMap.ker_comp _ _).symm.trans (LinearMap.ker_eq_bot_of_injective hv), inf_bot_eq, map_bot] /-- If `M / R` and `M' / R'` are modules, `i : R' → R` is a map, `j : M →+ M'` is a monoid map, such that they are both injective, and compatible with the scalar multiplications on `M` and `M'`, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map_injOn`. TODO : `LinearIndepOn` version. -/ theorem LinearIndependent.map_of_injective_injectiveₛ {R' M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : R' → R) (j : M →+ M') (hi : Injective i) (hj : Injective j) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : LinearIndependent R' (j ∘ v) := by rw [linearIndependent_iff'ₛ] at hv ⊢ intro S r₁ r₂ H s hs simp_rw [comp_apply, ← hc, ← map_sum] at H exact hi <| hv _ _ _ (hj H) s hs /-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a surjective map, and `j : M →+ M'` is an injective monoid map, such that the scalar multiplications on `M` and `M'` are compatible, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map_injOn`. TODO : `LinearIndepOn` version. -/ theorem LinearIndependent.map_of_surjective_injectiveₛ {R' M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : R → R') (j : M →+ M') (hi : Surjective i) (hj : Injective j) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : LinearIndependent R' (j ∘ v) := by obtain ⟨i', hi'⟩ := hi.hasRightInverse refine hv.map_of_injective_injectiveₛ i' j (fun _ _ h ↦ ?_) hj fun r m ↦ ?_ · apply_fun i at h rwa [hi', hi'] at h rw [hc (i' r) m, hi'] /-- If a linear map is injective on the span of a family of linearly independent vectors, then the family stays linearly independent after composing with the linear map. See `LinearIndependent.map` for the version with `Set.InjOn` replaced by `Disjoint` when working over a ring. -/ theorem LinearIndependent.map_injOn (hv : LinearIndependent R v) (f : M →ₗ[R] M') (hf_inj : Set.InjOn f (span R (Set.range v))) : LinearIndependent R (f ∘ v) := (f.linearIndependent_iff_of_injOn hf_inj).mpr hv theorem LinearIndepOn.map_injOn (hv : LinearIndepOn R v s) (f : M →ₗ[R] M') (hf_inj : Set.InjOn f (span R (v '' s))) : LinearIndepOn R (f ∘ v) s := (f.linearIndepOn_iff_of_injOn hf_inj).mpr hv theorem LinearIndepOn.comp_of_image {s : Set ι'} {f : ι' → ι} (h : LinearIndepOn R v (f '' s)) (hf : InjOn f s) : LinearIndepOn R (v ∘ f) s := LinearIndependent.comp h _ (Equiv.Set.imageOfInjOn _ _ hf).injective theorem LinearIndepOn.image_of_comp (f : ι → ι') (g : ι' → M) (hs : LinearIndepOn R (g ∘ f) s) : LinearIndepOn R g (f '' s) := by nontriviality R have : InjOn f s := injOn_iff_injective.2 hs.injective.of_comp exact (linearIndependent_equiv' (Equiv.Set.imageOfInjOn f s this) rfl).1 hs theorem LinearIndepOn.id_image (hs : LinearIndepOn R v s) : LinearIndepOn R id (v '' s) := LinearIndepOn.image_of_comp v id hs theorem LinearIndepOn_iff_linearIndepOn_image_injOn [Nontrivial R] : LinearIndepOn R v s ↔ LinearIndepOn R id (v '' s) ∧ InjOn v s := ⟨fun h ↦ ⟨h.id_image, h.injOn⟩, fun h ↦ (linearIndepOn_iff_image h.2).2 h.1⟩ theorem linearIndepOn_congr {w : ι → M} (h : EqOn v w s) : LinearIndepOn R v s ↔ LinearIndepOn R w s := by rw [LinearIndepOn, LinearIndepOn] convert Iff.rfl using 2 ext x exact h.symm x.2 theorem LinearIndepOn.congr {w : ι → M} (hli : LinearIndepOn R v s) (h : EqOn v w s) : LinearIndepOn R w s := (linearIndepOn_congr h).1 hli theorem LinearIndependent.group_smul {G : Type*} [hG : Group G] [MulAction G R] [SMul G M] [IsScalarTower G R M] [SMulCommClass G R M] {v : ι → M} (hv : LinearIndependent R v) (w : ι → G) : LinearIndependent R (w • v) := by rw [linearIndependent_iff''ₛ] at hv ⊢ intro s g₁ g₂ hgs hsum i refine (Group.isUnit (w i)).smul_left_cancel.mp ?_ refine hv s (fun i ↦ w i • g₁ i) (fun i ↦ w i • g₂ i) (fun i hi ↦ ?_) ?_ i · simp_rw [hgs i hi] · simpa only [smul_assoc, smul_comm] using hsum @[simp] theorem LinearIndependent.group_smul_iff {G : Type*} [hG : Group G] [MulAction G R] [MulAction G M] [IsScalarTower G R M] [SMulCommClass G R M] (v : ι → M) (w : ι → G) : LinearIndependent R (w • v) ↔ LinearIndependent R v := by refine ⟨fun h ↦ ?_, fun h ↦ h.group_smul w⟩ convert h.group_smul (fun i ↦ (w i)⁻¹) simp [funext_iff] -- This lemma cannot be proved with `LinearIndependent.group_smul` since the action of -- `Rˣ` on `R` is not commutative. theorem LinearIndependent.units_smul {v : ι → M} (hv : LinearIndependent R v) (w : ι → Rˣ) : LinearIndependent R (w • v) := by rw [linearIndependent_iff''ₛ] at hv ⊢ intro s g₁ g₂ hgs hsum i rw [← (w i).mul_left_inj] refine hv s (fun i ↦ g₁ i • w i) (fun i ↦ g₂ i • w i) (fun i hi ↦ ?_) ?_ i · simp_rw [hgs i hi] · simpa only [smul_eq_mul, mul_smul, Pi.smul_apply'] using hsum @[simp] theorem LinearIndependent.units_smul_iff (v : ι → M) (w : ι → Rˣ) : LinearIndependent R (w • v) ↔ LinearIndependent R v := by refine ⟨fun h ↦ ?_, fun h ↦ h.units_smul w⟩ convert h.units_smul (fun i ↦ (w i)⁻¹) simp [funext_iff] theorem linearIndependent_span (hs : LinearIndependent R v) : LinearIndependent R (M := span R (range v)) (fun i : ι ↦ ⟨v i, subset_span (mem_range_self i)⟩) := LinearIndependent.of_comp (span R (range v)).subtype hs /-- Every finite subset of a linearly independent set is linearly independent. -/ theorem linearIndependent_finset_map_embedding_subtype (s : Set M) (li : LinearIndependent R ((↑) : s → M)) (t : Finset s) : LinearIndependent R ((↑) : Finset.map (Embedding.subtype s) t → M) := li.comp (fun _ ↦ ⟨_, by aesop⟩) <| by intro; simp section Indexed theorem linearIndepOn_of_finite (s : Set ι) (H : ∀ t ⊆ s, Set.Finite t → LinearIndepOn R v t) : LinearIndepOn R v s := linearIndepOn_iffₛ.2 fun f hf g hg eq ↦ linearIndepOn_iffₛ.1 (H _ (union_subset hf hg) <| (Finset.finite_toSet _).union <| Finset.finite_toSet _) f Set.subset_union_left g Set.subset_union_right eq end Indexed /-- Linear independent families are injective, even if you multiply either side. -/ theorem LinearIndependent.eq_of_smul_apply_eq_smul_apply {M : Type*} [AddCommMonoid M] [Module R M] {v : ι → M} (li : LinearIndependent R v) (c d : R) (i j : ι) (hc : c ≠ 0) (h : c • v i = d • v j) : i = j := by have h_single_eq : Finsupp.single i c = Finsupp.single j d := li <| by simpa [Finsupp.linearCombination_apply] using h rcases (Finsupp.single_eq_single_iff ..).mp h_single_eq with (⟨H, _⟩ | ⟨hc, _⟩) · exact H · contradiction section Subtype /-! The following lemmas use the subtype defined by a set in `M` as the index set `ι`. -/ theorem LinearIndependent.disjoint_span_image (hv : LinearIndependent R v) {s t : Set ι} (hs : Disjoint s t) : Disjoint (Submodule.span R <| v '' s) (Submodule.span R <| v '' t) := by simp only [disjoint_def, Finsupp.mem_span_image_iff_linearCombination] rintro _ ⟨l₁, hl₁, rfl⟩ ⟨l₂, hl₂, H⟩ rw [hv.finsuppLinearCombination_injective.eq_iff] at H; subst l₂ have : l₁ = 0 := Submodule.disjoint_def.mp (Finsupp.disjoint_supported_supported hs) _ hl₁ hl₂ simp [this] theorem LinearIndependent.notMem_span_image [Nontrivial R] (hv : LinearIndependent R v) {s : Set ι} {x : ι} (h : x ∉ s) : v x ∉ Submodule.span R (v '' s) := by have h' : v x ∈ Submodule.span R (v '' {x}) := by rw [Set.image_singleton] exact mem_span_singleton_self (v x) intro w apply LinearIndependent.ne_zero x hv refine disjoint_def.1 (hv.disjoint_span_image ?_) (v x) h' w simpa using h @[deprecated (since := "2025-05-23")] alias LinearIndependent.not_mem_span_image := LinearIndependent.notMem_span_image theorem LinearIndependent.linearCombination_ne_of_notMem_support [Nontrivial R] (hv : LinearIndependent R v) {x : ι} (f : ι →₀ R) (h : x ∉ f.support) : f.linearCombination R v ≠ v x := by replace h : x ∉ (f.support : Set ι) := h intro w have p : ∀ x ∈ Finsupp.supported R R f.support, Finsupp.linearCombination R v x ≠ f.linearCombination R v := by simpa [← w, Finsupp.span_image_eq_map_linearCombination] using hv.notMem_span_image h exact p f (f.mem_supported_support R) rfl @[deprecated (since := "2025-05-23")] alias LinearIndependent.linearCombination_ne_of_not_mem_support := LinearIndependent.linearCombination_ne_of_notMem_support end Subtype theorem LinearIndepOn.id_imageₛ {s : Set M} {f : M →ₗ[R] M'} (hs : LinearIndepOn R id s) (hf_inj : Set.InjOn f (span R s)) : LinearIndepOn R id (f '' s) := id_image <| hs.map_injOn f (by simpa using hf_inj) theorem surjective_of_linearIndependent_of_span [Nontrivial R] (hv : LinearIndependent R v) (f : ι' ↪ ι) (hss : range v ⊆ span R (range (v ∘ f))) : Surjective f := by intro i let repr : (span R (range (v ∘ f)) : Type _) → ι' →₀ R := (hv.comp f f.injective).repr let l := (repr ⟨v i, hss (mem_range_self i)⟩).mapDomain f have h_total_l : Finsupp.linearCombination R v l = v i := by dsimp only [l] rw [Finsupp.linearCombination_mapDomain] rw [(hv.comp f f.injective).linearCombination_repr] have h_total_eq : Finsupp.linearCombination R v l = Finsupp.linearCombination R v (Finsupp.single i 1) := by rw [h_total_l, Finsupp.linearCombination_single, one_smul] have l_eq : l = _ := hv h_total_eq dsimp only [l] at l_eq rw [← Finsupp.embDomain_eq_mapDomain] at l_eq rcases Finsupp.single_of_embDomain_single (repr ⟨v i, _⟩) f i (1 : R) zero_ne_one.symm l_eq with ⟨i', hi'⟩ use i' exact hi'.2 theorem eq_of_linearIndepOn_id_of_span_subtype [Nontrivial R] {s t : Set M} (hs : LinearIndepOn R id s) (h : t ⊆ s) (hst : s ⊆ span R t) : s = t := by let f : t ↪ s := ⟨fun x => ⟨x.1, h x.2⟩, fun a b hab => Subtype.coe_injective (Subtype.mk.inj hab)⟩ have h_surj : Surjective f := by apply surjective_of_linearIndependent_of_span hs f _ convert hst <;> simp [f, comp_def] change s = t apply Subset.antisymm _ h intro x hx rcases h_surj ⟨x, hx⟩ with ⟨y, hy⟩ convert y.mem rw [← Subtype.mk.inj hy] theorem le_of_span_le_span [Nontrivial R] {s t u : Set M} (hl : LinearIndepOn R id u) (hsu : s ⊆ u) (htu : t ⊆ u) (hst : span R s ≤ span R t) : s ⊆ t := by have := eq_of_linearIndepOn_id_of_span_subtype (hl.mono (Set.union_subset hsu htu)) Set.subset_union_right (Set.union_subset (Set.Subset.trans subset_span hst) subset_span) rw [← this]; apply Set.subset_union_left theorem span_le_span_iff [Nontrivial R] {s t u : Set M} (hl : LinearIndependent R ((↑) : u → M)) (hsu : s ⊆ u) (htu : t ⊆ u) : span R s ≤ span R t ↔ s ⊆ t := ⟨le_of_span_le_span hl hsu htu, span_mono⟩ end Semiring section Module variable {v : ι → M} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] variable [Module R M] [Module R M'] open Finset in /-- If `∑ i, f i • v i = ∑ i, g i • v i`, then for all `i`, `f i = g i`. -/ theorem LinearIndependent.eq_coords_of_eq [Fintype ι] {v : ι → M} (hv : LinearIndependent R v) {f : ι → R} {g : ι → R} (heq : ∑ i, f i • v i = ∑ i, g i • v i) (i : ι) : f i = g i := by rw [← sub_eq_zero, ← sum_sub_distrib] at heq simp_rw [← sub_smul] at heq exact sub_eq_zero.mp ((linearIndependent_iff'.mp hv) univ (fun i ↦ f i - g i) heq i (mem_univ i)) /-- If `v` is a linearly independent family of vectors and the kernel of a linear map `f` is disjoint with the submodule spanned by the vectors of `v`, then `f ∘ v` is a linearly independent family of vectors. See also `LinearIndependent.map'` for a special case assuming `ker f = ⊥`. -/ theorem LinearIndependent.map (hv : LinearIndependent R v) {f : M →ₗ[R] M'} (hf_inj : Disjoint (span R (range v)) (LinearMap.ker f)) : LinearIndependent R (f ∘ v) := (f.linearIndependent_iff_of_disjoint hf_inj).mpr hv /-- An injective linear map sends linearly independent families of vectors to linearly independent families of vectors. See also `LinearIndependent.map` for a more general statement. -/ theorem LinearIndependent.map' (hv : LinearIndependent R v) (f : M →ₗ[R] M') (hf_inj : LinearMap.ker f = ⊥) : LinearIndependent R (f ∘ v) := hv.map <| by simp_rw [hf_inj, disjoint_bot_right] /-- If `M / R` and `M' / R'` are modules, `i : R' → R` is a map, `j : M →+ M'` is a monoid map, such that they send non-zero elements to non-zero elements, and compatible with the scalar multiplications on `M` and `M'`, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map'`. -/ theorem LinearIndependent.map_of_injective_injective {R' M' : Type*} [Ring R'] [AddCommGroup M'] [Module R' M'] (hv : LinearIndependent R v) (i : R' → R) (j : M →+ M') (hi : ∀ r, i r = 0 → r = 0) (hj : ∀ m, j m = 0 → m = 0) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : LinearIndependent R' (j ∘ v) := by rw [linearIndependent_iff'] at hv ⊢ intro S r' H s hs simp_rw [comp_apply, ← hc, ← map_sum] at H exact hi _ <| hv _ _ (hj _ H) s hs /-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a surjective map which maps zero to zero, `j : M →+ M'` is a monoid map which sends non-zero elements to non-zero elements, such that the scalar multiplications on `M` and `M'` are compatible, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map'`. -/ theorem LinearIndependent.map_of_surjective_injective {R' M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : R → R') (j : M →+ M') (hi : Surjective i) (hj : ∀ m, j m = 0 → m = 0) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : LinearIndependent R' (j ∘ v) := hv.map_of_surjective_injectiveₛ i _ hi ((injective_iff_map_eq_zero _).mpr hj) hc /-- If `f` is an injective linear map, then the family `f ∘ v` is linearly independent if and only if the family `v` is linearly independent. -/ protected theorem LinearMap.linearIndependent_iff (f : M →ₗ[R] M') (hf_inj : LinearMap.ker f = ⊥) : LinearIndependent R (f ∘ v) ↔ LinearIndependent R v := f.linearIndependent_iff_of_disjoint <| by simp_rw [hf_inj, disjoint_bot_right] /-- See `LinearIndependent.fin_cons` for a family of elements in a vector space. -/ theorem LinearIndependent.fin_cons' {m : ℕ} (x : M) (v : Fin m → M) (hli : LinearIndependent R v) (x_ortho : ∀ (c : R) (y : Submodule.span R (Set.range v)), c • x + y = (0 : M) → c = 0) : LinearIndependent R (Fin.cons x v : Fin m.succ → M) := by rw [Fintype.linearIndependent_iff] at hli ⊢ rintro g total_eq j simp_rw [Fin.sum_univ_succ, Fin.cons_zero, Fin.cons_succ] at total_eq have : g 0 = 0 := by refine x_ortho (g 0) ⟨∑ i : Fin m, g i.succ • v i, ?_⟩ total_eq exact sum_mem fun i _ => smul_mem _ _ (subset_span ⟨i, rfl⟩) rw [this, zero_smul, zero_add] at total_eq exact Fin.cases this (hli _ total_eq) j end Module /-! ### Properties which require `Ring R` -/ section Module variable {v : ι → M} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] variable [Module R M] [Module R M'] theorem linearIndependent_sum {v : ι ⊕ ι' → M} : LinearIndependent R v ↔ LinearIndependent R (v ∘ Sum.inl) ∧ LinearIndependent R (v ∘ Sum.inr) ∧ Disjoint (Submodule.span R (range (v ∘ Sum.inl))) (Submodule.span R (range (v ∘ Sum.inr))) := by classical rw [range_comp v, range_comp v] refine ⟨?_, ?_⟩ · intro h refine ⟨h.comp _ Sum.inl_injective, h.comp _ Sum.inr_injective, ?_⟩ exact h.disjoint_span_image <| isCompl_range_inl_range_inr.disjoint rintro ⟨hl, hr, hlr⟩ rw [linearIndependent_iff'] at * intro s g hg i hi have : ((∑ i ∈ s.preimage Sum.inl Sum.inl_injective.injOn, (fun x => g x • v x) (Sum.inl i)) + ∑ i ∈ s.preimage Sum.inr Sum.inr_injective.injOn, (fun x => g x • v x) (Sum.inr i)) = 0 := by -- Porting note: `g` must be specified. rw [Finset.sum_preimage' (g := fun x => g x • v x), Finset.sum_preimage' (g := fun x => g x • v x), ← Finset.sum_union, ← Finset.filter_or] · simpa only [← mem_union, range_inl_union_range_inr, mem_univ, Finset.filter_true] · exact Finset.disjoint_filter.2 fun x _ hx => disjoint_left.1 isCompl_range_inl_range_inr.disjoint hx rw [← eq_neg_iff_add_eq_zero] at this rw [disjoint_def'] at hlr have A := by refine hlr _ (sum_mem fun i _ => ?_) _ (neg_mem <| sum_mem fun i _ => ?_) this · exact smul_mem _ _ (subset_span ⟨Sum.inl i, mem_range_self _, rfl⟩) · exact smul_mem _ _ (subset_span ⟨Sum.inr i, mem_range_self _, rfl⟩) rcases i with i | i · exact hl _ _ A i (Finset.mem_preimage.2 hi) · rw [this, neg_eq_zero] at A exact hr _ _ A i (Finset.mem_preimage.2 hi) theorem LinearIndependent.sum_type {v' : ι' → M} (hv : LinearIndependent R v) (hv' : LinearIndependent R v') (h : Disjoint (Submodule.span R (range v)) (Submodule.span R (range v'))) : LinearIndependent R (Sum.elim v v') := linearIndependent_sum.2 ⟨hv, hv', h⟩ theorem LinearIndepOn.union {t : Set ι} (hs : LinearIndepOn R v s) (ht : LinearIndepOn R v t) (hdj : Disjoint (span R (v '' s)) (span R (v '' t))) : LinearIndepOn R v (s ∪ t) := by nontriviality R classical have hli := LinearIndependent.sum_type hs ht (by rwa [← image_eq_range, ← image_eq_range]) have hdj := (hdj.of_span₀ hs.zero_notMem_image).of_image rw [LinearIndepOn] convert (hli.comp _ (Equiv.Set.union hdj).injective) with ⟨x, hx | hx⟩ · rw [comp_apply, Equiv.Set.union_apply_left _ hx, Sum.elim_inl] rw [comp_apply, Equiv.Set.union_apply_right _ hx, Sum.elim_inr] theorem LinearIndepOn.id_union {s t : Set M} (hs : LinearIndepOn R id s) (ht : LinearIndepOn R id t) (hdj : Disjoint (span R s) (span R t)) : LinearIndepOn R id (s ∪ t) := hs.union ht (by simpa) theorem linearIndepOn_union_iff {t : Set ι} (hdj : Disjoint s t) : LinearIndepOn R v (s ∪ t) ↔ LinearIndepOn R v s ∧ LinearIndepOn R v t ∧ Disjoint (span R (v '' s)) (span R (v '' t)) := by refine ⟨fun h ↦ ⟨h.mono subset_union_left, h.mono subset_union_right, ?_⟩, fun h ↦ h.1.union h.2.1 h.2.2⟩ convert h.disjoint_span_image (s := (↑) ⁻¹' s) (t := (↑) ⁻¹' t) (hdj.preimage _) <;> aesop theorem linearIndepOn_id_union_iff {s t : Set M} (hdj : Disjoint s t) : LinearIndepOn R id (s ∪ t) ↔ LinearIndepOn R id s ∧ LinearIndepOn R id t ∧ Disjoint (span R s) (span R t) := by rw [linearIndepOn_union_iff hdj, image_id, image_id] open LinearMap theorem LinearIndepOn.image {s : Set M} {f : M →ₗ[R] M'} (hs : LinearIndepOn R id s) (hf_inj : Disjoint (span R s) (LinearMap.ker f)) : LinearIndepOn R id (f '' s) := hs.id_imageₛ <| LinearMap.injOn_of_disjoint_ker le_rfl hf_inj -- See, for example, Keith Conrad's note [ConradLinearChar] -- <https://kconrad.math.uconn.edu/blurbs/galoistheory/linearchar.pdf> /-- Dedekind's linear independence of characters -/ @[stacks 0CKL] theorem linearIndependent_monoidHom (G : Type*) [MulOneClass G] (L : Type*) [CommRing L] [NoZeroDivisors L] : LinearIndependent L (M := G → L) (fun f => f : (G →* L) → G → L) := by letI := Classical.decEq (G →* L) letI : MulAction L L := DistribMulAction.toMulAction -- We prove linear independence by showing that only the trivial linear combination vanishes. apply linearIndependent_iff'.2 intro s induction s using Finset.induction_on with | empty => simp | insert a s has ih => intro g hg -- Here -- * `a` is a new character we will insert into the `Finset` of characters `s`, -- * `ih` is the fact that only the trivial linear combination of characters in `s` is zero -- * `hg` is the fact that `g` are the coefficients of a linear combination summing to zero -- and it remains to prove that `g` vanishes on `insert a s`. -- We now make the key calculation: -- For any character `i` in the original `Finset`, we have `g i • i = g i • a` as functions -- on the monoid `G`. have h1 (i) (his : i ∈ s) : (g i • i : G → L) = g i • a := by ext x rw [← sub_eq_zero] apply ih (fun j => g j * j x - g j * a x) _ i his ext y -- After that, it's just a chase scene. calc (∑ i ∈ s, (g i * i x - g i * a x) • i : G → L) y = (∑ i ∈ s, g i * i x * i y) - ∑ i ∈ s, g i * a x * i y := by simp [sub_mul] _ = (∑ i ∈ insert a s, g i * i x * i y) - ∑ i ∈ insert a s, g i * a x * i y := by simp [Finset.sum_insert has] _ = (∑ i ∈ insert a s, g i * (i x * i y)) - ∑ i ∈ insert a s, a x * (g i * i y) := by congrm ∑ i ∈ insert a s, ?_ - ∑ i ∈ insert a s, ?_ · rw [mul_assoc] · rw [mul_assoc, mul_left_comm] _ = (∑ i ∈ insert a s, g i • i : G → L) (x * y) - a x * (∑ i ∈ insert a s, (g i • (i : G → L))) y := by simp [Finset.mul_sum] _ = 0 := by rw [hg]; simp -- On the other hand, since `a` is not already in `s`, for any character `i ∈ s` -- there is some element of the monoid on which it differs from `a`. have h2 (i) (his : i ∈ s) : ∃ y, i y ≠ a y := by by_contra! hia obtain rfl : i = a := MonoidHom.ext hia contradiction -- From these two facts we deduce that `g` actually vanishes on `s`, have h3 (i) (his : i ∈ s) : g i = 0 := by let ⟨y, hy⟩ := h2 i his have h : g i • i y = g i • a y := congr_fun (h1 i his) y rw [← sub_eq_zero, ← smul_sub, smul_eq_zero] at h exact h.resolve_right (sub_ne_zero_of_ne hy) -- And so, using the fact that the linear combination over `s` and over `insert a s` both -- vanish, we deduce that `g a = 0`. have h4 : g a = 0 := calc g a = g a * 1 := (mul_one _).symm _ = (g a • a : G → L) 1 := by rw [← a.map_one]; rfl _ = (∑ i ∈ insert a s, g i • i : G → L) 1 := by rw [Finset.sum_insert has, Finset.sum_eq_zero, add_zero] simp +contextual [h3] _ = 0 := by rw [hg]; rfl -- Now we're done; the last two facts together imply that `g` vanishes on every element -- of `insert a s`. exact (Finset.forall_mem_insert ..).2 ⟨h4, h3⟩ end Module section Nontrivial variable [Ring R] [AddCommGroup M] [Module R M] [Nontrivial R] [NoZeroSMulDivisors R M] {v : ι → M} {i : ι} lemma linearIndependent_unique_iff [Unique ι] : LinearIndependent R v ↔ v default ≠ 0 := by refine ⟨?_, .of_subsingleton _⟩ simpa [linearIndependent_iff, Finsupp.linearCombination_unique, Finsupp.ext_iff, Unique.forall_iff, or_imp] using fun h hv ↦ by simpa using h (.single default 1) hv @[deprecated LinearIndependent.of_subsingleton (since := "2025-11-11")] alias ⟨_, linearIndependent_unique⟩ := linearIndependent_unique_iff variable (R) in @[simp] theorem linearIndepOn_singleton_iff : LinearIndepOn R v {i} ↔ v i ≠ 0 := ⟨fun h ↦ h.ne_zero rfl, .singleton⟩ @[simp] theorem linearIndependent_subsingleton_index_iff [Subsingleton ι] (f : ι → M) : LinearIndependent R f ↔ ∀ i, f i ≠ 0 := by obtain (he | he) := isEmpty_or_nonempty ι · simp [linearIndependent_empty_type] obtain ⟨_⟩ := (unique_iff_subsingleton_and_nonempty (α := ι)).2 ⟨by assumption, he⟩ rw [linearIndependent_unique_iff] exact ⟨fun h i ↦ by rwa [Unique.eq_default i], fun h ↦ h _⟩ end Nontrivial
.lake/packages/mathlib/Mathlib/LinearAlgebra/LinearIndependent/Defs.lean
import Mathlib.Algebra.Order.Sub.Basic import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.Lean.Expr.ExtraRecognizers /-! # Linear independence This file defines linear independence in a module or vector space. It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light. We define `LinearIndependent R v` as `Function.Injective (Finsupp.linearCombination R v)`. Here `Finsupp.linearCombination` is the linear map sending a function `f : ι →₀ R` with finite support to the linear combination of vectors from `v` with these coefficients. The goal of this file is to define linear independence and to prove that several other statements are equivalent to this one, including `ker (Finsupp.linearCombination R v) = ⊥` and some versions with explicitly written linear combinations. ## Main definitions All definitions are given for families of vectors, i.e. `v : ι → M` where `M` is the module or vector space and `ι : Type*` is an arbitrary indexing type. * `LinearIndependent R v` states that the elements of the family `v` are linearly independent. * `LinearIndepOn R v s` states that the elements of the family `v` indexed by the members of the set `s : Set ι` are linearly independent. * `LinearIndependent.repr hv x` returns the linear combination representing `x : span R (range v)` on the linearly independent vectors `v`, given `hv : LinearIndependent R v` (using classical choice). `LinearIndependent.repr hv` is provided as a linear map. * `LinearIndependent.Maximal` states that there exists no linear independent family that strictly includes the given one. ## Main results * `Fintype.linearIndependent_iff`: if `ι` is a finite type, then any function `f : ι → R` has finite support, so we can reformulate the statement using `∑ i : ι, f i • v i` instead of a sum over an auxiliary `s : Finset ι`; ## Implementation notes We use families instead of sets in `LinearIndependent` because it allows us to say that two identical vectors are linearly dependent. If you want to use sets, use `LinearIndepOn id s` given a set `s : Set M`. The lemmas `LinearIndependent.linearIndepOn_id` and `LinearIndependent.of_linearIndepOn_id_range` connect those two worlds. In this file we prove some variants of results on different kinds of (semi)rings. We distinguish them by using suffixes in their names, e.g. `linearIndependent_iffₛ` for semirings, `linearIndependent_iffₒₛ` for (canonically) ordered semirings, and `linearIndependent_iff` (without suffix) for rings. ## TODO This file contains much more than definitions. Rework proofs to hold in semirings, by avoiding the path through `ker (Finsupp.linearCombination R v) = ⊥`. ## Tags linearly dependent, linear dependence, linearly independent, linear independence -/ assert_not_exists Cardinal noncomputable section open Function Set Submodule universe u' u variable {ι : Type u'} {ι' : Type*} {R : Type*} {K : Type*} {s : Set ι} variable {M : Type*} {M' : Type*} {V : Type u} section Semiring variable {v : ι → M} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M'] variable [Module R M] [Module R M'] variable (R) (v) /-- `LinearIndependent R v` states the family of vectors `v` is linearly independent over `R`. -/ def LinearIndependent : Prop := Injective (Finsupp.linearCombination R v) open Lean PrettyPrinter.Delaborator SubExpr in /-- Delaborator for `LinearIndependent` that suggests pretty printing with type hints in case the family of vectors is over a `Set`. Type hints look like `LinearIndependent fun (v : ↑s) => ↑v` or `LinearIndependent (ι := ↑s) f`, depending on whether the family is a lambda expression or not. -/ @[app_delab LinearIndependent] def delabLinearIndependent : Delab := whenPPOption getPPNotation <| whenNotPPOption getPPAnalysisSkip <| withOptionAtCurrPos `pp.analysis.skip true do let e ← getExpr guard <| e.isAppOfArity ``LinearIndependent 7 let some _ := (e.getArg! 0).coeTypeSet? | failure let optionsPerPos ← if (e.getArg! 3).isLambda then withNaryArg 3 do return (← read).optionsPerPos.setBool (← getPos) pp.funBinderTypes.name true else withNaryArg 0 do return (← read).optionsPerPos.setBool (← getPos) `pp.analysis.namedArg true withTheReader Context ({· with optionsPerPos}) delab /-- `LinearIndepOn R v s` states that the vectors in the family `v` that are indexed by the elements of `s` are linearly independent over `R`. -/ def LinearIndepOn (s : Set ι) : Prop := LinearIndependent R (fun x : s ↦ v x) variable {R v} theorem LinearIndepOn.linearIndependent {s : Set ι} (h : LinearIndepOn R v s) : LinearIndependent R (fun x : s ↦ v x) := h theorem linearIndependent_iff_injective_finsuppLinearCombination : LinearIndependent R v ↔ Injective (Finsupp.linearCombination R v) := Iff.rfl alias ⟨LinearIndependent.finsuppLinearCombination_injective, _⟩ := linearIndependent_iff_injective_finsuppLinearCombination theorem linearIndependent_iff_injective_fintypeLinearCombination [Fintype ι] : LinearIndependent R v ↔ Injective (Fintype.linearCombination R v) := by simp [← Finsupp.linearCombination_eq_fintype_linearCombination, LinearIndependent] alias ⟨LinearIndependent.fintypeLinearCombination_injective, _⟩ := linearIndependent_iff_injective_fintypeLinearCombination theorem LinearIndependent.injective [Nontrivial R] (hv : LinearIndependent R v) : Injective v := by simpa [comp_def] using Injective.comp hv (Finsupp.single_left_injective one_ne_zero) theorem LinearIndepOn.injOn [Nontrivial R] (hv : LinearIndepOn R v s) : InjOn v s := injOn_iff_injective.2 <| LinearIndependent.injective hv theorem LinearIndependent.smul_left_injective (hv : LinearIndependent R v) (i : ι) : Injective fun r : R ↦ r • v i := by convert hv.comp (Finsupp.single_injective i); simp theorem LinearIndependent.ne_zero [Nontrivial R] (i : ι) (hv : LinearIndependent R v) : v i ≠ 0 := by intro h have := @hv (Finsupp.single i 1 : ι →₀ R) 0 (by simpa using h) simp at this theorem LinearIndepOn.ne_zero [Nontrivial R] {i : ι} (hv : LinearIndepOn R v s) (hi : i ∈ s) : v i ≠ 0 := LinearIndependent.ne_zero ⟨i, hi⟩ hv theorem LinearIndepOn.zero_notMem_image [Nontrivial R] (hs : LinearIndepOn R v s) : 0 ∉ v '' s := fun ⟨_, hi, h0⟩ ↦ hs.ne_zero hi h0 @[deprecated (since := "2025-05-23")] alias LinearIndepOn.zero_not_mem_image := LinearIndepOn.zero_notMem_image theorem linearIndependent_empty_type [IsEmpty ι] : LinearIndependent R v := injective_of_subsingleton _ @[simp] theorem linearIndependent_zero_iff [Nontrivial R] : LinearIndependent R (0 : ι → M) ↔ IsEmpty ι := ⟨fun h ↦ not_nonempty_iff.1 fun ⟨i⟩ ↦ (h.ne_zero i rfl).elim, fun _ ↦ linearIndependent_empty_type⟩ @[simp] theorem linearIndepOn_zero_iff [Nontrivial R] : LinearIndepOn R (0 : ι → M) s ↔ s = ∅ := linearIndependent_zero_iff.trans isEmpty_coe_sort @[simp] theorem linearIndependent_subsingleton_iff [Nontrivial R] [Subsingleton M] (f : ι → M) : LinearIndependent R f ↔ IsEmpty ι := by rw [Subsingleton.elim f 0, linearIndependent_zero_iff] variable (R M) in theorem linearIndependent_empty : LinearIndependent R (fun x => x : (∅ : Set M) → M) := linearIndependent_empty_type variable (R v) in @[simp] theorem linearIndepOn_empty : LinearIndepOn R v ∅ := linearIndependent_empty_type .. theorem linearIndependent_set_coe_iff : LinearIndependent R (fun x : s ↦ v x) ↔ LinearIndepOn R v s := Iff.rfl theorem linearIndependent_subtype_iff {s : Set M} : LinearIndependent R (Subtype.val : s → M) ↔ LinearIndepOn R id s := Iff.rfl theorem linearIndependent_comp_subtype_iff : LinearIndependent R (v ∘ Subtype.val : s → M) ↔ LinearIndepOn R v s := Iff.rfl /-- A subfamily of a linearly independent family (i.e., a composition with an injective map) is a linearly independent family. -/ theorem LinearIndependent.comp (h : LinearIndependent R v) (f : ι' → ι) (hf : Injective f) : LinearIndependent R (v ∘ f) := by simpa [comp_def] using Injective.comp h (Finsupp.mapDomain_injective hf) lemma LinearIndepOn.mono {t s : Set ι} (hs : LinearIndepOn R v s) (h : t ⊆ s) : LinearIndepOn R v t := hs.comp _ <| Set.inclusion_injective h -- This version makes `l₁` and `l₂` explicit. theorem linearIndependent_iffₛ : LinearIndependent R v ↔ ∀ l₁ l₂, Finsupp.linearCombination R v l₁ = Finsupp.linearCombination R v l₂ → l₁ = l₂ := Iff.rfl open Finset in theorem linearIndependent_iff'ₛ : LinearIndependent R v ↔ ∀ s : Finset ι, ∀ f g : ι → R, ∑ i ∈ s, f i • v i = ∑ i ∈ s, g i • v i → ∀ i ∈ s, f i = g i := linearIndependent_iffₛ.trans ⟨fun hv s f g eq i his ↦ by have h := hv (∑ i ∈ s, Finsupp.single i (f i)) (∑ i ∈ s, Finsupp.single i (g i)) <| by simpa only [map_sum, Finsupp.linearCombination_single] using eq have (f : ι → R) : f i = (∑ j ∈ s, Finsupp.single j (f j)) i := calc f i = (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single i (f i)) := by { rw [Finsupp.lapply_apply, Finsupp.single_eq_same] } _ = ∑ j ∈ s, (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single j (f j)) := Eq.symm <| Finset.sum_eq_single i (fun j _hjs hji => by rw [Finsupp.lapply_apply, Finsupp.single_eq_of_ne' hji]) fun hnis => hnis.elim his _ = (∑ j ∈ s, Finsupp.single j (f j)) i := (map_sum ..).symm rw [this f, this g, h], fun hv f g hl ↦ Finsupp.ext fun _ ↦ by classical refine _root_.by_contradiction fun hni ↦ hni <| hv (f.support ∪ g.support) f g ?_ _ ?_ · rwa [← sum_subset subset_union_left, ← sum_subset subset_union_right] <;> rintro i - hi <;> rw [Finsupp.notMem_support_iff.mp hi, zero_smul] · contrapose! hni simp_rw [notMem_union, Finsupp.notMem_support_iff] at hni rw [hni.1, hni.2]⟩ theorem linearIndependent_iff''ₛ : LinearIndependent R v ↔ ∀ (s : Finset ι) (f g : ι → R), (∀ i ∉ s, f i = g i) → ∑ i ∈ s, f i • v i = ∑ i ∈ s, g i • v i → ∀ i, f i = g i := by classical exact linearIndependent_iff'ₛ.trans ⟨fun H s f g eq hv i ↦ if his : i ∈ s then H s f g hv i his else eq i his, fun H s f g eq i hi ↦ by convert H s (fun j ↦ if j ∈ s then f j else 0) (fun j ↦ if j ∈ s then g j else 0) (fun j hj ↦ (if_neg hj).trans (if_neg hj).symm) (by simp_rw [ite_smul, zero_smul, Finset.sum_extend_by_zero, eq]) i <;> exact (if_pos hi).symm⟩ theorem not_linearIndependent_iffₛ : ¬LinearIndependent R v ↔ ∃ s : Finset ι, ∃ f g : ι → R, ∑ i ∈ s, f i • v i = ∑ i ∈ s, g i • v i ∧ ∃ i ∈ s, f i ≠ g i := by rw [linearIndependent_iff'ₛ] simp only [exists_prop, not_forall] theorem Fintype.linearIndependent_iffₛ [Fintype ι] : LinearIndependent R v ↔ ∀ f g : ι → R, ∑ i, f i • v i = ∑ i, g i • v i → ∀ i, f i = g i := by simp_rw [linearIndependent_iff_injective_fintypeLinearCombination, Injective, Fintype.linearCombination_apply, funext_iff] theorem Fintype.not_linearIndependent_iffₛ [Fintype ι] : ¬LinearIndependent R v ↔ ∃ f g : ι → R, ∑ i, f i • v i = ∑ i, g i • v i ∧ ∃ i, f i ≠ g i := by simpa using not_iff_not.2 Fintype.linearIndependent_iffₛ lemma linearIndepOn_finset_iffₛ {s : Finset ι} : LinearIndepOn R v s ↔ ∀ f g : ι → R, ∑ i ∈ s, f i • v i = ∑ i ∈ s, g i • v i → ∀ i ∈ s, f i = g i := by classical simp_rw [LinearIndepOn, Fintype.linearIndependent_iffₛ] constructor · rintro hv f g hfg i hi simp_rw [← s.sum_attach] at hfg exact hv (f ∘ Subtype.val) (g ∘ Subtype.val) hfg ⟨i, hi⟩ · rintro hv f g hfg i simpa using hv (fun j ↦ if hj : j ∈ s then f ⟨j, hj⟩ else 0) (fun j ↦ if hj : j ∈ s then g ⟨j, hj⟩ else 0) (by simpa +contextual [← s.sum_attach]) i lemma not_linearIndepOn_finset_iffₛ {s : Finset ι} : ¬LinearIndepOn R v s ↔ ∃ f g : ι → R, ∑ i ∈ s, f i • v i = ∑ i ∈ s, g i • v i ∧ ∃ i ∈ s, f i ≠ g i := by simpa using linearIndepOn_finset_iffₛ.not /-- A family is linearly independent if and only if all of its finite subfamily is linearly independent. -/ theorem linearIndependent_iff_finset_linearIndependent : LinearIndependent R v ↔ ∀ (s : Finset ι), LinearIndependent R (v ∘ (Subtype.val : s → ι)) := ⟨fun H _ ↦ H.comp _ Subtype.val_injective, fun H ↦ linearIndependent_iff'ₛ.2 fun s f g eq i hi ↦ Fintype.linearIndependent_iffₛ.1 (H s) (f ∘ Subtype.val) (g ∘ Subtype.val) (by simpa only [← s.sum_coe_sort] using eq) ⟨i, hi⟩⟩ lemma linearIndepOn_iff_linearIndepOn_finset : LinearIndepOn R v s ↔ ∀ t : Finset ι, ↑t ⊆ s → LinearIndepOn R v t where mp hv t hts := hv.mono hts mpr hv := by rw [LinearIndepOn, linearIndependent_iff_finset_linearIndependent] exact fun t ↦ (hv (t.map <| .subtype _) (by simp)).comp (ι' := t) (fun x ↦ ⟨x, Finset.mem_map_of_mem (.subtype _) x.2⟩) fun x ↦ by aesop /-- If the image of a family of vectors under a linear map is linearly independent, then so is the original family. -/ theorem LinearIndependent.of_comp (f : M →ₗ[R] M') (hfv : LinearIndependent R (f ∘ v)) : LinearIndependent R v := by rw [LinearIndependent, Finsupp.linearCombination_linear_comp, LinearMap.coe_comp] at hfv exact hfv.of_comp theorem LinearIndepOn.of_comp (f : M →ₗ[R] M') (hfv : LinearIndepOn R (f ∘ v) s) : LinearIndepOn R v s := LinearIndependent.of_comp f hfv /-- If `f` is a linear map injective on the span of the range of `v`, then the family `f ∘ v` is linearly independent if and only if the family `v` is linearly independent. See `LinearMap.linearIndependent_iff_of_disjoint` for the version with `Set.InjOn` replaced by `Disjoint` when working over a ring. -/ protected theorem LinearMap.linearIndependent_iff_of_injOn (f : M →ₗ[R] M') (hf_inj : Set.InjOn f (span R (Set.range v))) : LinearIndependent R (f ∘ v) ↔ LinearIndependent R v := by simp_rw [LinearIndependent, Finsupp.linearCombination_linear_comp, coe_comp] rw [hf_inj.injective_iff] rw [← Finsupp.range_linearCombination, LinearMap.coe_range] protected theorem LinearMap.linearIndepOn_iff_of_injOn (f : M →ₗ[R] M') (hf_inj : Set.InjOn f (span R (v '' s))) : LinearIndepOn R (f ∘ v) s ↔ LinearIndepOn R v s := f.linearIndependent_iff_of_injOn (by rwa [← image_eq_range]) (v := fun i : s ↦ v i) -- TODO : Rename this `LinearIndependent.of_subsingleton`. @[nontriviality] theorem linearIndependent_of_subsingleton [Subsingleton R] : LinearIndependent R v := linearIndependent_iffₛ.2 fun _l _l' _hl => Subsingleton.elim _ _ @[nontriviality] theorem LinearIndepOn.of_subsingleton [Subsingleton R] : LinearIndepOn R v s := linearIndependent_of_subsingleton theorem linearIndependent_equiv (e : ι ≃ ι') {f : ι' → M} : LinearIndependent R (f ∘ e) ↔ LinearIndependent R f := ⟨fun h ↦ comp_id f ▸ e.self_comp_symm ▸ h.comp _ e.symm.injective, fun h ↦ h.comp _ e.injective⟩ theorem linearIndependent_equiv' (e : ι ≃ ι') {f : ι' → M} {g : ι → M} (h : f ∘ e = g) : LinearIndependent R g ↔ LinearIndependent R f := h ▸ linearIndependent_equiv e theorem linearIndepOn_equiv (e : ι ≃ ι') {f : ι' → M} {s : Set ι} : LinearIndepOn R (f ∘ e) s ↔ LinearIndepOn R f (e '' s) := linearIndependent_equiv' (e.image s) <| by simp [funext_iff] @[simp] theorem linearIndepOn_univ : LinearIndepOn R v univ ↔ LinearIndependent R v := linearIndependent_equiv' (Equiv.Set.univ ι) rfl alias ⟨_, LinearIndependent.linearIndepOn⟩ := linearIndepOn_univ theorem linearIndepOn_iff_image {ι} {s : Set ι} {f : ι → M} (hf : Set.InjOn f s) : LinearIndepOn R f s ↔ LinearIndepOn R id (f '' s) := linearIndependent_equiv' (Equiv.Set.imageOfInjOn _ _ hf) rfl theorem linearIndepOn_range_iff {ι} {f : ι → ι'} (hf : Injective f) (g : ι' → M) : LinearIndepOn R g (range f) ↔ LinearIndependent R (g ∘ f) := Iff.symm <| linearIndependent_equiv' (Equiv.ofInjective f hf) rfl alias ⟨LinearIndependent.of_linearIndepOn_range, _⟩ := linearIndepOn_range_iff theorem linearIndepOn_id_range_iff {ι} {f : ι → M} (hf : Injective f) : LinearIndepOn R id (range f) ↔ LinearIndependent R f := linearIndepOn_range_iff hf id alias ⟨LinearIndependent.of_linearIndepOn_id_range, _⟩ := linearIndepOn_id_range_iff theorem LinearIndependent.linearIndepOn_id (i : LinearIndependent R v) : LinearIndepOn R id (range v) := by simpa using i.comp _ (rangeSplitting_injective v) /-- A version of `LinearIndependent.linearIndepOn_id` with the set range equality as a hypothesis. -/ theorem LinearIndependent.linearIndepOn_id' (hv : LinearIndependent R v) {t : Set M} (ht : Set.range v = t) : LinearIndepOn R id t := ht ▸ hv.linearIndepOn_id section Indexed theorem linearIndepOn_iffₛ : LinearIndepOn R v s ↔ ∀ f ∈ Finsupp.supported R R s, ∀ g ∈ Finsupp.supported R R s, Finsupp.linearCombination R v f = Finsupp.linearCombination R v g → f = g := by simp only [LinearIndepOn, linearIndependent_iffₛ, Finsupp.mem_supported, Finsupp.linearCombination_apply, Set.subset_def, Finset.mem_coe] refine ⟨fun h l₁ h₁ l₂ h₂ eq ↦ (Finsupp.subtypeDomain_eq_iff h₁ h₂).1 <| h _ _ <| (Finsupp.sum_subtypeDomain_index h₁).trans eq ▸ (Finsupp.sum_subtypeDomain_index h₂).symm, fun h l₁ l₂ eq ↦ ?_⟩ refine Finsupp.embDomain_injective (Embedding.subtype s) <| h _ ?_ _ ?_ ?_ iterate 2 simpa using fun _ h _ ↦ h simp_rw [Finsupp.embDomain_eq_mapDomain] rwa [Finsupp.sum_mapDomain_index, Finsupp.sum_mapDomain_index] <;> intros <;> simp only [zero_smul, add_smul] /-- An indexed set of vectors is linearly dependent iff there are two distinct `Finsupp.LinearCombination`s of the vectors with the same value. -/ theorem linearDepOn_iff'ₛ : ¬LinearIndepOn R v s ↔ ∃ f g : ι →₀ R, f ∈ Finsupp.supported R R s ∧ g ∈ Finsupp.supported R R s ∧ Finsupp.linearCombination R v f = Finsupp.linearCombination R v g ∧ f ≠ g := by simp [linearIndepOn_iffₛ] /-- A version of `linearDepOn_iff'ₛ` with `Finsupp.linearCombination` unfolded. -/ theorem linearDepOn_iffₛ : ¬LinearIndepOn R v s ↔ ∃ f g : ι →₀ R, f ∈ Finsupp.supported R R s ∧ g ∈ Finsupp.supported R R s ∧ ∑ i ∈ f.support, f i • v i = ∑ i ∈ g.support, g i • v i ∧ f ≠ g := linearDepOn_iff'ₛ theorem linearIndependent_restrict_iff : LinearIndependent R (s.restrict v) ↔ LinearIndepOn R v s := Iff.rfl theorem LinearIndepOn.linearIndependent_restrict (hs : LinearIndepOn R v s) : LinearIndependent R (s.restrict v) := hs theorem linearIndepOn_iff_linearCombinationOnₛ : LinearIndepOn R v s ↔ Injective (Finsupp.linearCombinationOn ι M R v s) := by rw [← linearIndependent_restrict_iff] simp [LinearIndependent, Finsupp.linearCombination_restrict] end Indexed section repr /-- Canonical isomorphism between linear combinations and the span of linearly independent vectors. -/ @[simps (rhsMd := default) apply_coe symm_apply] def LinearIndependent.linearCombinationEquiv (hv : LinearIndependent R v) : (ι →₀ R) ≃ₗ[R] span R (range v) := by refine LinearEquiv.ofBijective (LinearMap.codRestrict (span R (range v)) (Finsupp.linearCombination R v) ?_) ⟨hv.codRestrict _, ?_⟩ · simp_rw [← Finsupp.range_linearCombination]; exact fun c ↦ ⟨c, rfl⟩ rw [← LinearMap.range_eq_top, LinearMap.range_eq_map, LinearMap.map_codRestrict, ← LinearMap.range_le_iff_comap, range_subtype, Submodule.map_top, Finsupp.range_linearCombination] /-- Linear combination representing a vector in the span of linearly independent vectors. Given a family of linearly independent vectors, we can represent any vector in their span as a linear combination of these vectors. These are provided by this linear map. It is simply one direction of `LinearIndependent.linearCombinationEquiv`. -/ def LinearIndependent.repr (hv : LinearIndependent R v) : span R (range v) →ₗ[R] ι →₀ R := hv.linearCombinationEquiv.symm variable (hv : LinearIndependent R v) {i : ι} @[simp] theorem LinearIndependent.linearCombination_repr (x) : Finsupp.linearCombination R v (hv.repr x) = x := Subtype.ext_iff.1 (LinearEquiv.apply_symm_apply hv.linearCombinationEquiv x) theorem LinearIndependent.linearCombination_comp_repr : (Finsupp.linearCombination R v).comp hv.repr = Submodule.subtype _ := LinearMap.ext <| hv.linearCombination_repr theorem LinearIndependent.repr_ker : LinearMap.ker hv.repr = ⊥ := by rw [LinearIndependent.repr, LinearEquiv.ker] theorem LinearIndependent.repr_range : LinearMap.range hv.repr = ⊤ := by rw [LinearIndependent.repr, LinearEquiv.range] theorem LinearIndependent.repr_eq {l : ι →₀ R} {x : span R (range v)} (eq : Finsupp.linearCombination R v l = ↑x) : hv.repr x = l := by have : ↑((LinearIndependent.linearCombinationEquiv hv : (ι →₀ R) →ₗ[R] span R (range v)) l) = Finsupp.linearCombination R v l := rfl have : (LinearIndependent.linearCombinationEquiv hv : (ι →₀ R) →ₗ[R] span R (range v)) l = x := by rw [eq] at this exact Subtype.ext_iff.2 this rw [← LinearEquiv.symm_apply_apply hv.linearCombinationEquiv l] rw [← this] rfl theorem LinearIndependent.repr_eq_single (i) (x : span R (range v)) (hx : ↑x = v i) : hv.repr x = Finsupp.single i 1 := by apply hv.repr_eq simp [Finsupp.linearCombination_single, hx] theorem LinearIndependent.span_repr_eq [Nontrivial R] (x) : Span.repr R (Set.range v) x = (hv.repr x).equivMapDomain (Equiv.ofInjective _ hv.injective) := by have p : (Span.repr R (Set.range v) x).equivMapDomain (Equiv.ofInjective _ hv.injective).symm = hv.repr x := by apply (LinearIndependent.linearCombinationEquiv hv).injective ext simp only [LinearIndependent.linearCombinationEquiv_apply_coe, Equiv.self_comp_ofInjective_symm, LinearIndependent.linearCombination_repr, Finsupp.linearCombination_equivMapDomain, Span.finsupp_linearCombination_repr] ext ⟨_, ⟨i, rfl⟩⟩ simp [← p] theorem LinearIndependent.eq_zero_of_smul_mem_span (hv : LinearIndependent R v) (i : ι) (a : R) (ha : a • v i ∈ span R (v '' (univ \ {i}))) : a = 0 := by rw [Finsupp.span_image_eq_map_linearCombination, mem_map] at ha rcases ha with ⟨l, hl, e⟩ rw [linearIndependent_iffₛ.1 hv l (Finsupp.single i a) (by simp [e])] at hl by_contra hn exact (notMem_of_mem_diff (hl <| by simp [hn])) (mem_singleton _) @[deprecated (since := "2025-05-13")] alias LinearIndependent.not_smul_mem_span := LinearIndependent.eq_zero_of_smul_mem_span nonrec lemma LinearIndepOn.eq_zero_of_smul_mem_span (hv : LinearIndepOn R v s) (hi : i ∈ s) (a : R) (ha : a • v i ∈ span R (v '' (s \ {i}))) : a = 0 := hv.eq_zero_of_smul_mem_span ⟨i, hi⟩ _ <| by simpa [← comp_def, image_comp, image_diff Subtype.val_injective] variable [Nontrivial R] lemma LinearIndependent.notMem_span (hv : LinearIndependent R v) (i : ι) : v i ∉ span R (v '' {i}ᶜ) := fun hi ↦ one_ne_zero <| hv.eq_zero_of_smul_mem_span i 1 <| by simpa [Set.compl_eq_univ_diff] using hi @[deprecated (since := "2025-05-23")] alias LinearIndependent.not_mem_span := LinearIndependent.notMem_span lemma LinearIndepOn.notMem_span (hv : LinearIndepOn R v s) (hi : i ∈ s) : v i ∉ span R (v '' (s \ {i})) := fun hi' ↦ one_ne_zero <| hv.eq_zero_of_smul_mem_span hi 1 <| by simpa [Set.compl_eq_univ_diff] using hi' @[deprecated (since := "2025-05-23")] alias LinearIndepOn.not_mem_span := LinearIndepOn.notMem_span lemma LinearIndepOn.notMem_span_of_insert (hv : LinearIndepOn R v (insert i s)) (hi : i ∉ s) : v i ∉ span R (v '' s) := by simpa [hi] using hv.notMem_span <| mem_insert .. @[deprecated (since := "2025-05-23")] alias LinearIndepOn.not_mem_span_of_insert := LinearIndepOn.notMem_span_of_insert end repr section Maximal universe v w /-- A linearly independent family is maximal if there is no strictly larger linearly independent family. -/ @[nolint unusedArguments] def LinearIndependent.Maximal {ι : Type w} {R : Type u} [Semiring R] {M : Type v} [AddCommMonoid M] [Module R M] {v : ι → M} (_i : LinearIndependent R v) : Prop := ∀ (s : Set M) (_i' : LinearIndependent R ((↑) : s → M)) (_h : range v ≤ s), range v = s /-- An alternative characterization of a maximal linearly independent family, quantifying over types (in the same universe as `M`) into which the indexing family injects. -/ theorem LinearIndependent.maximal_iff {ι : Type w} {R : Type u} [Semiring R] [Nontrivial R] {M : Type v} [AddCommMonoid M] [Module R M] {v : ι → M} (i : LinearIndependent R v) : i.Maximal ↔ ∀ (κ : Type v) (w : κ → M) (_i' : LinearIndependent R w) (j : ι → κ) (_h : w ∘ j = v), Surjective j := by constructor · rintro p κ w i' j rfl specialize p (range w) i'.linearIndepOn_id (range_comp_subset_range _ _) rw [range_comp, ← image_univ (f := w)] at p exact range_eq_univ.mp (image_injective.mpr i'.injective p) · intro p w i' h specialize p w ((↑) : w → M) i' (fun i => ⟨v i, range_subset_iff.mp h i⟩) (by ext simp) have q := congr_arg (fun s => ((↑) : w → M) '' s) p.range_eq dsimp at q rw [← image_univ, image_image] at q simpa using q end Maximal /-! ### Properties which require `LinearOrder R` and `CanonicallyOrderedAdd R` If the semiring `R` is linearly and canonically ordered (e.g. `R = ℕ`), `LinearIndependent` can be proved from linear combination over two disjoint sets. -/ section LinearlyCanonicallyOrdered variable [LinearOrder R] [CanonicallyOrderedAdd R] [AddRightReflectLE R] [IsCancelAdd M] theorem linearIndependent_iffₒₛ : LinearIndependent R v ↔ ∀ (s t : Finset ι) (f : ι → R), Disjoint s t → ∑ i ∈ s, f i • v i = ∑ i ∈ t, f i • v i → (∀ i ∈ s, f i = 0) ∧ ∀ i ∈ t, f i = 0 := by classical letI : Sub R := CanonicallyOrderedAdd.toSub haveI : OrderedSub R := CanonicallyOrderedAdd.toOrderedSub rw [linearIndependent_iff'ₛ] refine ⟨fun h s t f hst heq => ?_, fun h s f g heq => ?_⟩ · specialize h (s ∪ t) (fun i => if i ∈ s then f i else 0) (fun i => if i ∈ t then f i else 0) ?_ · simpa refine ⟨fun i hi => ?_, fun i hi => ?_⟩ · simpa [hi, hst.notMem_of_mem_left_finset hi] using h i (Finset.mem_union_left _ hi) · simpa [hi, hst.notMem_of_mem_right_finset hi] using (h i (Finset.mem_union_right _ hi)).symm · specialize h { i ∈ s | g i ≤ f i } { i ∈ s | f i < g i } (fun i => if g i ≤ f i then f i - g i else g i - f i) ?_ ?_ · simp_rw [Finset.disjoint_left, Finset.mem_filter] exact fun i ⟨_, hi⟩ ⟨_, hi'⟩ => hi.not_gt hi' · rw [← add_right_cancel_iff (a := ∑ i ∈ s with g i ≤ f i, g i • v i + ∑ i ∈ s with f i < g i, f i • v i)] conv_lhs => rw [← add_assoc, ← Finset.sum_add_distrib] conv_rhs => rw [add_left_comm, ← Finset.sum_add_distrib] convert heq <;> simp_rw [← Finset.sum_filter_add_sum_filter_not s (fun i => g i ≤ f i), not_le] <;> congr! 2 with i hi <;> simp only [Finset.mem_filter] at hi · simp [hi.2, ← add_smul, tsub_add_cancel_of_le hi.2] · simp [hi.2.not_ge, ← add_smul, tsub_add_cancel_of_le hi.2.le] simp only [Finset.mem_filter] at h intro i hi by_cases hi' : g i ≤ f i · apply hi'.antisymm' simpa [hi', tsub_eq_zero_iff_le] using h.1 i ⟨hi, hi'⟩ · apply (not_le.1 hi').le.antisymm simpa [hi', tsub_eq_zero_iff_le] using h.2 i ⟨hi, not_le.1 hi'⟩ theorem not_linearIndependent_iffₒₛ : ¬ LinearIndependent R v ↔ ∃ (s t : Finset ι) (f : ι → R), Disjoint s t ∧ ∑ i ∈ s, f i • v i = ∑ i ∈ t, f i • v i ∧ ∃ i ∈ s, 0 < f i := by simp only [linearIndependent_iffₒₛ, pos_iff_ne_zero] set_option push_neg.use_distrib true in push_neg refine ⟨fun ⟨s, t, f, hst, heq, h⟩ => ?_, fun ⟨s, t, f, hst, heq, hi⟩ => ⟨s, t, f, hst, heq, .inl hi⟩⟩ rcases h with ⟨i, hi, hfi⟩ | ⟨i, hi, hgi⟩ · exact ⟨s, t, f, hst, heq, i, hi, hfi⟩ · exact ⟨t, s, f, hst.symm, heq.symm, i, hi, hgi⟩ nonrec theorem Fintype.linearIndependent_iffₒₛ [DecidableEq ι] [Fintype ι] : LinearIndependent R v ↔ ∀ t, ∀ (f : ι → R), ∑ i ∈ t, f i • v i = ∑ i ∉ t, f i • v i → ∀ i, f i = 0 := by rw [linearIndependent_iffₒₛ] refine ⟨fun h t f heq i => ?_, fun h t₁ t₂ f ht₁t₂ heq => ?_⟩ · specialize h t tᶜ f disjoint_compl_right heq by_cases hi : i ∈ t · exact h.1 i hi · exact h.2 i (Finset.mem_compl.2 hi) · specialize h t₁ (fun i => if i ∈ t₁ ∨ i ∈ t₂ then f i else 0) ?_ · rw [← Finset.sum_subset ht₁t₂.le_compl_left] · convert heq using 2 with i hi i hi <;> simp [hi] · intro i hi hi' simp [Finset.mem_compl.1 hi, hi'] refine ⟨fun i hi => ?_, fun i hi => ?_⟩ <;> simpa [hi] using h i theorem Fintype.not_linearIndependent_iffₒₛ [DecidableEq ι] [Fintype ι] : ¬ LinearIndependent R v ↔ ∃ t, ∃ (f : ι → R), ∑ i ∈ t, f i • v i = ∑ i ∉ t, f i • v i ∧ ∃ i ∈ t, 0 < f i := by simp only [linearIndependent_iffₒₛ, not_forall, pos_iff_ne_zero] refine ⟨fun ⟨t, f, heq, i, hfi⟩ => ?_, fun ⟨t, f, heq, i, hi, hfi⟩ => ⟨t, f, heq, i, hfi⟩⟩ by_cases hi' : i ∈ t · exact ⟨t, f, heq, i, hi', hfi⟩ · refine ⟨tᶜ, f, ?_, i, Finset.mem_compl.2 hi', hfi⟩ simp [heq] lemma linearIndepOn_finset_iffₒₛ [DecidableEq ι] {s : Finset ι} : LinearIndepOn R v s ↔ ∀ t ⊆ s, ∀ (f : ι → R), ∑ i ∈ t, f i • v i = ∑ i ∈ s \ t, f i • v i → ∀ i ∈ s, f i = 0 := by rw [LinearIndepOn, Fintype.linearIndependent_iffₒₛ] refine ⟨fun h t ht f heq i hi => h { i | i.1 ∈ t } (f ∘ Subtype.val) ?_ ⟨i, hi⟩, fun h t f heq i => ?_⟩ · simp only [Finset.compl_filter, Finset.sum_filter, Function.comp_apply, Finset.coe_sort_coe] rw [Finset.sum_coe_sort s fun i => if i ∈ t then f i • v i else 0, Finset.sum_coe_sort s fun i => if i ∉ t then f i • v i else 0] simpa [Finset.inter_eq_right.2 ht, Finset.sum_ite, Finset.filter_notMem_eq_sdiff] · specialize h (t.map (Embedding.subtype _)) (Finset.map_subtype_subset _) (fun i => if h : i ∈ s then f ⟨i, h⟩ else 0) ?_ i i.2 · conv => enter [2, 1, 1] rw [← s.subtype_map_of_mem (fun x hx => hx), Finset.subtype_eq_univ.2 (fun x hx => hx)] change Finset.map (Embedding.subtype (· ∈ (s : Set ι))) _ rw [← Finset.map_sdiff] simpa [Embedding.subtype, ← Finset.compl_eq_univ_sdiff] simpa using h lemma not_linearIndepOn_finset_iffₒₛ [DecidableEq ι] {s : Finset ι} : ¬LinearIndepOn R v s ↔ ∃ t ⊆ s, ∃ (f : ι → R), ∑ i ∈ t, f i • v i = ∑ i ∈ s \ t, f i • v i ∧ ∃ i ∈ t, 0 < f i := by simp only [linearIndepOn_finset_iffₒₛ, not_forall, pos_iff_ne_zero] refine ⟨fun ⟨t, hst, f, heq, i, hi, hfi⟩ => ?_, fun ⟨t, hst, f, heq, i, hi, hfi⟩ => ⟨t, hst, f, heq, i, hst hi, hfi⟩⟩ by_cases hi' : i ∈ t · exact ⟨t, hst, f, heq, i, hi', hfi⟩ · refine ⟨s \ t, Finset.sdiff_subset, f, ?_, i, Finset.mem_sdiff.2 ⟨hi, hi'⟩, hfi⟩ simpa [Finset.sdiff_sdiff_eq_self hst] using heq.symm end LinearlyCanonicallyOrdered end Semiring /-! ### Properties which require `Ring R` -/ section Module variable [Ring R] [AddCommGroup M] [AddCommGroup M'] variable [Module R M] [Module R M'] variable {v : ι → M} {i : ι} theorem linearIndependent_iff_ker : LinearIndependent R v ↔ LinearMap.ker (Finsupp.linearCombination R v) = ⊥ := LinearMap.ker_eq_bot.symm theorem linearIndependent_iff : LinearIndependent R v ↔ ∀ l, Finsupp.linearCombination R v l = 0 → l = 0 := by simp [linearIndependent_iff_ker, LinearMap.ker_eq_bot'] /-- A version of `linearIndependent_iff` where the linear combination is a `Finset` sum. -/ theorem linearIndependent_iff' : LinearIndependent R v ↔ ∀ s : Finset ι, ∀ g : ι → R, ∑ i ∈ s, g i • v i = 0 → ∀ i ∈ s, g i = 0 := by rw [linearIndependent_iff'ₛ] refine ⟨fun h s f ↦ ?_, fun h s f g ↦ ?_⟩ · convert h s f 0; simp_rw [Pi.zero_apply, zero_smul, Finset.sum_const_zero] · rw [← sub_eq_zero, ← Finset.sum_sub_distrib] convert h s (f - g) using 3 <;> simp only [Pi.sub_apply, sub_smul, sub_eq_zero] /-- A version of `linearIndependent_iff` where the linear combination is a `Finset` sum of a function with support contained in the `Finset`. -/ theorem linearIndependent_iff'' : LinearIndependent R v ↔ ∀ (s : Finset ι) (g : ι → R), (∀ i ∉ s, g i = 0) → ∑ i ∈ s, g i • v i = 0 → ∀ i, g i = 0 := by classical exact linearIndependent_iff'.trans ⟨fun H s g hg hv i => if his : i ∈ s then H s g hv i his else hg i his, fun H s g hg i hi => by convert H s (fun j => if j ∈ s then g j else 0) (fun j hj => if_neg hj) (by simp_rw [ite_smul, zero_smul, Finset.sum_extend_by_zero, hg]) i exact (if_pos hi).symm⟩ theorem linearIndependent_add_smul_iff {c : ι → R} {i : ι} (h₀ : c i = 0) : LinearIndependent R (v + (c · • v i)) ↔ LinearIndependent R v := by simp [linearIndependent_iff_injective_finsuppLinearCombination, ← Finsupp.linearCombination_comp_addSingleEquiv i c h₀] theorem not_linearIndependent_iff : ¬LinearIndependent R v ↔ ∃ s : Finset ι, ∃ g : ι → R, ∑ i ∈ s, g i • v i = 0 ∧ ∃ i ∈ s, g i ≠ 0 := by rw [linearIndependent_iff'] simp only [exists_prop, not_forall] theorem Fintype.linearIndependent_iff [Fintype ι] : LinearIndependent R v ↔ ∀ g : ι → R, ∑ i, g i • v i = 0 → ∀ i, g i = 0 := by refine ⟨fun H g => by simpa using linearIndependent_iff'.1 H Finset.univ g, fun H => linearIndependent_iff''.2 fun s g hg hs i => H _ ?_ _⟩ rw [← hs] refine (Finset.sum_subset (Finset.subset_univ _) fun i _ hi => ?_).symm rw [hg i hi, zero_smul] theorem Fintype.not_linearIndependent_iff [Fintype ι] : ¬LinearIndependent R v ↔ ∃ g : ι → R, ∑ i, g i • v i = 0 ∧ ∃ i, g i ≠ 0 := by simpa using not_iff_not.2 Fintype.linearIndependent_iff lemma linearIndepOn_finset_iff {s : Finset ι} : LinearIndepOn R v s ↔ ∀ f : ι → R, ∑ i ∈ s, f i • v i = 0 → ∀ i ∈ s, f i = 0 := by classical simp_rw [LinearIndepOn, Fintype.linearIndependent_iff] constructor · rintro hv f hf i hi rw [← s.sum_attach] at hf exact hv (f ∘ Subtype.val) hf ⟨i, hi⟩ · rintro hv f hf₀ i simpa using hv (fun j ↦ if hj : j ∈ s then f ⟨j, hj⟩ else 0) (by simpa +contextual [← s.sum_attach]) i lemma not_linearIndepOn_finset_iff {s : Finset ι} : ¬LinearIndepOn R v s ↔ ∃ f : ι → R, ∑ i ∈ s, f i • v i = 0 ∧ ∃ i ∈ s, f i ≠ 0 := by simpa using linearIndepOn_finset_iff.not /-- If the kernel of a linear map is disjoint from the span of a family of vectors, then the family is linearly independent iff it is linearly independent after composing with the linear map. -/ protected theorem LinearMap.linearIndependent_iff_of_disjoint (f : M →ₗ[R] M') (hf_inj : Disjoint (span R (Set.range v)) (LinearMap.ker f)) : LinearIndependent R (f ∘ v) ↔ LinearIndependent R v := f.linearIndependent_iff_of_injOn <| LinearMap.injOn_of_disjoint_ker le_rfl hf_inj section LinearIndepOn /-! The following give equivalent versions of `LinearIndepOn` and its negation. -/ theorem linearIndepOn_iff : LinearIndepOn R v s ↔ ∀ l ∈ Finsupp.supported R R s, (Finsupp.linearCombination R v) l = 0 → l = 0 := linearIndepOn_iffₛ.trans ⟨fun h l hl ↦ h l hl 0 (zero_mem _), fun h f hf g hg eq ↦ sub_eq_zero.mp (h (f - g) (sub_mem hf hg) <| by rw [map_sub, eq, sub_self])⟩ /-- An indexed set of vectors is linearly dependent iff there is a nontrivial `Finsupp.linearCombination` of the vectors that is zero. -/ theorem linearDepOn_iff' : ¬LinearIndepOn R v s ↔ ∃ f : ι →₀ R, f ∈ Finsupp.supported R R s ∧ Finsupp.linearCombination R v f = 0 ∧ f ≠ 0 := by simp [linearIndepOn_iff] /-- A version of `linearDepOn_iff'` with `Finsupp.linearCombination` unfolded. -/ theorem linearDepOn_iff : ¬LinearIndepOn R v s ↔ ∃ f : ι →₀ R, f ∈ Finsupp.supported R R s ∧ ∑ i ∈ f.support, f i • v i = 0 ∧ f ≠ 0 := linearDepOn_iff' theorem linearIndepOn_iff_disjoint : LinearIndepOn R v s ↔ Disjoint (Finsupp.supported R R s) (LinearMap.ker <| Finsupp.linearCombination R v) := by rw [linearIndepOn_iff, LinearMap.disjoint_ker] theorem linearIndepOn_iff_linearCombinationOn : LinearIndepOn R v s ↔ (LinearMap.ker <| Finsupp.linearCombinationOn ι M R v s) = ⊥ := linearIndepOn_iff_linearCombinationOnₛ.trans <| LinearMap.ker_eq_bot (M := Finsupp.supported R R s).symm /-- A version of `linearIndepOn_iff` where the linear combination is a `Finset` sum. -/ lemma linearIndepOn_iff' : LinearIndepOn R v s ↔ ∀ (t : Finset ι) (g : ι → R), (t : Set ι) ⊆ s → ∑ i ∈ t, g i • v i = 0 → ∀ i ∈ t, g i = 0 := by classical rw [LinearIndepOn, linearIndependent_iff'] refine ⟨fun h t g hts h0 i hit ↦ ?_, fun h t g h0 i hit ↦ ?_⟩ · refine h (t.preimage _ Subtype.val_injective.injOn) (fun i ↦ g i) ?_ ⟨i, hts hit⟩ (by simpa) rwa [t.sum_preimage ((↑) : s → ι) Subtype.val_injective.injOn (fun i ↦ g i • v i)] simp only [Subtype.range_coe_subtype, setOf_mem_eq] exact fun x hxt hxs ↦ (hxs (hts hxt)) |>.elim replace h : ∀ i (hi : i ∈ s), ⟨i, hi⟩ ∈ t → ∀ (h : i ∈ s), g ⟨i, h⟩ = 0 := by simpa [h0] using h (t.image (↑)) (fun i ↦ if hi : i ∈ s then g ⟨i, hi⟩ else 0) apply h _ _ hit /-- A version of `linearIndepOn_iff` where the linear combination is a `Finset` sum of a function with support contained in the `Finset`. -/ lemma linearIndepOn_iff'' : LinearIndepOn R v s ↔ ∀ (t : Finset ι) (g : ι → R), (t : Set ι) ⊆ s → (∀ i ∉ t, g i = 0) → ∑ i ∈ t, g i • v i = 0 → ∀ i ∈ t, g i = 0 := by classical exact linearIndepOn_iff'.trans ⟨fun h t g hts htg h0 ↦ h _ _ hts h0, fun h t g hts h0 ↦ by simpa +contextual [h0] using h t (fun i ↦ if i ∈ t then g i else 0) hts⟩ end LinearIndepOn open LinearMap theorem linearIndependent_iff_eq_zero_of_smul_mem_span : LinearIndependent R v ↔ ∀ (i : ι) (a : R), a • v i ∈ span R (v '' (univ \ {i})) → a = 0 := ⟨fun hv ↦ hv.eq_zero_of_smul_mem_span, fun H => linearIndependent_iff.2 fun l hl => by ext i; simp only [Finsupp.zero_apply] by_contra hn refine hn (H i _ ?_) refine (Finsupp.mem_span_image_iff_linearCombination R).2 ⟨Finsupp.single i (l i) - l, ?_, ?_⟩ · rw [Finsupp.mem_supported'] intro j hj have hij : j = i := Classical.not_not.1 fun hij : j ≠ i => hj ((mem_diff _).2 ⟨mem_univ _, fun h => hij (eq_of_mem_singleton h)⟩) simp [hij] · simp [hl]⟩ /-- Version of `LinearIndependent.of_subsingleton` that works for the zero ring. -/ lemma LinearIndependent.of_subsingleton' [Subsingleton ι] (i : ι) (hi : ∀ r : R, r • v i = 0 → r = 0) : LinearIndependent R v := by let := uniqueOfSubsingleton i simpa [linearIndependent_iff, Finsupp.linearCombination_unique, Finsupp.ext_iff, Unique.forall_iff] using fun _ ↦ hi _ /-- Version of `LinearIndepOn.singleton` that works for the zero ring. -/ @[simp] lemma LinearIndepOn.singleton' (hi : ∀ r : R, r • v i = 0 → r = 0) : LinearIndepOn R v {i} := LinearIndependent.of_subsingleton' ⟨i, rfl⟩ hi variable [NoZeroSMulDivisors R M] lemma LinearIndependent.of_subsingleton [Subsingleton ι] (i : ι) (hi : v i ≠ 0) : LinearIndependent R v := .of_subsingleton' i (by simp [hi]) lemma LinearIndepOn.singleton (hi : v i ≠ 0) : LinearIndepOn R v {i} := by simp [hi] variable (R) in @[deprecated LinearIndepOn.singleton (since := "2025-11-11")] lemma LinearIndepOn.id_singleton {x : M} (hx : x ≠ 0) : LinearIndepOn R id {x} := .singleton hx end Module /-! ### Properties which require `DivisionRing K` These can be considered generalizations of properties of linear independence in vector spaces. -/ section Module variable [DivisionRing K] [AddCommGroup V] [Module K V] variable {v : ι → V} {s t : Set ι} {x y : V} open Submodule theorem linearIndependent_iff_notMem_span : LinearIndependent K v ↔ ∀ i, v i ∉ span K (v '' (univ \ {i})) := by apply linearIndependent_iff_eq_zero_of_smul_mem_span.trans constructor · intro h i h_in_span apply one_ne_zero (h i 1 (by simp [h_in_span])) · intro h i a ha by_contra ha' exact False.elim (h _ ((smul_mem_iff _ ha').1 ha)) @[deprecated (since := "2025-05-23")] alias linearIndependent_iff_not_mem_span := linearIndependent_iff_notMem_span lemma linearIndepOn_iff_notMem_span : LinearIndepOn K v s ↔ ∀ i ∈ s, v i ∉ span K (v '' (s \ {i})) := by rw [LinearIndepOn, linearIndependent_iff_notMem_span, ← Function.comp_def] simp_rw [Set.image_comp] simp [Set.image_diff Subtype.val_injective] @[deprecated (since := "2025-05-23")] alias linearIndepOn_iff_not_mem_span := linearIndepOn_iff_notMem_span end Module
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeModule/Int.lean
import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.Data.ZMod.QuotientGroup import Mathlib.GroupTheory.Index import Mathlib.LinearAlgebra.FreeModule.PID /-! # Index of submodules of free ℤ-modules (considered as an `AddSubgroup`). This file provides lemmas about when a submodule of a free ℤ-module is a subgroup of finite index. -/ variable {ι R M : Type*} {n : ℕ} [CommRing R] [AddCommGroup M] namespace Module.Basis.SmithNormalForm variable [Fintype ι] /-- Given a submodule `N` in Smith normal form of a free `R`-module, its index as an additive subgroup is an appropriate power of the cardinality of `R` multiplied by the product of the indexes of the ideals generated by each basis vector. -/ lemma toAddSubgroup_index_eq_pow_mul_prod [Module R M] {N : Submodule R M} (snf : Basis.SmithNormalForm N ι n) : N.toAddSubgroup.index = Nat.card R ^ (Fintype.card ι - n) * ∏ i : Fin n, (Ideal.span {snf.a i}).toAddSubgroup.index := by classical rcases snf with ⟨bM, bN, f, a, snf⟩ dsimp only set N' : Submodule R (ι → R) := N.map bM.equivFun with hN' let bN' : Basis (Fin n) R N' := bN.map (bM.equivFun.submoduleMap N) have snf' : ∀ i, (bN' i : ι → R) = Pi.single (f i) (a i) := by intro i simp only [map_apply, bN'] erw [LinearEquiv.submoduleMap_apply] simp only [equivFun_apply, snf, map_smul, repr_self, Finsupp.single_eq_pi_single] ext j simp [Pi.single_apply] have hNN' : N.toAddSubgroup.index = N'.toAddSubgroup.index := by set e : (ι → R) ≃+ M := ↑bM.equivFun.symm with he let e' : (ι → R) →+ M := e have he' : Function.Surjective e' := e.surjective convert (AddSubgroup.index_comap_of_surjective N.toAddSubgroup he').symm using 2 rw [AddSubgroup.comap_equiv_eq_map_symm, he, hN', LinearEquiv.coe_toAddEquiv_symm, AddEquiv.symm_symm] exact Submodule.map_toAddSubgroup .. rw [hNN'] have hN' : N'.toAddSubgroup = AddSubgroup.pi Set.univ (fun i ↦ (Ideal.span {if h : ∃ j, f j = i then a h.choose else 0}).toAddSubgroup) := by ext g simp only [Submodule.mem_toAddSubgroup, bN'.mem_submodule_iff', snf', AddSubgroup.mem_pi, Set.mem_univ, true_implies, Ideal.mem_span_singleton] refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases h with ⟨c, rfl⟩ intro i simp only [Finset.sum_apply, Pi.smul_apply, Pi.single_apply] split_ifs with h · convert dvd_mul_left (a h.choose) (c h.choose) calc ∑ x : Fin n, _ = c h.choose * if i = f h.choose then a h.choose else 0 := by refine Finset.sum_eq_single h.choose ?_ (by simp) rintro j - hj have hinj := f.injective.ne hj rw [h.choose_spec] at hinj simp [hinj.symm] _ = c h.choose * a h.choose := by simp [h.choose_spec] · convert dvd_refl (0 : R) convert Finset.sum_const_zero with j rw [not_exists] at h specialize h j rw [eq_comm] at h simp [h] · refine ⟨fun j ↦ (h (f j)).choose, ?_⟩ ext i simp only [EmbeddingLike.apply_eq_iff_eq, exists_eq, ↓reduceDIte, Classical.choose_eq, Finset.sum_apply, Pi.smul_apply, Pi.single_apply, smul_ite, smul_zero] rw [eq_comm] by_cases! hj : ∃ j, f j = i · calc ∑ x : Fin n, _ = if i = f hj.choose then (h (f hj.choose)).choose * a hj.choose else 0 := by convert Finset.sum_eq_single (M := R) hj.choose ?_ ?_ · simp · rintro j - h have hinj := f.injective.ne h rw [hj.choose_spec] at hinj simp [hinj.symm] · simp _ = g i := by simp only [hj.choose_spec, ↓reduceIte] rw [mul_comm] conv_rhs => rw [← hj.choose_spec, (h (f hj.choose)).choose_spec] simp only [EmbeddingLike.apply_eq_iff_eq, exists_eq, ↓reduceDIte, Classical.choose_eq] congr! · exact hj.choose_spec.symm · simp [hj] · convert Finset.sum_const_zero with x · specialize hj x rw [ne_comm] at hj simp [hj] · rw [← zero_dvd_iff] convert h i simp [hj] simp only [hN', AddSubgroup.index_pi, apply_dite, Finset.prod_dite, Set.singleton_zero, Ideal.span_zero, Submodule.bot_toAddSubgroup, AddSubgroup.index_pi, AddSubgroup.index_bot, Finset.prod_const, Finset.univ_eq_attach, Finset.card_attach] rw [mul_comm] congr · convert Finset.card_compl {x | ∃ j, f j = x} using 2 · exact (Finset.compl_filter _).symm · convert (Finset.card_image_of_injective Finset.univ f.injective).symm <;> simp · rw [Finset.attach_eq_univ] let f' : Fin n → { x // x ∈ Finset.filter (fun x ↦ ∃ j, f j = x) Finset.univ } := fun i ↦ ⟨f i, by simp⟩ have hf' : Function.Injective f' := fun i j hij ↦ by rw [Subtype.ext_iff] at hij exact f.injective hij let f'' : Fin n ↪ { x // x ∈ Finset.filter (fun x ↦ ∃ j, f j = x) Finset.univ } := ⟨f', hf'⟩ have hu : (Finset.univ : Finset { x // x ∈ Finset.filter (fun x ↦ ∃ j, f j = x) Finset.univ }) = Finset.univ.map f'' := by ext x simp only [Finset.univ_eq_attach, Finset.mem_attach, Finset.mem_map, Finset.mem_univ, true_and, true_iff] have hx := x.property simp only [Finset.univ_filter_exists, Finset.mem_image, Finset.mem_univ, true_and] at hx rcases hx with ⟨i, hi⟩ refine ⟨i, ?_⟩ rw [Subtype.ext_iff] exact hi rw [hu, Finset.prod_map] congr! with i rw [← f.injective.eq_iff] generalize_proofs h rw [h.choose_spec] rfl /-- Given a submodule `N` in Smith normal form of a free `R`-module, its index as an additive subgroup is infinite (represented as zero) if the submodule basis has fewer vectors than the basis for the module, and otherwise equals the product of the indexes of the ideals generated by each basis vector. -/ lemma toAddSubgroup_index_eq_ite [Infinite R] [Module R M] {N : Submodule R M} (snf : Basis.SmithNormalForm N ι n) : N.toAddSubgroup.index = (if n = Fintype.card ι then ∏ i : Fin n, (Ideal.span {snf.a i}).toAddSubgroup.index else 0) := by rw [snf.toAddSubgroup_index_eq_pow_mul_prod] split_ifs with h · simp [h] · have hlt : n < Fintype.card ι := Ne.lt_of_le h (by simpa using Fintype.card_le_of_embedding snf.f) simp [hlt] /-- Given a submodule `N` in Smith normal form of a free ℤ-module, it has finite index as an additive subgroup (i.e., `N.toAddSubgroup.index ≠ 0`) if and only if the submodule basis has as many vectors as the basis for the module. -/ lemma toAddSubgroup_index_ne_zero_iff {N : Submodule ℤ M} (snf : Basis.SmithNormalForm N ι n) : N.toAddSubgroup.index ≠ 0 ↔ n = Fintype.card ι := by rw [snf.toAddSubgroup_index_eq_ite] rcases snf with ⟨bM, bN, f, a, snf⟩ simp only [ne_eq, ite_eq_right_iff, Classical.not_imp, and_iff_left_iff_imp] have ha : ∀ i, a i ≠ 0 := by intro i hi apply Basis.ne_zero bN i specialize snf i simpa [hi] using snf intro h simpa [Ideal.span_singleton_toAddSubgroup_eq_zmultiples, Int.index_zmultiples, Finset.prod_eq_zero_iff] using ha end Module.Basis.SmithNormalForm namespace Int variable [Finite ι] lemma submodule_toAddSubgroup_index_ne_zero_iff {N : Submodule ℤ (ι → ℤ)} : N.toAddSubgroup.index ≠ 0 ↔ Nonempty (N ≃ₗ[ℤ] (ι → ℤ)) := by obtain ⟨n, snf⟩ := N.smithNormalForm <| .ofEquivFun <| .refl .. have := Fintype.ofFinite ι rw [snf.toAddSubgroup_index_ne_zero_iff] rcases snf with ⟨-, bN, -, -, -⟩ refine ⟨fun h ↦ ?_, fun ⟨e⟩ ↦ ?_⟩ · subst h exact ⟨(bN.reindex (Fintype.equivFin _).symm).equivFun⟩ · have hc := card_eq_of_linearEquiv ℤ <| bN.equivFun.symm.trans e simpa using hc lemma addSubgroup_index_ne_zero_iff {H : AddSubgroup (ι → ℤ)} : H.index ≠ 0 ↔ Nonempty (H ≃+ (ι → ℤ)) := by convert submodule_toAddSubgroup_index_ne_zero_iff (N := AddSubgroup.toIntSubmodule H) using 1 exact ⟨fun ⟨e⟩ ↦ ⟨e.toIntLinearEquiv⟩, fun ⟨e⟩ ↦ ⟨e.toAddEquiv⟩⟩ lemma subgroup_index_ne_zero_iff {H : Subgroup (ι → Multiplicative ℤ)} : H.index ≠ 0 ↔ Nonempty (H ≃* (ι → Multiplicative ℤ)) := by let em : Multiplicative (ι → ℤ) ≃* (ι → Multiplicative ℤ) := MulEquiv.funMultiplicative _ _ let H' : Subgroup (Multiplicative (ι → ℤ)) := H.comap em let eH' : H' ≃* H := (MulEquiv.subgroupCongr <| Subgroup.comap_equiv_eq_map_symm em H).trans (MulEquiv.subgroupMap em.symm _).symm have h : H'.index = H.index := Subgroup.index_comap_of_surjective _ em.surjective rw [← h, ← Subgroup.index_toAddSubgroup, addSubgroup_index_ne_zero_iff] exact ⟨fun ⟨e⟩ ↦ ⟨(eH'.symm.trans (AddEquiv.toMultiplicative e)).trans em⟩, fun ⟨e⟩ ↦ ⟨(MulEquiv.toAdditive ((eH'.trans e).trans em.symm)).trans (AddEquiv.additiveMultiplicative _)⟩⟩ end Int
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeModule/IdealQuotient.lean
import Mathlib.LinearAlgebra.FreeModule.Finite.Quotient /-! # 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. -/ open Module open scoped DirectSum namespace Ideal 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) := Submodule.quotientEquivPiSpan (I.restrictScalars R) b <| finrank_eq_finrank b I hI /-- 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 := Submodule.quotientEquivPiZMod (I.restrictScalars ℤ) b <| finrank_eq_finrank b I hI /-- A nonzero ideal over a free finite extension of `ℤ` has a finite quotient. It can't be an instance because of the side condition `I ≠ ⊥`. -/ theorem finiteQuotientOfFreeOfNeBot [Module.Free ℤ S] [Module.Finite ℤ S] (I : Ideal S) (hI : I ≠ ⊥) : Finite (S ⧸ I) := let b := Module.Free.chooseBasis ℤ S Submodule.finiteQuotientOfFreeOfRankEq (I.restrictScalars ℤ) <| finrank_eq_finrank b I hI 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) := Submodule.quotientEquivDirectSum F b (N := (I.restrictScalars R)) <| finrank_eq_finrank b I hI 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))] : Module.finrank F (S ⧸ I) = ∑ i, Module.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, Module.finrank_directSum] end Ideal
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeModule/StrongRankCondition.lean
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
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeModule/ModN.lean
import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.Algebra.Module.ZMod import Mathlib.LinearAlgebra.Dimension.Free /-! # Quotienting out a free `ℤ`-module If `G` is a rank `d` free `ℤ`-module, then `G/nG` is a finite group of cardinality `n ^ d`. -/ open Finsupp Function Module variable {G H M : Type*} [AddCommGroup G] {n : ℕ} variable (G n) in /-- `ModN G n` denotes the quotient of `G` by multiples of `n` -/ abbrev ModN : Type _ := G ⧸ LinearMap.range (LinearMap.lsmul ℤ G n) namespace ModN instance : Module (ZMod n) (ModN G n) := QuotientAddGroup.zmodModule (by simp) /-- The universal property of `ModN G n` in terms of monoids: Monoid homomorphisms from `ModN G n` are the same as monoid homomorphisms from `G` whose values are `n`-torsion. -/ protected def liftEquiv [AddMonoid M] : (ModN G n →+ M) ≃ {φ : G →+ M // ∀ g, n • φ g = 0} where toFun f := ⟨f.comp (QuotientAddGroup.mk' _), fun g ↦ by let Gn : AddSubgroup G := (LinearMap.range (LinearMap.lsmul ℤ G n)).toAddSubgroup suffices n • g ∈ (QuotientAddGroup.mk' Gn).ker by simp only [AddMonoidHom.coe_comp, comp_apply, ← map_nsmul] change f (QuotientAddGroup.mk' Gn (n • g)) = 0 -- Can we avoid `change`? rw [this, map_zero] simp [QuotientAddGroup.ker_mk', Gn]⟩ invFun φ := QuotientAddGroup.lift _ φ <| by rintro - ⟨g, rfl⟩; simpa using φ.property g left_inv f := by ext x induction x using QuotientAddGroup.induction_on rfl -- Should `simp` suffice here? right_inv φ := by aesop /-- The universal property of `ModN G n` in terms of `ZMod n`-modules: `ZMod n`-linear maps from `ModN G n` are the same as monoid homomorphisms from `G` whose values are `n`-torsion. -/ protected def liftEquiv' [AddCommGroup H] [Module (ZMod n) H] : (ModN G n →ₗ[ZMod n] H) ≃ {φ : G →+ H // ∀ g, n • φ g = 0} := (AddMonoidHom.toZModLinearMapEquiv n).symm.toEquiv.trans ModN.liftEquiv variable (n) in /-- The quotient map `G → G / nG`. -/ def mkQ : G →+ ModN G n := (LinearMap.range (LinearMap.lsmul ℤ G n)).mkQ variable [NeZero n] /-- Given a free module `G` over `ℤ`, construct the corresponding basis of `G / ⟨n⟩` over `ℤ / nℤ`. -/ noncomputable def basis {ι : Type*} (b : Basis ι ℤ G) : Basis ι (ZMod n) (ModN G n) := by set ψ : G →+ G := zsmulAddGroupHom n set nG := LinearMap.range (LinearMap.lsmul ℤ G n) set H := G ⧸ nG set φ : G →ₗ[ℤ] H := nG.mkQ let mod : (ι →₀ ℤ) →ₗ[ℤ] (ι →₀ ZMod n) := mapRange.linearMap (Int.castAddHom _).toIntLinearMap let f : G →ₗ[ℤ] (ι →₀ ℤ) := b.repr have hker : nG ≤ LinearMap.ker (mod.comp f) := by rintro _ ⟨x, rfl⟩ ext b simp [mod, f] let g : H →ₗ[ℤ] (ι →₀ ZMod n) := nG.liftQ (mod.comp f) hker refine ⟨.ofBijective (g.toAddMonoidHom.toZModLinearMap n) ⟨?_, ?_⟩⟩ · rw [AddMonoidHom.coe_toZModLinearMap, LinearMap.toAddMonoidHom_coe, injective_iff_map_eq_zero, nG.mkQ_surjective.forall] intro x hx simp only [Submodule.mkQ_apply, g] at hx rw [Submodule.liftQ_apply] at hx replace hx : ∀ b, ↑n ∣ f x b := by simpa [mod, DFunLike.ext_iff, ZMod.intCast_zmod_eq_zero_iff_dvd] using hx simp only [Submodule.mkQ_apply] rw [Submodule.Quotient.mk_eq_zero] choose c hc using hx refine ⟨b.repr.symm ⟨(f x).support, c, by simp [hc, NeZero.ne]⟩, b.repr.injective ?_⟩ simpa [DFunLike.ext_iff, eq_comm] using hc · suffices mod ∘ b.repr = g ∘ nG.mkQ by exact (this ▸ (mapRange_surjective _ (map_zero _) ZMod.intCast_surjective).comp b.repr.surjective).of_comp ext x b simp [mod, g, f, H] lemma basis_apply_eq_mkQ {ι : Type*} (b : Basis ι ℤ G) (i : ι) : basis b i = mkQ n (b i) := by rw [Basis.apply_eq_iff]; simp [basis, mkQ] variable [Module.Free ℤ G] [Module.Finite ℤ G] instance instModuleFinite : Module.Finite (ZMod n) (ModN G n) := .of_basis <| basis <| Module.Free.chooseBasis ℤ G instance instFinite : Finite (ModN G n) := Module.finite_of_finite (ZMod n) variable (G n) @[simp] lemma natCard_eq : Nat.card (ModN G n) = n ^ Module.finrank ℤ G := by simp [Nat.card_congr (basis <| Module.Free.chooseBasis ℤ G).repr.toEquiv, Nat.card_eq_fintype_card, Module.finrank_eq_card_chooseBasisIndex] end ModN
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeModule/Norm.lean
import Mathlib.LinearAlgebra.Dual.Lemmas import Mathlib.LinearAlgebra.FreeModule.IdealQuotient import Mathlib.RingTheory.AdjoinRoot import Mathlib.RingTheory.Norm.Defs /-! # Norms on free modules over principal ideal domains -/ open Ideal Module Polynomial variable {R S ι : Type*} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R] [CommRing S] [IsDomain S] [Algebra R S] section CommRing variable (F : Type*) /-- 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 * _ rw [mul_comm, ← smul_eq_mul, LinearEquiv.restrictScalars_apply] grind [LinearEquiv.coord_apply_smul, Ideal.selfBasis_def] 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])) := PowerBasis.finite <| AdjoinRoot.powerBasis <| 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) : Module.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] congr with i exact (AdjoinRoot.powerBasis <| smithCoeffs_ne_zero b _ h i).finrank end Field
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeModule/PID.lean
import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.LinearAlgebra.Matrix.ToLin /-! # 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 -/ open Module 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 open Submodule.IsPrincipal in theorem dvd_generator_iff {R : Type*} [CommSemiring R] {I : Ideal R} [I.IsPrincipal] {x : R} (hx : x ∈ I) : x ∣ generator I ↔ I = Ideal.span {x} := by simp_rw [le_antisymm_iff, I.span_singleton_le_iff_mem.2 hx, and_true, ← Ideal.mem_span_singleton] conv_rhs => rw [← span_singleton_generator I, Submodule.span_singleton_le_iff_mem] 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 [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_lt' (hϕ ψ') rw [← span_singleton_generator (ϕ.submoduleImage N)] exact Ideal.span_singleton_le_span_singleton.mpr d_dvd_left · exact subset_span (mem_insert _ _) variable [IsDomain R] /-- 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 -- 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 := (LinearMap.ker ϕ).map M.subtype let N' : Submodule R O := (LinearMap.ker (ϕ.comp (inclusion N_le_M))).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] 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, coe_subtype] -- 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, 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_linearIndepOn 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 ∈ {i}ᶜ, a j) • a i • s i ∈ N := N.smul_mem _ (ha' i) _ = (∏ j, a j) • s i := by rw [Fintype.prod_eq_prod_compl_mul i, mul_smul] -- 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. -/ structure Module.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 Module.Basis.SmithNormalForm variable {n : ℕ} {N : Submodule R M} (snf : Basis.SmithNormalForm N ι n) (m : N) lemma repr_eq_zero_of_notMem_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 [hi, snf.snf, map_finsuppSum] @[deprecated (since := "2025-05-24")] alias repr_eq_zero_of_nmem_range := repr_eq_zero_of_notMem_range lemma le_ker_coord_of_notMem_range {i : ι} (hi : i ∉ Set.range snf.f) : N ≤ LinearMap.ker (snf.bM.coord i) := fun m hm ↦ snf.repr_eq_zero_of_notMem_range ⟨m, hm⟩ hi @[deprecated (since := "2025-05-24")] alias le_ker_coord_of_nmem_range := le_ker_coord_of_notMem_range @[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_finsuppSum] classical simp_rw [hm, map_smul, map_finsuppSum, 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 Module.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 full_rank variable {N : Submodule R M} /-- If `M` is finite free over a PID `R`, then for any submodule `N` of the same rank, we can find basis for `M` and `N` with the same indexing such that the inclusion map is a square diagonal matrix. See `Submodule.exists_smith_normal_form_of_rank_eq` for a version that states the existence of the basis. -/ noncomputable def Submodule.smithNormalFormOfRankEq [Fintype ι] (b : Basis ι R M) (h : Module.finrank R N = Module.finrank R M) : Basis.SmithNormalForm N ι (Fintype.card ι) := let ⟨n, bM, bN, f, a, snf⟩ := N.smithNormalForm b let e : Fin n ≃ Fin (Fintype.card ι) := Fintype.equivOfCardEq (by simp only [Fintype.card_fin, ← Module.finrank_eq_card_basis bM, ← h, Module.finrank_eq_card_basis bN]) ⟨bM, bN.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 `M` is finite free over a PID `R`, then for any submodule `N` of the same rank, we can find basis for `M` and `N` with the same indexing such that the inclusion map is a square diagonal matrix. See also `Submodule.smithNormalFormOfRankEq` for a version of this theorem that returns a `Basis.SmithNormalForm`. -/ theorem Submodule.exists_smith_normal_form_of_rank_eq (b : Basis ι R M) (h : Module.finrank R N = Module.finrank R M) : ∃ (b' : Basis ι R M) (a : ι → R) (ab' : Basis ι R N), ∀ i, (ab' i : M) = a i • b' i := by cases nonempty_fintype ι let ⟨bM, bN, f, a, snf⟩ := N.smithNormalFormOfRankEq b h 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 ⟨bM, a ∘ e.symm, bN.reindex e, fun i ↦ by simp only [snf, fe, Basis.coe_reindex, (· ∘ ·)]⟩ /-- If `M` is finite free over a PID `R`, then for any submodule `N` of the same rank, we can find basis for `M` and `N` with the same indexing such that the inclusion map is a square diagonal matrix; this is the basis for `M`. See: * `Submodule.smithNormalFormBotBasis` for the basis on `N`, * `Submodule.smithNormalFormCoeffs` for the entries of the diagonal matrix * `Submodule.smithNormalFormBotBasis_def` for the proof that the inclusion map forms a square diagonal matrix. -/ noncomputable def Submodule.smithNormalFormTopBasis (b : Basis ι R M) (h : Module.finrank R N = Module.finrank R M) : Basis ι R M := (exists_smith_normal_form_of_rank_eq b h).choose /-- If `M` is finite free over a PID `R`, then for any submodule `N` of the same rank, we can find basis for `M` and `N` with the same indexing such that the inclusion map is a square diagonal matrix; this is the basis for `N`. See: * `Submodule.smithNormalFormTopBasis` for the basis on `M`, * `Submodule.smithNormalFormCoeffs` for the entries of the diagonal matrix * `Submodule.smithNormalFormBotBasis_def` for the proof that the inclusion map forms a square diagonal matrix. -/ noncomputable def Submodule.smithNormalFormBotBasis (b : Basis ι R M) (h : Module.finrank R N = Module.finrank R M) : Basis ι R N := (exists_smith_normal_form_of_rank_eq b h).choose_spec.choose_spec.choose /-- If `M` is finite free over a PID `R`, then for any submodule `N` of the same rank, we can find basis for `M` and `N` with the same indexing such that the inclusion map is a square diagonal matrix; these are the entries of the diagonal matrix. See: * `Submodule.smithNormalFormTopBasis` for the basis on `M`, * `Submodule.smithNormalFormBotBasis` for the basis on `N`, * `Submodule.smithNormalFormBotBasis_def` for the proof that the inclusion map forms a square diagonal matrix. -/ noncomputable def Submodule.smithNormalFormCoeffs (b : Basis ι R M) (h : Module.finrank R N = Module.finrank R M) : ι → R := (exists_smith_normal_form_of_rank_eq b h).choose_spec.choose @[simp] theorem Submodule.smithNormalFormBotBasis_def (b : Basis ι R M) (h : Module.finrank R N = Module.finrank R M) : ∀ i, (smithNormalFormBotBasis b h i : M) = smithNormalFormCoeffs b h i • smithNormalFormTopBasis b h i := (exists_smith_normal_form_of_rank_eq b h).choose_spec.choose_spec.choose_spec @[simp] theorem Submodule.smithNormalFormCoeffs_ne_zero (b : Basis ι R M) (h : Module.finrank R N = Module.finrank R M) (i : ι) : smithNormalFormCoeffs b h i ≠ 0 := by intro hi apply Basis.ne_zero (smithNormalFormBotBasis b h) i refine Subtype.coe_injective ?_ simp [hi] end full_rank section Ideal variable {S : Type*} [CommRing S] [IsDomain S] [Algebra R S] theorem Ideal.finrank_eq_finrank [Finite ι] (b : Basis ι R S) (I : Ideal S) (hI : I ≠ ⊥) : Module.finrank R (restrictScalars R I) = Module.finrank R S := by obtain ⟨_, bS, bI, _, _, _⟩ := (I.restrictScalars R).smithNormalForm b cases nonempty_fintype ι rw [Module.finrank_eq_card_basis bS, Module.finrank_eq_card_basis bI] exact Ideal.rank_eq bS hI (bI.map ((restrictScalarsEquiv R S S I).restrictScalars R)) /-- 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 ι) := Submodule.smithNormalFormOfRankEq b (finrank_eq_finrank b I hI) 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 := Submodule.exists_smith_normal_form_of_rank_eq b (finrank_eq_finrank b I hI) /-- 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`, * `Ideal.smithCoeffs` for the entries of the diagonal matrix * `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`, * `Ideal.smithCoeffs` for the entries of the diagonal matrix * `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`, * `Ideal.selfBasis` for the basis on `I`, * `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] end Ideal end SmithNormal end PrincipalIdealDomain
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeModule/Basic.lean
import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Module.ULift import Mathlib.Data.Finsupp.Fintype import Mathlib.LinearAlgebra.Basis.Basic import Mathlib.Logic.Small.Basic /-! # 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.linearCombination_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. -/ assert_not_exists DirectSum Matrix TensorProduct universe u v w z variable {ι : Type*} (R : Type u) (M : Type v) (N : Type z) namespace Module 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 Free (R : Type u) (M : Type v) [Semiring R] [AddCommMonoid M] [Module R M] : Prop where exists_basis (R M) : Nonempty <| (I : Type v) × Basis I R M lemma Free.exists_set [Free R M] : ∃ S : Set M, Nonempty (Basis S R M) := let ⟨_I, b⟩ := exists_basis R M; ⟨Set.range b, ⟨b.reindexRange⟩⟩ theorem free_iff_set : Free R M ↔ ∃ S : Set M, Nonempty (Basis S R M) := ⟨fun _ ↦ Free.exists_set .., fun ⟨S, hS⟩ ↦ ⟨nonempty_sigma.2 ⟨S, hS⟩⟩⟩ /-- 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 free_def [Small.{w, v} M] : Free R M ↔ ∃ I : Type w, Nonempty (Basis I R M) where mp h := ⟨Shrink (Set.range h.exists_basis.some.2), ⟨(Basis.reindexRange h.exists_basis.some.2).reindex (equivShrink _)⟩⟩ mpr h := ⟨(nonempty_sigma.2 h).map fun ⟨_, b⟩ => ⟨Set.range b, b.reindexRange⟩⟩ variable {R M} theorem Free.of_basis {ι : Type w} (b : Basis ι R M) : Free R M := (free_def R M).2 ⟨Set.range b, ⟨b.reindexRange⟩⟩ end Basic namespace 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)`. -/ @[deprecated Module.Free.chooseBasis (since := "2025-08-01")] 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 instance [Module.Free R M] [Nontrivial M] : FaithfulSMul R M := .of_injective _ (chooseBasis R M).repr.symm.injective 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 attribute [local instance] RingHomInvPair.of_ringEquiv in lemma of_ringEquiv {R R' M M'} [Semiring R] [AddCommMonoid M] [Module R M] [Semiring R'] [AddCommMonoid M'] [Module R' M'] (e₁ : R ≃+* R') (e₂ : M ≃ₛₗ[RingHomClass.toRingHom e₁] M') [Module.Free R M] : Module.Free R' M' := by let I := Module.Free.ChooseBasisIndex R M obtain ⟨e₃ : M ≃ₗ[R] I →₀ R⟩ := Module.Free.chooseBasis R M let e : M' ≃+ (I →₀ R') := (e₂.symm.trans e₃).toAddEquiv.trans (Finsupp.mapRange.addEquiv (ι := I) e₁.toAddEquiv) have he (x) : e x = Finsupp.mapRange.addEquiv (ι := I) e₁.toAddEquiv (e₃ (e₂.symm x)) := rfl let e' : M' ≃ₗ[R'] (I →₀ R') := { __ := e, map_smul' := fun m x ↦ Finsupp.ext fun i ↦ by simp [he, map_smulₛₗ] } exact of_basis (.ofRepr e') attribute [local instance] RingHomInvPair.of_ringEquiv in lemma iff_of_ringEquiv {R R' M M'} [Semiring R] [AddCommMonoid M] [Module R M] [Semiring R'] [AddCommMonoid M'] [Module R' M'] (e₁ : R ≃+* R') (e₂ : M ≃ₛₗ[RingHomClass.toRingHom e₁] M') : Module.Free R M ↔ Module.Free R' M' := ⟨fun _ ↦ of_ringEquiv e₁ e₂, fun _ ↦ of_ringEquiv e₁.symm e₂.symm⟩ 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 ulift [Free R M] : Free R (ULift M) := of_equiv ULift.moduleEquiv.symm instance (priority := 100) of_subsingleton [Subsingleton N] : Module.Free R N := of_basis.{u,z,z} (Basis.empty N : Basis PEmpty R N) -- This was previously a global instance, -- but it doesn't appear to be used and has been implicated in slow typeclass resolutions. lemma of_subsingleton' [Subsingleton R] : Module.Free R N := letI := Module.subsingleton R N Module.Free.of_subsingleton R N end Semiring end Free namespace Basis open Finset variable {S : Type*} [CommRing R] [Ring S] [Algebra R S] variable {R} in /-- If `B` is a basis of the `R`-algebra `S` such that `B i = 1` for some index `i`, then each `r : R` gets represented as `s • B i` as an element of `S`. -/ theorem repr_algebraMap {ι : Type*} {B : Basis ι R S} {i : ι} (hBi : B i = 1) (r : R) : B.repr (algebraMap R S r) = Finsupp.single i r := by ext j; simp [Algebra.algebraMap_eq_smul_one, ← hBi] end Module.Basis
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeModule/Determinant.lean
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 high] 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)
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeModule/Finite/Matrix.lean
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.LinearAlgebra.Dimension.Finite /-! # 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 Module (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 Module.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 Module.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 Module.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 Module.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 cardinalMk_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, Module.rank_linearMap_self] @[stacks 09HS] theorem card_algHom_le_finrank : Nat.card (M →ₐ[K] L) ≤ finrank K M := by convert toNat_le_toNat (cardinalMk_algHom_le_rank K M L) ?_ · rw [toNat_lift, finrank] · rw [lift_lt_aleph0]; have := Module.nontrivial K L; apply Module.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
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeModule/Finite/CardQuotient.lean
import Mathlib.Data.Int.Associated import Mathlib.Data.Int.NatAbs import Mathlib.LinearAlgebra.Determinant import Mathlib.LinearAlgebra.FreeModule.Finite.Quotient /-! # Cardinal of quotient of free finite `ℤ`-modules by submodules of full rank ## Main results * `Submodule.natAbs_det_basis_change`: let `b` be a `ℤ`-basis for a module `M` over `ℤ` and let `bN` be a basis for a submodule `N` of the same dimension. Then the cardinal of `M ⧸ N` is given by taking the determinant of `bN` over `b`. -/ open Module Submodule section Submodule variable {M : Type*} [AddCommGroup M] [Module.Free ℤ M] [Module.Finite ℤ M] /-- Let `e : M ≃ N` be an additive isomorphism (therefore a `ℤ`-linear equiv). Then an alternative way to compute the cardinality of the quotient `M ⧸ N` is given by taking the determinant of `e`. See `natAbs_det_basis_change` for a more familiar formulation of this result. -/ theorem Submodule.natAbs_det_equiv (N : Submodule ℤ M) {E : Type*} [EquivLike E M N] [AddEquivClass E M N] (e : E) : Int.natAbs (LinearMap.det (N.subtype ∘ₗ AddMonoidHom.toIntLinearMap (e : M →+ N))) = Nat.card (M ⧸ N) := by let b := Module.Free.chooseBasis ℤ M -- Since `e : M ≃ₗ[ℤ] N`, the submodule `N` has full rank. have h : Module.finrank ℤ N = Module.finrank ℤ M := (AddEquiv.toIntLinearEquiv e : M ≃ₗ[ℤ] N).symm.finrank_eq -- Use the Smith normal form to choose a nice basis for `N`. let a := smithNormalFormCoeffs b h let b' := smithNormalFormTopBasis b h let ab := smithNormalFormBotBasis b h have ab_eq := smithNormalFormBotBasis_def b h let e' : M ≃ₗ[ℤ] N := b'.equiv ab (Equiv.refl _) let f : M →ₗ[ℤ] M := N.subtype.comp (e' : M →ₗ[ℤ] N) let f_apply : ∀ x, f x = b'.equiv ab (Equiv.refl _) x := fun x ↦ rfl suffices (LinearMap.det f).natAbs = Nat.card (M ⧸ N) by calc _ = (LinearMap.det (N.subtype ∘ₗ (AddEquiv.toIntLinearEquiv e : M ≃ₗ[ℤ] N))).natAbs := rfl _ = (LinearMap.det (N.subtype ∘ₗ _)).natAbs := Int.natAbs_eq_iff_associated.mpr (LinearMap.associated_det_comp_equiv _ _ _) _ = Nat.card (M ⧸ N) := this have ha : ∀ i, f (b' i) = a i • b' i := by intro i rw [f_apply, b'.equiv_apply, Equiv.refl_apply] exact ab_eq i calc Int.natAbs (LinearMap.det f) = Int.natAbs (LinearMap.toMatrix b' b' f).det := by rw [LinearMap.det_toMatrix] _ = Int.natAbs (Matrix.diagonal a).det := ?_ _ = Int.natAbs (∏ i, a i) := by rw [Matrix.det_diagonal] _ = ∏ i, Int.natAbs (a i) := map_prod Int.natAbsHom a Finset.univ _ = Nat.card (M ⧸ N) := ?_ -- since `LinearMap.toMatrix b' b' f` is the diagonal matrix with `a` along the diagonal. · congr 2; ext i j rw [LinearMap.toMatrix_apply, ha, LinearEquiv.map_smul, Basis.repr_self, Finsupp.smul_single, smul_eq_mul, mul_one] by_cases h : i = j · rw [h, Matrix.diagonal_apply_eq, Finsupp.single_eq_same] · rw [Matrix.diagonal_apply_ne _ h, Finsupp.single_eq_of_ne h] -- Now we map everything through the linear equiv `M ≃ₗ (ι → ℤ)`, -- which maps `(M ⧸ N)` to `Π i, ZMod (a i).nat_abs`. haveI : ∀ i, NeZero (a i).natAbs := fun i ↦ ⟨Int.natAbs_ne_zero.mpr (smithNormalFormCoeffs_ne_zero b h i)⟩ simp_rw [Nat.card_congr (quotientEquivPiZMod N b h).toEquiv, Nat.card_pi, Nat.card_zmod, a] /-- Let `b` be a basis for `M` over `ℤ` and `bN` a basis for `N` over `ℤ` of the same dimension. Then an alternative way to compute the cardinality of `M ⧸ N` is given by taking the determinant of `bN` over `b`. -/ theorem Submodule.natAbs_det_basis_change {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι ℤ M) (N : Submodule ℤ M) (bN : Basis ι ℤ N) : (b.det ((↑) ∘ bN)).natAbs = Nat.card (M ⧸ N) := by let e := b.equiv bN (Equiv.refl _) calc (b.det (N.subtype ∘ bN)).natAbs = (LinearMap.det (N.subtype ∘ₗ (e : M →ₗ[ℤ] N))).natAbs := by rw [Basis.det_comp_basis] _ = _ := natAbs_det_equiv N e end Submodule section AddSubgroup theorem AddSubgroup.index_eq_natAbs_det {E : Type*} [AddCommGroup E] {ι : Type*} [DecidableEq ι] [Fintype ι] (bE : Basis ι ℤ E) (N : AddSubgroup E) (bN : Basis ι ℤ N) : N.index = (bE.det (bN ·)).natAbs := have : Module.Free ℤ E := Module.Free.of_basis bE have : Module.Finite ℤ E := Module.Finite.of_basis bE (Submodule.natAbs_det_basis_change bE N.toIntSubmodule bN).symm theorem AddSubgroup.relIndex_eq_natAbs_det {E : Type*} [AddCommGroup E] (L₁ L₂ : AddSubgroup E) (H : L₁ ≤ L₂) {ι : Type*} [DecidableEq ι] [Fintype ι] (b₁ : Basis ι ℤ L₁.toIntSubmodule) (b₂ : Basis ι ℤ L₂.toIntSubmodule) : L₁.relIndex L₂ = (b₂.det (fun i ↦ ⟨b₁ i, (H (SetLike.coe_mem _))⟩)).natAbs := by rw [relIndex, index_eq_natAbs_det b₂ _ (b₁.map (addSubgroupOfEquivOfLe H).toIntLinearEquiv.symm)] rfl @[deprecated (since := "2025-08-12")] alias AddSubgroup.relindex_eq_natAbs_det := AddSubgroup.relIndex_eq_natAbs_det theorem AddSubgroup.relIndex_eq_abs_det {E : Type*} [AddCommGroup E] [Module ℚ E] (L₁ L₂ : AddSubgroup E) (H : L₁ ≤ L₂) {ι : Type*} [DecidableEq ι] [Fintype ι] (b₁ b₂ : Basis ι ℚ E) (h₁ : L₁ = .closure (Set.range b₁)) (h₂ : L₂ = .closure (Set.range b₂)) : L₁.relIndex L₂ = |b₂.det b₁| := by rw [AddSubgroup.relIndex_eq_natAbs_det L₁ L₂ H (b₁.addSubgroupOfClosure L₁ h₁) (b₂.addSubgroupOfClosure L₂ h₂), Nat.cast_natAbs, Int.cast_abs] change |algebraMap ℤ ℚ _| = _ rw [Basis.det_apply, Basis.det_apply, RingHom.map_det] congr; ext simp [Basis.toMatrix_apply] @[deprecated (since := "2025-08-12")] alias AddSubgroup.relindex_eq_abs_det := AddSubgroup.relIndex_eq_abs_det end AddSubgroup
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeModule/Finite/Basic.lean
import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.LinearAlgebra.Matrix.StdBasis import Mathlib.RingTheory.Finiteness.Cardinality /-! # 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 /-- If a free module is finite, then the arbitrary basis is finite. -/ noncomputable instance Module.Free.ChooseBasisIndex.fintype (R : Type u) (M : Type v) [Semiring R] [AddCommMonoid M] [Module R M] [Module.Free R M] [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 _ _) /-- A free module with a basis indexed by a `Fintype` is finite. -/ theorem 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 Module.Finite.matrix {R ι₁ ι₂ M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] [Module.Free R M] [Module.Finite R M] [_root_.Finite ι₁] [_root_.Finite ι₂] : Module.Finite R (Matrix ι₁ ι₂ M) := by cases nonempty_fintype ι₁ cases nonempty_fintype ι₂ exact Module.Finite.of_basis <| (Free.chooseBasis _ _).matrix _ _ example {ι₁ ι₂ R : Type*} [Semiring R] [Finite ι₁] [Finite ι₂] : Module.Finite R (Matrix ι₁ ι₂ R) := inferInstance
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeModule/Finite/Quotient.lean
import Mathlib.Data.ZMod.QuotientRing import Mathlib.LinearAlgebra.Dimension.Constructions import Mathlib.LinearAlgebra.FreeModule.PID import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.LinearAlgebra.Quotient.Pi /-! # Quotient of submodules of full rank in free finite modules over PIDs ## Main results * `Submodule.quotientEquivPiSpan`: `M ⧸ N`, if `M` is free finite module over a PID `R` and `N` is a submodule of full rank, can be written as a product of quotients of `R` by principal ideals. -/ open Module open scoped DirectSum namespace Submodule variable {ι R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] variable [IsDomain R] [IsPrincipalIdealRing R] [Finite ι] /-- We can write the quotient by a submodule of full rank over a PID as a product of quotients by principal ideals. -/ noncomputable def quotientEquivPiSpan (N : Submodule R M) (b : Basis ι R M) (h : Module.finrank R N = Module.finrank R M) : (M ⧸ N) ≃ₗ[R] Π i, R ⧸ Ideal.span ({smithNormalFormCoeffs b h i} : Set R) := by haveI := Fintype.ofFinite ι -- Choose `e : M ≃ₗ N` and a basis `b'` for `M` that turns the map -- `f := ((Submodule.subtype N).comp e` into a diagonal matrix: -- there is an `a : ι → ℤ` such that `f (b' i) = a i • b' i`. let a := smithNormalFormCoeffs b h let b' := smithNormalFormTopBasis b h let ab := smithNormalFormBotBasis b h have ab_eq := smithNormalFormBotBasis_def b h have mem_I_iff : ∀ x, x ∈ N ↔ ∀ i, a i ∣ b'.repr x i := by intro x simp_rw [ab.mem_submodule_iff', ab, 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 `M ≃ₗ (ι → R)`, -- which maps `N` to `N' := Π i, a i ℤ`. let N' : Submodule R (ι → R) := Submodule.pi Set.univ fun i => span R ({a i} : Set R) have : Submodule.map (b'.equivFun : M →ₗ[R] ι → R) N = N' := by ext x simp only [N', Submodule.mem_map, Submodule.mem_pi, mem_span_singleton, Set.mem_univ, mem_I_iff, smul_eq_mul, forall_true_left, LinearEquiv.coe_coe, Basis.equivFun_apply, mul_comm _ (a _), eq_comm (b := (x _))] 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.equiv N N' b'.equivFun this).trans (re₂₃ := inferInstance) (re₃₂ := inferInstance) ?_ classical exact Submodule.quotientPi (show _ → Submodule R R from fun i => span R ({a i} : Set R)) /-- Quotients by submodules of full rank of free finite `ℤ`-modules are isomorphic to a direct product of `ZMod`. -/ noncomputable def quotientEquivPiZMod (N : Submodule ℤ M) (b : Basis ι ℤ M) (h : Module.finrank ℤ N = Module.finrank ℤ M) : M ⧸ N ≃+ Π i, ZMod (smithNormalFormCoeffs b h i).natAbs := let a := smithNormalFormCoeffs b h let e := N.quotientEquivPiSpan b h let e' : (∀ i : ι, ℤ ⧸ Ideal.span ({a i} : Set ℤ)) ≃+ ∀ i : ι, ZMod (a i).natAbs := AddEquiv.piCongrRight fun i => ↑(Int.quotientSpanEquivZMod (a i)) (↑(e : (M ⧸ N) ≃ₗ[ℤ] _) : M ⧸ N ≃+ _).trans e' /-- A submodule of full rank of a free finite `ℤ`-module has a finite quotient. It can't be an instance because of the side condition `Module.finrank ℤ N = Module.finrank ℤ M`. -/ theorem finiteQuotientOfFreeOfRankEq [Module.Free ℤ M] [Module.Finite ℤ M] (N : Submodule ℤ M) (h : Module.finrank ℤ N = Module.finrank ℤ M) : Finite (M ⧸ N) := by let b := Module.Free.chooseBasis ℤ M let a := smithNormalFormCoeffs b h let e := N.quotientEquivPiZMod b h have : ∀ i, NeZero (a i).natAbs := fun i ↦ ⟨Int.natAbs_ne_zero.mpr (smithNormalFormCoeffs_ne_zero b h i)⟩ exact Finite.of_equiv (Π i, ZMod (a i).natAbs) e.symm theorem finiteQuotient_iff [Module.Free ℤ M] [Module.Finite ℤ M] (N : Submodule ℤ M) : Finite (M ⧸ N) ↔ Module.finrank ℤ N = Module.finrank ℤ M := by refine ⟨fun h ↦ le_antisymm (finrank_le N) <| ((LinearMap.lsmul ℤ M (Nat.card (M ⧸ N))).codRestrict N fun x ↦ ?_).finrank_le_finrank_of_injective ?_, fun h ↦ finiteQuotientOfFreeOfRankEq N h⟩ · simpa using AddSubgroup.nsmul_index_mem N.toAddSubgroup x · refine (LinearMap.lsmul_injective ?_).codRestrict _ exact Int.ofNat_ne_zero.mpr <| Nat.card_ne_zero.mpr ⟨Set.nonempty_iff_univ_nonempty.mpr Set.univ_nonempty, h⟩ variable (F : Type*) [CommRing F] [Algebra F R] [Module F M] [IsScalarTower F R M] (b : Basis ι R M) {N : Submodule R M} /-- Decompose `M⧸N` as a direct sum of cyclic `R`-modules (quotients by the ideals generated by Smith coefficients of `N`). -/ noncomputable def quotientEquivDirectSum (h : Module.finrank R N = Module.finrank R M) : (M ⧸ N) ≃ₗ[F] ⨁ i, R ⧸ Ideal.span ({smithNormalFormCoeffs b h i} : Set R) := by haveI := Fintype.ofFinite ι exact ((N.quotientEquivPiSpan b _).restrictScalars F).trans (DirectSum.linearEquivFunOnFintype _ _ _).symm theorem finrank_quotient_eq_sum {ι} [Fintype ι] (b : Basis ι R M) [Nontrivial F] (h : Module.finrank R N = Module.finrank R M) [∀ i, Module.Free F (R ⧸ Ideal.span ({smithNormalFormCoeffs b h i} : Set R))] [∀ i, Module.Finite F (R ⧸ Ideal.span ({smithNormalFormCoeffs b h i} : Set R))] : Module.finrank F (M ⧸ N) = ∑ i, Module.finrank F (R ⧸ Ideal.span ({smithNormalFormCoeffs b h i} : Set R)) := by rw [LinearEquiv.finrank_eq <| quotientEquivDirectSum F b h, Module.finrank_directSum] end Submodule
.lake/packages/mathlib/Mathlib/LinearAlgebra/SesquilinearForm/Star.lean
import Mathlib.LinearAlgebra.Matrix.PosDef /-! # Sesquilinear forms over a star ring This file provides some properties about sesquilinear forms `M →ₗ⋆[R] M →ₗ[R] R` when `R` is a `StarRing`. -/ open Module LinearMap variable {R M n : Type*} [CommSemiring R] [StarRing R] [AddCommMonoid M] [Module R M] [Fintype n] [DecidableEq n] {B : M →ₗ⋆[R] M →ₗ[R] R} (b : Basis n R M) lemma LinearMap.isSymm_iff_basis {ι : Type*} (b : Basis ι R M) : IsSymm B ↔ ∀ i j, star (B (b i) (b j)) = B (b j) (b i) where mp h i j := h.eq _ _ mpr := by refine fun h ↦ ⟨fun x y ↦ ?_⟩ obtain ⟨fx, tx, ix, -, hx⟩ := Submodule.mem_span_iff_exists_finset_subset.1 (by simp : x ∈ Submodule.span R (Set.range b)) obtain ⟨fy, ty, iy, -, hy⟩ := Submodule.mem_span_iff_exists_finset_subset.1 (by simp : y ∈ Submodule.span R (Set.range b)) rw [← hx, ← hy] simp only [map_sum, LinearMap.map_smulₛₗ, starRingEnd_apply, map_smul, coeFn_sum, Finset.sum_apply, smul_apply, smul_eq_mul, Finset.mul_sum, map_mul, star_star] rw [Finset.sum_comm] refine Finset.sum_congr rfl (fun b₁ h₁ ↦ Finset.sum_congr rfl fun b₂ h₂ ↦ ?_) rw [mul_left_comm] obtain ⟨i, rfl⟩ := ix h₁ obtain ⟨j, rfl⟩ := iy h₂ rw [h] lemma LinearMap.isSymm_iff_isHermitian_toMatrix : B.IsSymm ↔ (toMatrix₂ b b B).IsHermitian := by rw [isSymm_iff_basis b, Matrix.IsHermitian.ext_iff, forall_comm] simp [Eq.comm] lemma star_dotProduct_toMatrix₂_mulVec (x y : n → R) : star x ⬝ᵥ (toMatrix₂ b b B).mulVec y = B (b.equivFun.symm x) (b.equivFun.symm y) := dotProduct_toMatrix₂_mulVec b b B x y lemma apply_eq_star_dotProduct_toMatrix₂_mulVec (x y : M) : B x y = star (b.repr x) ⬝ᵥ (toMatrix₂ b b B).mulVec (b.repr y) := apply_eq_dotProduct_toMatrix₂_mulVec b b B x y variable {R : Type*} [CommRing R] [StarRing R] [PartialOrder R] [Module R M] {B : M →ₗ⋆[R] M →ₗ[R] R} (b : Basis n R M) lemma LinearMap.isPosSemidef_iff_posSemidef_toMatrix : B.IsPosSemidef ↔ (toMatrix₂ b b B).PosSemidef := by rw [isPosSemidef_def, Matrix.PosSemidef] apply and_congr (B.isSymm_iff_isHermitian_toMatrix b) rw [isNonneg_def] refine ⟨fun h x ↦ ?_, fun h x ↦ ?_⟩ · rw [star_dotProduct_toMatrix₂_mulVec] exact h _ · rw [apply_eq_star_dotProduct_toMatrix₂_mulVec b] exact h _