path stringlengths 11 71 | content stringlengths 75 124k |
|---|---|
Lean\Exception.lean | /-
Copyright (c) 2022 E.W.Ayers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: E.W.Ayers
-/
import Lean.Exception
/-!
# Additional methods for working with `Exception`s
This file contains two additional methods for working with `Exception`s
* `successIfFail`, a generalisation of `fail_if_success` to arbitrary `MonadError`s
* `isFailedToSynthesize`: check if an exception is of the "failed to synthesize" form
-/
open Lean
/--
A generalisation of `fail_if_success` to an arbitrary `MonadError`.
-/
def successIfFail {α : Type} {M : Type → Type} [MonadError M] [Monad M] (m : M α) :
M Exception := do
match ← tryCatch (m *> pure none) (pure ∘ some) with
| none => throwError "Expected an exception."
| some ex => return ex
namespace Lean
namespace Exception
/--
Check if an exception is a "failed to synthesize" exception.
These exceptions are raised in several different places,
and the only commonality is the prefix of the string, so that's what we look for.
-/
def isFailedToSynthesize (e : Exception) : IO Bool := do
pure <| (← e.toMessageData.toString).startsWith "failed to synthesize"
|
Lean\Expr.lean | /-
Copyright (c) 2019 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Simon Hudon, Scott Morrison, Keeley Hoek, Robert Y. Lewis, Floris van Doorn
-/
import Mathlib.Lean.Expr.Basic
import Mathlib.Lean.Expr.ReplaceRec
|
Lean\GoalsLocation.lean | /-
Copyright (c) 2023 Jovan Gerbscheid. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jovan Gerbscheid
-/
import Lean.Meta.Tactic.Util
import Lean.SubExpr
/-! This file defines some functions for dealing with `SubExpr.GoalsLocation`. -/
namespace Lean.SubExpr.GoalsLocation
/-- The root expression of the position specified by the `GoalsLocation`. -/
def rootExpr : GoalsLocation → MetaM Expr
| ⟨_, .hyp fvarId⟩ => fvarId.getType
| ⟨_, .hypType fvarId _⟩ => fvarId.getType
| ⟨_, .hypValue fvarId _⟩ => do return (← fvarId.getDecl).value
| ⟨mvarId, .target _⟩ => mvarId.getType
/-- The `SubExpr.Pos` specified by the `GoalsLocation`. -/
def pos : GoalsLocation → Pos
| ⟨_, .hyp _⟩ => .root
| ⟨_, .hypType _ pos⟩ => pos
| ⟨_, .hypValue _ pos⟩ => pos
| ⟨_, .target pos⟩ => pos
/-- The hypothesis specified by the `GoalsLocation`. -/
def location : GoalsLocation → MetaM (Option Name)
| ⟨_, .hyp fvarId⟩ => some <$> fvarId.getUserName
| ⟨_, .hypType fvarId _⟩ => some <$> fvarId.getUserName
| ⟨_, .hypValue fvarId _⟩ => some <$> fvarId.getUserName
| ⟨_, .target _⟩ => return none
|
Lean\Json.lean | /-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Lean.Data.Json.FromToJson
/-!
# Json serialization typeclass for `PUnit` & `Fin n` & `Subtype p`
-/
universe u
namespace Lean
deriving instance FromJson, ToJson for PUnit
instance {n : Nat} : FromJson (Fin n) where
fromJson? j := do
let i : Nat ← fromJson? j
if h : i < n then
return ⟨i, h⟩
else
throw s!"must be less than {n}"
instance {n : Nat} : ToJson (Fin n) where
toJson i := toJson i.val
instance {α : Type u} [FromJson α] (p : α → Prop) [DecidablePred p] : FromJson (Subtype p) where
fromJson? j := do
let i : α ← fromJson? j
if h : p i then
return ⟨i, h⟩
else
throw "condition does not hold"
instance {α : Type u} [ToJson α] (p : α → Prop) : ToJson (Subtype p) where
toJson x := toJson x.val
|
Lean\LocalContext.lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Lean.LocalContext
/-!
# Additional methods about `LocalContext`
-/
namespace Lean.LocalContext
universe u v
variable {m : Type u → Type v} [Monad m] [Alternative m]
variable {β : Type u}
/-- Return the result of `f` on the first local declaration on which `f` succeeds. -/
@[specialize] def firstDeclM (lctx : LocalContext) (f : LocalDecl → m β) : m β :=
do match (← lctx.findDeclM? (optional ∘ f)) with
| none => failure
| some b => pure b
/-- Return the result of `f` on the last local declaration on which `f` succeeds. -/
@[specialize] def lastDeclM (lctx : LocalContext) (f : LocalDecl → m β) : m β :=
do match (← lctx.findDeclRevM? (optional ∘ f)) with
| none => failure
| some b => pure b
end Lean.LocalContext
|
Lean\Message.lean | /-
Copyright (c) 2022 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Lean.Message
/-!
# Additional operations on MessageData and related types
-/
open Lean Std MessageData
instance {α β : Type} [ToMessageData α] [ToMessageData β] : ToMessageData (α × β) :=
⟨fun x => paren <| toMessageData x.1 ++ ofFormat "," ++ Format.line ++ toMessageData x.2⟩
|
Lean\Meta.lean | /-
Copyright (c) 2022 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Lean.Elab.Term
import Lean.Elab.Tactic.Basic
import Lean.Meta.Tactic.Assert
import Lean.Meta.Tactic.Clear
import Batteries.CodeAction -- to enable the hole code action
/-! ## Additional utilities in `Lean.MVarId` -/
open Lean Meta
namespace Lean.MVarId
/-- Add the hypothesis `h : t`, given `v : t`, and return the new `FVarId`. -/
def «let» (g : MVarId) (h : Name) (v : Expr) (t : Option Expr := .none) :
MetaM (FVarId × MVarId) := do
(← g.define h (← t.getDM (inferType v)) v).intro1P
/-- Has the effect of `refine ⟨e₁,e₂,⋯, ?_⟩`.
-/
def existsi (mvar : MVarId) (es : List Expr) : MetaM MVarId := do
es.foldlM (fun mv e ↦ do
let (subgoals,_) ← Elab.Term.TermElabM.run <| Elab.Tactic.run mv do
Elab.Tactic.evalTactic (← `(tactic| refine ⟨?_,?_⟩))
let [sg1, sg2] := subgoals | throwError "expected two subgoals"
sg1.assign e
pure sg2)
mvar
/-- Applies `intro` repeatedly until it fails. We use this instead of
`Lean.MVarId.intros` to allowing unfolding.
For example, if we want to do introductions for propositions like `¬p`,
the `¬` needs to be unfolded into `→ False`, and `intros` does not do such unfolding. -/
partial def intros! (mvarId : MVarId) : MetaM (Array FVarId × MVarId) :=
run #[] mvarId
where
/-- Implementation of `intros!`. -/
run (acc : Array FVarId) (g : MVarId) :=
try
let ⟨f, g⟩ ← mvarId.intro1
run (acc.push f) g
catch _ =>
pure (acc, g)
end Lean.MVarId
namespace Lean.Meta
/-- Get the type the given metavariable after instantiating metavariables and cleaning up
annotations. -/
def _root_.Lean.MVarId.getType'' (mvarId : MVarId) : MetaM Expr :=
return (← instantiateMVars (← mvarId.getType)).cleanupAnnotations
end Lean.Meta
namespace Lean.Elab.Tactic
/-- Analogue of `liftMetaTactic` for tactics that return a single goal. -/
-- I'd prefer to call that `liftMetaTactic1`,
-- but that is taken in core by a function that lifts a `tac : MVarId → MetaM (Option MVarId)`.
def liftMetaTactic' (tac : MVarId → MetaM MVarId) : TacticM Unit :=
liftMetaTactic fun g => do pure [← tac g]
variable {α : Type}
@[inline] private def TacticM.runCore (x : TacticM α) (ctx : Context) (s : State) :
TermElabM (α × State) :=
x ctx |>.run s
@[inline] private def TacticM.runCore' (x : TacticM α) (ctx : Context) (s : State) : TermElabM α :=
Prod.fst <$> x.runCore ctx s
/-- Copy of `Lean.Elab.Tactic.run` that can return a value. -/
-- We need this because Lean 4 core only provides `TacticM` functions for building simp contexts,
-- making it quite painful to call `simp` from `MetaM`.
def run_for (mvarId : MVarId) (x : TacticM α) : TermElabM (Option α × List MVarId) :=
mvarId.withContext do
let pendingMVarsSaved := (← get).pendingMVars
modify fun s => { s with pendingMVars := [] }
let aux : TacticM (Option α × List MVarId) :=
/- Important: the following `try` does not backtrack the state.
This is intentional because we don't want to backtrack the error message
when we catch the "abort internal exception"
We must define `run` here because we define `MonadExcept` instance for `TacticM` -/
try
let a ← x
pure (a, ← getUnsolvedGoals)
catch ex =>
if isAbortTacticException ex then
pure (none, ← getUnsolvedGoals)
else
throw ex
try
aux.runCore' { elaborator := .anonymous } { goals := [mvarId] }
finally
modify fun s => { s with pendingMVars := pendingMVarsSaved }
end Lean.Elab.Tactic
|
Lean\Name.lean | /-
Copyright (c) 2023 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Lean.Meta.Match.MatcherInfo
import Lean.Meta.Tactic.Delta
import Std.Data.HashMap.Basic
/-!
# Additional functions on `Lean.Name`.
We provide `allNames` and `allNamesByModule`.
-/
open Lean Meta Elab
private def isBlackListed (declName : Name) : CoreM Bool := do
if declName.toString.startsWith "Lean" then return true
let env ← getEnv
pure <| declName.isInternalDetail
|| isAuxRecursor env declName
|| isNoConfusion env declName
<||> isRec declName <||> isMatcher declName
/--
Retrieve all names in the environment satisfying a predicate.
-/
def allNames (p : Name → Bool) : CoreM (Array Name) := do
(← getEnv).constants.foldM (init := #[]) fun names n _ => do
if p n && !(← isBlackListed n) then
return names.push n
else
return names
/--
Retrieve all names in the environment satisfying a predicate,
gathered together into a `HashMap` according to the module they are defined in.
-/
def allNamesByModule (p : Name → Bool) : CoreM (Std.HashMap Name (Array Name)) := do
(← getEnv).constants.foldM (init := Std.HashMap.empty) fun names n _ => do
if p n && !(← isBlackListed n) then
let some m ← findModuleOf? n | return names
-- TODO use `modify` and/or `alter` when available
match names[m]? with
| some others => return names.insert m (others.push n)
| none => return names.insert m #[n]
else
return names
/-- Decapitalize the last component of a name. -/
def Lean.Name.decapitalize (n : Name) : Name :=
n.modifyBase fun
| .str p s => .str p s.decapitalize
| n => n
/-- Whether the lemma has a name of the form produced by `Lean.Meta.mkAuxLemma`. -/
def Lean.Name.isAuxLemma (n : Name) : Bool := n matches .num (.str _ "_auxLemma") _
/-- Unfold all lemmas created by `Lean.Meta.mkAuxLemma`.
The names of these lemmas end in `_auxLemma.nn` where `nn` is a number. -/
def Lean.Meta.unfoldAuxLemmas (e : Expr) : MetaM Expr := do
deltaExpand e Lean.Name.isAuxLemma
|
Lean\Thunk.lean | /-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import Batteries.Data.Thunk
/-!
# Basic facts about `Thunk`.
-/
namespace Thunk
@[simp] theorem get_pure {α} (x : α) : (Thunk.pure x).get = x := rfl
@[simp] theorem get_mk {α} (f : Unit → α) : (Thunk.mk f).get = f () := rfl
universe u v
variable {α : Type u} {β : Type v}
instance [DecidableEq α] : DecidableEq (Thunk α) := by
intro a b
have : a = b ↔ a.get = b.get := ⟨by intro x; rw [x], by intro; ext; assumption⟩
rw [this]
infer_instance
/-- The cartesian product of two thunks. -/
def prod (a : Thunk α) (b : Thunk β) : Thunk (α × β) := Thunk.mk fun _ => (a.get, b.get)
@[simp] theorem prod_get_fst {a : Thunk α} {b : Thunk β} : (prod a b).get.1 = a.get := rfl
@[simp] theorem prod_get_snd {a : Thunk α} {b : Thunk β} : (prod a b).get.2 = b.get := rfl
/-- The sum of two thunks. -/
def add [Add α] (a b : Thunk α) : Thunk α := Thunk.mk fun _ => a.get + b.get
instance [Add α] : Add (Thunk α) := ⟨add⟩
@[simp] theorem add_get [Add α] {a b : Thunk α} : (a + b).get = a.get + b.get := rfl
end Thunk
|
Lean\Elab\Term.lean | /-
Copyright (c) 2023 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Lean.Elab.SyntheticMVars
/-!
# Additions to `Lean.Elab.Term`
-/
namespace Lean.Elab.Term
/-- Fully elaborates the term `patt`, allowing typeclass inference failure,
but while setting `errToSorry` to false.
Typeclass failures result in plain metavariables.
Instantiates all assigned metavariables. -/
def elabPattern (patt : Term) (expectedType? : Option Expr) : TermElabM Expr := do
withTheReader Term.Context ({ · with ignoreTCFailures := true, errToSorry := false }) <|
withSynthesizeLight do
let t ← elabTerm patt expectedType?
synthesizeSyntheticMVars (postpone := .no) (ignoreStuckTC := true)
instantiateMVars t
|
Lean\Elab\Tactic\Basic.lean | /-
Copyright (c) 2023 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Jon Eugster
-/
import Mathlib.Lean.Meta
/-!
# Additions to `Lean.Elab.Tactic.Basic`
-/
open Lean Elab Tactic
namespace Lean.Elab.Tactic
/-- Return expected type for the main goal, cleaning up annotations, using `Lean.MVarId.getType''`.
Remark: note that `MVarId.getType'` uses `whnf` instead of `cleanupAnnotations`, and
`MVarId.getType''` also uses `cleanupAnnotations` -/
def getMainTarget'' : TacticM Expr := do
(← getMainGoal).getType''
/--
Like `done` but takes a scope (e.g. a tactic name) as an argument
to produce more detailed error messages.
-/
def doneWithScope (scope : MessageData) : TacticM Unit := do
let gs ← getUnsolvedGoals
unless gs.isEmpty do
logError m!"{scope} failed to solve some goals.\n"
Term.reportUnsolvedGoals gs
throwAbortTactic
/--
Like `focusAndDone` but takes a scope (e.g. tactic name) as an argument to
produce more detailed error messages.
-/
def focusAndDoneWithScope {α : Type} (scope : MessageData) (tactic : TacticM α) : TacticM α :=
focus do
let a ← try tactic catch e =>
if isAbortTacticException e then throw e
else throwError "{scope} failed.\n{← nestedExceptionToMessageData e}"
doneWithScope scope
pure a
end Lean.Elab.Tactic
|
Lean\Expr\Basic.lean | /-
Copyright (c) 2019 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Simon Hudon, Scott Morrison, Keeley Hoek, Robert Y. Lewis,
Floris van Doorn, E.W.Ayers, Arthur Paulino
-/
import Lean.Meta.Tactic.Rewrite
import Batteries.Lean.Expr
import Batteries.Data.Rat.Basic
import Batteries.Data.List.Basic
import Batteries.Logic
/-!
# Additional operations on Expr and related types
This file defines basic operations on the types expr, name, declaration, level, environment.
This file is mostly for non-tactics.
-/
namespace Lean
namespace BinderInfo
/-! ### Declarations about `BinderInfo` -/
/-- The brackets corresponding to a given `BinderInfo`. -/
def brackets : BinderInfo → String × String
| BinderInfo.implicit => ("{", "}")
| BinderInfo.strictImplicit => ("{{", "}}")
| BinderInfo.instImplicit => ("[", "]")
| _ => ("(", ")")
end BinderInfo
namespace Name
/-! ### Declarations about `name` -/
/-- Find the largest prefix `n` of a `Name` such that `f n != none`, then replace this prefix
with the value of `f n`. -/
def mapPrefix (f : Name → Option Name) (n : Name) : Name := Id.run do
if let some n' := f n then return n'
match n with
| anonymous => anonymous
| str n' s => mkStr (mapPrefix f n') s
| num n' i => mkNum (mapPrefix f n') i
/-- Build a name from components. For example ``from_components [`foo, `bar]`` becomes
``` `foo.bar```.
It is the inverse of `Name.components` on list of names that have single components. -/
def fromComponents : List Name → Name := go .anonymous where
/-- Auxiliary for `Name.fromComponents` -/
go : Name → List Name → Name
| n, [] => n
| n, s :: rest => go (s.updatePrefix n) rest
/-- Update the last component of a name. -/
def updateLast (f : String → String) : Name → Name
| .str n s => .str n (f s)
| n => n
/-- Get the last field of a name as a string.
Doesn't raise an error when the last component is a numeric field. -/
def lastComponentAsString : Name → String
| .str _ s => s
| .num _ n => toString n
| .anonymous => ""
@[deprecated (since := "2024-05-14")] alias getString := lastComponentAsString
/-- `nm.splitAt n` splits a name `nm` in two parts, such that the *second* part has depth `n`, i.e.
`(nm.splitAt n).2.getNumParts = n` (assuming `nm.getNumParts ≥ n`).
Example: ``splitAt `foo.bar.baz.back.bat 1 = (`foo.bar.baz.back, `bat)``. -/
def splitAt (nm : Name) (n : Nat) : Name × Name :=
let (nm2, nm1) := nm.componentsRev.splitAt n
(.fromComponents <| nm1.reverse, .fromComponents <| nm2.reverse)
/-- `isPrefixOf? pre nm` returns `some post` if `nm = pre ++ post`.
Note that this includes the case where `nm` has multiple more namespaces.
If `pre` is not a prefix of `nm`, it returns `none`. -/
def isPrefixOf? (pre nm : Name) : Option Name :=
if pre == nm then
some anonymous
else match nm with
| anonymous => none
| num p' a => (isPrefixOf? pre p').map (·.num a)
| str p' s => (isPrefixOf? pre p').map (·.str s)
open Meta
-- from Lean.Server.Completion
def isBlackListed {m} [Monad m] [MonadEnv m] (declName : Name) : m Bool := do
if declName == ``sorryAx then return true
if declName matches .str _ "inj" then return true
if declName matches .str _ "noConfusionType" then return true
let env ← getEnv
pure <| declName.isInternalDetail
|| isAuxRecursor env declName
|| isNoConfusion env declName
<||> isRec declName <||> isMatcher declName
end Name
namespace ConstantInfo
/-- Checks whether this `ConstantInfo` is a definition, -/
def isDef : ConstantInfo → Bool
| defnInfo _ => true
| _ => false
/-- Checks whether this `ConstantInfo` is a theorem, -/
def isThm : ConstantInfo → Bool
| thmInfo _ => true
| _ => false
/-- Update `ConstantVal` (the data common to all constructors of `ConstantInfo`)
in a `ConstantInfo`. -/
def updateConstantVal : ConstantInfo → ConstantVal → ConstantInfo
| defnInfo info, v => defnInfo {info with toConstantVal := v}
| axiomInfo info, v => axiomInfo {info with toConstantVal := v}
| thmInfo info, v => thmInfo {info with toConstantVal := v}
| opaqueInfo info, v => opaqueInfo {info with toConstantVal := v}
| quotInfo info, v => quotInfo {info with toConstantVal := v}
| inductInfo info, v => inductInfo {info with toConstantVal := v}
| ctorInfo info, v => ctorInfo {info with toConstantVal := v}
| recInfo info, v => recInfo {info with toConstantVal := v}
/-- Update the name of a `ConstantInfo`. -/
def updateName (c : ConstantInfo) (name : Name) : ConstantInfo :=
c.updateConstantVal {c.toConstantVal with name}
/-- Update the type of a `ConstantInfo`. -/
def updateType (c : ConstantInfo) (type : Expr) : ConstantInfo :=
c.updateConstantVal {c.toConstantVal with type}
/-- Update the level parameters of a `ConstantInfo`. -/
def updateLevelParams (c : ConstantInfo) (levelParams : List Name) :
ConstantInfo :=
c.updateConstantVal {c.toConstantVal with levelParams}
/-- Update the value of a `ConstantInfo`, if it has one. -/
def updateValue : ConstantInfo → Expr → ConstantInfo
| defnInfo info, v => defnInfo {info with value := v}
| thmInfo info, v => thmInfo {info with value := v}
| opaqueInfo info, v => opaqueInfo {info with value := v}
| d, _ => d
/-- Turn a `ConstantInfo` into a declaration. -/
def toDeclaration! : ConstantInfo → Declaration
| defnInfo info => Declaration.defnDecl info
| thmInfo info => Declaration.thmDecl info
| axiomInfo info => Declaration.axiomDecl info
| opaqueInfo info => Declaration.opaqueDecl info
| quotInfo _ => panic! "toDeclaration for quotInfo not implemented"
| inductInfo _ => panic! "toDeclaration for inductInfo not implemented"
| ctorInfo _ => panic! "toDeclaration for ctorInfo not implemented"
| recInfo _ => panic! "toDeclaration for recInfo not implemented"
end ConstantInfo
open Meta
/-- Same as `mkConst`, but with fresh level metavariables. -/
def mkConst' (constName : Name) : MetaM Expr := do
return mkConst constName (← (← getConstInfo constName).levelParams.mapM fun _ => mkFreshLevelMVar)
namespace Expr
/-! ### Declarations about `Expr` -/
def bvarIdx? : Expr → Option Nat
| bvar idx => some idx
| _ => none
/-- Invariant: `i : ℕ` should be less than the size of `as : Array Expr`. -/
private def getAppAppsAux : Expr → Array Expr → Nat → Array Expr
| .app f a, as, i => getAppAppsAux f (as.set! i (.app f a)) (i-1)
| _, as, _ => as
/-- Given `f a b c`, return `#[f a, f a b, f a b c]`.
Each entry in the array is an `Expr.app`,
and this array has the same length as the one returned by `Lean.Expr.getAppArgs`. -/
@[inline]
def getAppApps (e : Expr) : Array Expr :=
let dummy := mkSort levelZero
let nargs := e.getAppNumArgs
getAppAppsAux e (mkArray nargs dummy) (nargs-1)
/-- Erase proofs in an expression by replacing them with `sorry`s.
This function replaces all proofs in the expression
and in the types that appear in the expression
by `sorryAx`s.
The resulting expression has the same type as the old one.
It is useful, e.g., to verify if the proof-irrelevant part of a definition depends on a variable.
-/
def eraseProofs (e : Expr) : MetaM Expr :=
Meta.transform (skipConstInApp := true) e
(pre := fun e => do
if (← Meta.isProof e) then
return .continue (← mkSyntheticSorry (← inferType e))
else
return .continue)
/--
Check if an expression is a "rational in normal form",
i.e. either an integer number in normal form,
or `n / d` where `n` is an integer in normal form, `d` is a natural number in normal form,
`d ≠ 1`, and `n` and `d` are coprime (in particular, we check that `(mkRat n d).den = d`).
If so returns the rational number.
-/
def rat? (e : Expr) : Option Rat := do
if e.isAppOfArity ``Div.div 4 then
let d ← e.appArg!.nat?
guard (d ≠ 1)
let n ← e.appFn!.appArg!.int?
let q := mkRat n d
guard (q.den = d)
pure q
else
e.int?
/--
Test if an expression represents an explicit number written in normal form:
* A "natural number in normal form" is an expression `OfNat.ofNat n`, even if it is not of type `ℕ`,
as long as `n` is a literal.
* An "integer in normal form" is an expression which is either a natural number in number form,
or `-n`, where `n` is a natural number in normal form.
* A "rational in normal form" is an expressions which is either an integer in normal form,
or `n / d` where `n` is an integer in normal form, `d` is a natural number in normal form,
`d ≠ 1`, and `n` and `d` are coprime (in particular, we check that `(mkRat n d).den = d`).
-/
def isExplicitNumber : Expr → Bool
| .lit _ => true
| .mdata _ e => isExplicitNumber e
| e => e.rat?.isSome
/-- If an `Expr` has form `.fvar n`, then returns `some n`, otherwise `none`. -/
def fvarId? : Expr → Option FVarId
| .fvar n => n
| _ => none
/-- If an `Expr` has the form `Type u`, then return `some u`, otherwise `none`. -/
def type? : Expr → Option Level
| .sort u => u.dec
| _ => none
/-- `isConstantApplication e` checks whether `e` is syntactically an application of the form
`(fun x₁ ⋯ xₙ => H) y₁ ⋯ yₙ` where `H` does not contain the variable `xₙ`. In other words,
it does a syntactic check that the expression does not depend on `yₙ`. -/
def isConstantApplication (e : Expr) :=
e.isApp && aux e.getAppNumArgs'.pred e.getAppFn' e.getAppNumArgs'
where
/-- `aux depth e n` checks whether the body of the `n`-th lambda of `e` has loose bvar
`depth - 1`. -/
aux (depth : Nat) : Expr → Nat → Bool
| .lam _ _ b _, n + 1 => aux depth b n
| e, 0 => !e.hasLooseBVar (depth - 1)
| _, _ => false
/-- Counts the immediate depth of a nested `let` expression. -/
def letDepth : Expr → Nat
| .letE _ _ _ b _ => b.letDepth + 1
| _ => 0
open Meta
/-- Check that an expression contains no metavariables (after instantiation). -/
-- There is a `TacticM` level version of this, but it's useful to have in `MetaM`.
def ensureHasNoMVars (e : Expr) : MetaM Unit := do
let e ← instantiateMVars e
if e.hasExprMVar then
throwError "tactic failed, resulting expression contains metavariables{indentExpr e}"
/-- Construct the term of type `α` for a given natural number
(doing typeclass search for the `OfNat` instance required). -/
def ofNat (α : Expr) (n : Nat) : MetaM Expr := do
mkAppOptM ``OfNat.ofNat #[α, mkRawNatLit n, none]
/-- Construct the term of type `α` for a given integer
(doing typeclass search for the `OfNat` and `Neg` instances required). -/
def ofInt (α : Expr) : Int → MetaM Expr
| Int.ofNat n => Expr.ofNat α n
| Int.negSucc n => do mkAppM ``Neg.neg #[← Expr.ofNat α (n+1)]
section recognizers
/--
Return `some n` if `e` is one of the following
- A nat literal (numeral)
- `Nat.zero`
- `Nat.succ x` where `isNumeral x`
- `OfNat.ofNat _ x _` where `isNumeral x` -/
partial def numeral? (e : Expr) : Option Nat :=
if let some n := e.rawNatLit? then n
else
let f := e.getAppFn
if !f.isConst then none
else
let fName := f.constName!
if fName == ``Nat.succ && e.getAppNumArgs == 1 then (numeral? e.appArg!).map Nat.succ
else if fName == ``OfNat.ofNat && e.getAppNumArgs == 3 then numeral? (e.getArg! 1)
else if fName == ``Nat.zero && e.getAppNumArgs == 0 then some 0
else none
/-- Test if an expression is either `Nat.zero`, or `OfNat.ofNat 0`. -/
def zero? (e : Expr) : Bool :=
match e.numeral? with
| some 0 => true
| _ => false
/-- Tests is if an expression matches either `x ≠ y` or `¬ (x = y)`.
If it matches, returns `some (type, x, y)`. -/
def ne?' (e : Expr) : Option (Expr × Expr × Expr) :=
e.ne? <|> (e.not? >>= Expr.eq?)
/-- `Lean.Expr.le? e` takes `e : Expr` as input.
If `e` represents `a ≤ b`, then it returns `some (t, a, b)`, where `t` is the Type of `a`,
otherwise, it returns `none`. -/
@[inline] def le? (p : Expr) : Option (Expr × Expr × Expr) := do
let (type, _, lhs, rhs) ← p.app4? ``LE.le
return (type, lhs, rhs)
/-- Given a proposition `ty` that is an `Eq`, `Iff`, or `HEq`, returns `(tyLhs, lhs, tyRhs, rhs)`,
where `lhs : tyLhs` and `rhs : tyRhs`,
and where `lhs` is related to `rhs` by the respective relation.
See also `Lean.Expr.iff?`, `Lean.Expr.eq?`, and `Lean.Expr.heq?`. -/
def sides? (ty : Expr) : Option (Expr × Expr × Expr × Expr) :=
if let some (lhs, rhs) := ty.iff? then
some (.sort .zero, lhs, .sort .zero, rhs)
else if let some (ty, lhs, rhs) := ty.eq? then
some (ty, lhs, ty, rhs)
else
ty.heq?
end recognizers
universe u
def modifyAppArgM {M : Type → Type u} [Functor M] [Pure M]
(modifier : Expr → M Expr) : Expr → M Expr
| app f a => mkApp f <$> modifier a
| e => pure e
def modifyRevArg (modifier : Expr → Expr) : Nat → Expr → Expr
| 0, (.app f x) => .app f (modifier x)
| (i+1), (.app f x) => .app (modifyRevArg modifier i f) x
| _, e => e
/-- Given `f a₀ a₁ ... aₙ₋₁`, runs `modifier` on the `i`th argument or
returns the original expression if out of bounds. -/
def modifyArg (modifier : Expr → Expr) (e : Expr) (i : Nat) (n := e.getAppNumArgs) : Expr :=
modifyRevArg modifier (n - i - 1) e
/-- Given `f a₀ a₁ ... aₙ₋₁`, sets the argument on the `i`th argument to `x` or
returns the original expression if out of bounds. -/
def setArg (e : Expr) (i : Nat) (x : Expr) (n := e.getAppNumArgs) : Expr :=
e.modifyArg (fun _ => x) i n
def getRevArg? : Expr → Nat → Option Expr
| app _ a, 0 => a
| app f _, i+1 => getRevArg! f i
| _, _ => none
/-- Given `f a₀ a₁ ... aₙ₋₁`, returns the `i`th argument or none if out of bounds. -/
def getArg? (e : Expr) (i : Nat) (n := e.getAppNumArgs) : Option Expr :=
getRevArg? e (n - i - 1)
/-- Given `f a₀ a₁ ... aₙ₋₁`, runs `modifier` on the `i`th argument.
An argument `n` may be provided which says how many arguments we are expecting `e` to have. -/
def modifyArgM {M : Type → Type u} [Monad M] (modifier : Expr → M Expr)
(e : Expr) (i : Nat) (n := e.getAppNumArgs) : M Expr := do
let some a := getArg? e i | return e
let a ← modifier a
return modifyArg (fun _ ↦ a) e i n
/-- Traverses an expression `e` and renames bound variables named `old` to `new`. -/
def renameBVar (e : Expr) (old new : Name) : Expr :=
match e with
| app fn arg => app (fn.renameBVar old new) (arg.renameBVar old new)
| lam n ty bd bi =>
lam (if n == old then new else n) (ty.renameBVar old new) (bd.renameBVar old new) bi
| forallE n ty bd bi =>
forallE (if n == old then new else n) (ty.renameBVar old new) (bd.renameBVar old new) bi
| e => e
open Lean.Meta in
/-- `getBinderName e` returns `some n` if `e` is an expression of the form `∀ n, ...`
and `none` otherwise. -/
def getBinderName (e : Expr) : MetaM (Option Name) := do
match ← withReducible (whnf e) with
| .forallE (binderName := n) .. | .lam (binderName := n) .. => pure (some n)
| _ => pure none
open Lean.Elab.Term
/-- Annotates a `binderIdent` with the binder information from an `fvar`. -/
def addLocalVarInfoForBinderIdent (fvar : Expr) (tk : TSyntax ``binderIdent) : MetaM Unit :=
-- the only TermElabM thing we do in `addLocalVarInfo` is check inPattern,
-- which we assume is always false for this function
discard <| TermElabM.run do
match tk with
| `(binderIdent| $n:ident) => Elab.Term.addLocalVarInfo n fvar
| tk => Elab.Term.addLocalVarInfo (Unhygienic.run `(_%$tk)) fvar
/-- If `e` has a structure as type with field `fieldName`, `mkDirectProjection e fieldName` creates
the projection expression `e.fieldName` -/
def mkDirectProjection (e : Expr) (fieldName : Name) : MetaM Expr := do
let type ← whnf (← inferType e)
let .const structName us := type.getAppFn | throwError "{e} doesn't have a structure as type"
let some projName := getProjFnForField? (← getEnv) structName fieldName |
throwError "{structName} doesn't have field {fieldName}"
return mkAppN (.const projName us) (type.getAppArgs.push e)
/-- If `e` has a structure as type with field `fieldName` (either directly or in a parent
structure), `mkProjection e fieldName` creates the projection expression `e.fieldName` -/
def mkProjection (e : Expr) (fieldName : Name) : MetaM Expr := do
let .const structName _ := (← whnf (← inferType e)).getAppFn |
throwError "{e} doesn't have a structure as type"
let some baseStruct := findField? (← getEnv) structName fieldName |
throwError "No parent of {structName} has field {fieldName}"
let mut e := e
for projName in (getPathToBaseStructure? (← getEnv) baseStruct structName).get! do
let type ← whnf (← inferType e)
let .const _structName us := type.getAppFn | throwError "{e} doesn't have a structure as type"
e := mkAppN (.const projName us) (type.getAppArgs.push e)
mkDirectProjection e fieldName
/-- If `e` is a projection of the structure constructor, reduce the projection.
Otherwise returns `none`. If this function detects that expression is ill-typed, throws an error.
For example, given `Prod.fst (x, y)`, returns `some x`. -/
def reduceProjStruct? (e : Expr) : MetaM (Option Expr) := do
let .const cname _ := e.getAppFn | return none
let some pinfo ← getProjectionFnInfo? cname | return none
let args := e.getAppArgs
if ha : args.size = pinfo.numParams + 1 then
-- The last argument of a projection is the structure.
let sarg := args[pinfo.numParams]'(ha ▸ pinfo.numParams.lt_succ_self)
-- Check that the structure is a constructor expression.
unless sarg.getAppFn.isConstOf pinfo.ctorName do
return none
let sfields := sarg.getAppArgs
-- The ith projection extracts the ith field of the constructor
let sidx := pinfo.numParams + pinfo.i
if hs : sidx < sfields.size then
return some (sfields[sidx]'hs)
else
throwError m!"ill-formed expression, {cname} is the {pinfo.i + 1}-th projection function \
but {sarg} does not have enough arguments"
else
return none
/-- Returns true if `e` contains a name `n` where `p n` is true. -/
def containsConst (e : Expr) (p : Name → Bool) : Bool :=
Option.isSome <| e.find? fun | .const n _ => p n | _ => false
/--
Rewrites `e` via some `eq`, producing a proof `e = e'` for some `e'`.
Rewrites with a fresh metavariable as the ambient goal.
Fails if the rewrite produces any subgoals.
-/
def rewrite (e eq : Expr) : MetaM Expr := do
let ⟨_, eq', []⟩ ← (← mkFreshExprMVar none).mvarId!.rewrite e eq
| throwError "Expr.rewrite may not produce subgoals."
return eq'
/--
Rewrites the type of `e` via some `eq`, then moves `e` into the new type via `Eq.mp`.
Rewrites with a fresh metavariable as the ambient goal.
Fails if the rewrite produces any subgoals.
-/
def rewriteType (e eq : Expr) : MetaM Expr := do
mkEqMP (← (← inferType e).rewrite eq) e
/-- Given `(hNotEx : Not ex)` where `ex` is of the form `Exists x, p x`,
return a `forall x, Not (p x)` and a proof for it.
This function handles nested existentials. -/
partial def forallNot_of_notExists (ex hNotEx : Expr) : MetaM (Expr × Expr) := do
let .app (.app (.const ``Exists [lvl]) A) p := ex | failure
go lvl A p hNotEx
where
/-- Given `(hNotEx : Not (@Exists.{lvl} A p))`,
return a `forall x, Not (p x)` and a proof for it.
This function handles nested existentials. -/
go (lvl : Level) (A p hNotEx : Expr) : MetaM (Expr × Expr) := do
let xn ← mkFreshUserName `x
withLocalDeclD xn A fun x => do
let px := p.beta #[x]
let notPx := mkNot px
let hAllNotPx := mkApp3 (.const ``forall_not_of_not_exists [lvl]) A p hNotEx
if let .app (.app (.const ``Exists [lvl']) A') p' := px then
let hNotPxN ← mkFreshUserName `h
withLocalDeclD hNotPxN notPx fun hNotPx => do
let (qx, hQx) ← go lvl' A' p' hNotPx
let allQx ← mkForallFVars #[x] qx
let hNotPxImpQx ← mkLambdaFVars #[hNotPx] hQx
let hAllQx ← mkLambdaFVars #[x] (.app hNotPxImpQx (.app hAllNotPx x))
return (allQx, hAllQx)
else
let allNotPx ← mkForallFVars #[x] notPx
return (allNotPx, hAllNotPx)
end Expr
/-- Get the projections that are projections to parent structures. Similar to `getParentStructures`,
except that this returns the (last component of the) projection names instead of the parent names.
-/
def getFieldsToParents (env : Environment) (structName : Name) : Array Name :=
getStructureFields env structName |>.filter fun fieldName =>
isSubobjectField? env structName fieldName |>.isSome
end Lean
|
Lean\Expr\ExtraRecognizers.lean | /-
Copyright (c) 2023 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Data.Set.Defs
/-!
# Additional Expr recognizers needing theory imports
-/
namespace Lean.Expr
/-- If `e` is a coercion of a set to a type, return the set.
Succeeds either for `Set.Elem s` terms or `{x // x ∈ s}` subtype terms. -/
def coeTypeSet? (e : Expr) : Option Expr := do
if e.isAppOfArity ``Set.Elem 2 then
return e.appArg!
else if e.isAppOfArity ``Subtype 2 then
let .lam _ _ body _ := e.appArg! | failure
guard <| body.isAppOfArity ``Membership.mem 5
let #[_, _, inst, .bvar 0, s] := body.getAppArgs | failure
guard <| inst.isAppOfArity ``Set.instMembership 1
return s
else
failure
end Lean.Expr
|
Lean\Expr\ReplaceRec.lean | /-
Copyright (c) 2019 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Simon Hudon, Scott Morrison, Keeley Hoek, Robert Y. Lewis,
Floris van Doorn, E.W.Ayers
-/
import Lean.Expr
import Mathlib.Util.MemoFix
/-!
# ReplaceRec
We define a more flexible version of `Expr.replace` where we can use recursive calls even when
replacing a subexpression. We completely mimic the implementation of `Expr.replace`.
-/
namespace Lean.Expr
/-- A version of `Expr.replace` where the replacement function is available to the function `f?`.
`replaceRec f? e` will call `f? r e` where `r = replaceRec f?`.
If `f? r e = none` then `r` will be called on each immediate subexpression of `e` and reassembled.
If it is `some x`, traversal terminates and `x` is returned.
If you wish to recursively replace things in the implementation of `f?`, you can apply `r`.
The function is also memoised, which means that if the
same expression (by reference) is encountered the cached replacement is used. -/
def replaceRec (f? : (Expr → Expr) → Expr → Option Expr) : Expr → Expr :=
memoFix fun r e ↦
match f? r e with
| some x => x
| none => traverseChildren (M := Id) r e
end Lean.Expr
|
Lean\Meta\Basic.lean | /-
Copyright (c) 2023 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Lean.Meta.AppBuilder
import Lean.Meta.Basic
/-!
# Additions to `Lean.Meta.Basic`
Likely these already exist somewhere. Pointers welcome.
-/
/--
Restore the metavariable context after execution.
-/
def Lean.Meta.preservingMCtx {α : Type} (x : MetaM α) : MetaM α := do
let mctx ← getMCtx
try x finally setMCtx mctx
open Lean Meta
/--
This function is similar to `forallMetaTelescopeReducing`: Given `e` of the
form `forall ..xs, A`, this combinator will create a new metavariable for
each `x` in `xs` until it reaches an `x` whose type is defeq to `t`,
and instantiate `A` with these, while also reducing `A` if needed.
It uses `forallMetaTelescopeReducing`.
This function returns a triple `(mvs, bis, out)` where
- `mvs` is an array containing the new metavariables.
- `bis` is an array containing the binder infos for the `mvs`.
- `out` is `e` but instantiated with the `mvs`.
-/
def Lean.Meta.forallMetaTelescopeReducingUntilDefEq
(e t : Expr) (kind : MetavarKind := MetavarKind.natural) :
MetaM (Array Expr × Array BinderInfo × Expr) := do
let (ms, bs, tp) ← forallMetaTelescopeReducing e (some 1) kind
unless ms.size == 1 do
if ms.size == 0 then throwError m!"Failed: {← ppExpr e} is not the type of a function."
else throwError m!"Failed"
let mut mvs := ms
let mut bis := bs
let mut out : Expr := tp
while !(← isDefEq (← inferType mvs.toList.getLast!) t) do
let (ms, bs, tp) ← forallMetaTelescopeReducing out (some 1) kind
unless ms.size == 1 do
throwError m!"Failed to find {← ppExpr t} as the type of a parameter of {← ppExpr e}."
mvs := mvs ++ ms
bis := bis ++ bs
out := tp
return (mvs, bis, out)
/-- `pureIsDefEq e₁ e₂` is short for `withNewMCtxDepth <| isDefEq e₁ e₂`.
Determines whether two expressions are definitionally equal to each other
when metavariables are not assignable. -/
@[inline]
def Lean.Meta.pureIsDefEq (e₁ e₂ : Expr) : MetaM Bool :=
withNewMCtxDepth <| isDefEq e₁ e₂
/-- `mkRel n lhs rhs` is `mkAppM n #[lhs, rhs]`, but with optimizations for `Eq` and `Iff`. -/
def Lean.Meta.mkRel (n : Name) (lhs rhs : Expr) : MetaM Expr :=
if n == ``Eq then
mkEq lhs rhs
else if n == ``Iff then
return mkApp2 (.const ``Iff []) lhs rhs
else
mkAppM n #[lhs, rhs]
|
Lean\Meta\CongrTheorems.lean | /-
Copyright (c) 2023 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Lean.Meta.Tactic.Cleanup
import Lean.Meta.Tactic.Cases
import Lean.Meta.Tactic.Refl
import Mathlib.Logic.IsEmpty
/-!
# Additions to `Lean.Meta.CongrTheorems`
-/
namespace Lean.Meta
initialize registerTraceClass `Meta.CongrTheorems
/-- Generates a congruence lemma for a function `f` for `numArgs` of its arguments.
The only `Lean.Meta.CongrArgKind` kinds that appear in such a lemma
are `.eq`, `.heq`, and `.subsingletonInst`.
The resulting lemma proves either an `Eq` or a `HEq` depending on whether the types
of the LHS and RHS are equal or not.
This function is a wrapper around `Lean.Meta.mkHCongrWithArity`.
It transforms the resulting congruence lemma by trying to automatically prove hypotheses
using subsingleton lemmas, and if they are so provable they are recorded with `.subsingletonInst`.
Note that this is slightly abusing `.subsingletonInst` since
(1) the argument might not be for a `Decidable` instance and
(2) the argument might not even be an instance. -/
def mkHCongrWithArity' (f : Expr) (numArgs : Nat) : MetaM CongrTheorem := do
let thm ← mkHCongrWithArity f numArgs
process thm thm.type thm.argKinds.toList #[] #[] #[] #[]
where
/--
Process the congruence theorem by trying to pre-prove arguments using `prove`.
- `cthm` is the original `CongrTheorem`, modified only after visiting every argument.
- `type` is type of the congruence theorem, after all the parameters so far have been applied.
- `argKinds` is the list of `CongrArgKind`s, which this function recurses on.
- `argKinds'` is the accumulated array of `CongrArgKind`s, which is the original array but
with some kinds replaced by `.subsingletonInst`.
- `params` is the *new* list of parameters, as fvars that need to be abstracted at the end.
- `args` is the list of arguments (fvars) to supply to `cthm.proof` before abstracting `params`.
- `letArgs` records `(fvar, expr)` assignments for each `fvar` that was solved for by `prove`.
-/
process (cthm : CongrTheorem) (type : Expr) (argKinds : List CongrArgKind)
(argKinds' : Array CongrArgKind) (params args : Array Expr)
(letArgs : Array (Expr × Expr)) : MetaM CongrTheorem := do
match argKinds with
| [] =>
if letArgs.isEmpty then
-- Then we didn't prove anything, so we can use the CongrTheorem as-is.
return cthm
else
let proof := letArgs.foldr (init := mkAppN cthm.proof args) (fun (fvar, val) proof =>
(proof.abstract #[fvar]).instantiate1 val)
let pf' ← mkLambdaFVars params proof
return {proof := pf', type := ← inferType pf', argKinds := argKinds'}
| argKind :: argKinds =>
match argKind with
| .eq | .heq =>
forallBoundedTelescope type (some 3) fun params' type' => do
let #[x, y, eq] := params' | unreachable!
-- See if we can prove `Eq` from previous parameters.
let g := (← mkFreshExprMVar (← inferType eq)).mvarId!
let g ← g.clear eq.fvarId!
if (← observing? <| prove g args).isSome then
let eqPf ← instantiateMVars (.mvar g)
process cthm type' argKinds (argKinds'.push .subsingletonInst)
(params := params ++ #[x, y]) (args := args ++ params')
(letArgs := letArgs.push (eq, eqPf))
else
process cthm type' argKinds (argKinds'.push argKind)
(params := params ++ params') (args := args ++ params')
(letArgs := letArgs)
| _ => panic! "Unexpected CongrArgKind"
/-- Close the goal given only the fvars in `params`, or else fails. -/
prove (g : MVarId) (params : Array Expr) : MetaM Unit := do
-- Prune the local context.
let g ← g.cleanup
-- Substitute equalities that come from only this congruence lemma.
let [g] ← g.casesRec fun localDecl => do
return (localDecl.type.isEq || localDecl.type.isHEq) && params.contains localDecl.toExpr
| failure
try g.refl; return catch _ => pure ()
try g.hrefl; return catch _ => pure ()
if ← g.proofIrrelHeq then return
-- Make the goal be an eq and then try `Subsingleton.elim`
let g ← g.heqOfEq
if ← g.subsingletonElim then return
-- We have no more tricks.
failure
universe u v
/-- A version of `Subsingleton` with few instances. It should fail fast. -/
class FastSubsingleton (α : Sort u) : Prop where
/-- The subsingleton instance. -/
[inst : Subsingleton α]
/-- A version of `IsEmpty` with few instances. It should fail fast. -/
class FastIsEmpty (α : Sort u) : Prop where
[inst : IsEmpty α]
protected theorem FastSubsingleton.elim {α : Sort u} [h : FastSubsingleton α] : (a b : α) → a = b :=
h.inst.allEq
instance (priority := 100) {α : Type u} [inst : FastIsEmpty α] : FastSubsingleton α where
inst := have := inst.inst; inferInstance
instance {p : Prop} : FastSubsingleton p := {}
instance {p : Prop} : FastSubsingleton (Decidable p) := {}
instance : FastSubsingleton (Fin 1) := {}
instance : FastSubsingleton PUnit := {}
instance : FastIsEmpty Empty := {}
instance : FastIsEmpty False := {}
instance : FastIsEmpty (Fin 0) := {}
instance {α : Sort u} [inst : FastIsEmpty α] {β : (x : α) → Sort v} :
FastSubsingleton ((x : α) → β x) where
inst.allEq _ _ := funext fun a => (inst.inst.false a).elim
instance {α : Sort u} {β : (x : α) → Sort v} [inst : ∀ x, FastSubsingleton (β x)] :
FastSubsingleton ((x : α) → β x) where
inst := have := λ x => (inst x).inst; inferInstance
/--
Runs `mx` in a context where all local `Subsingleton` and `IsEmpty` instances
have associated `FastSubsingleton` and `FastIsEmpty` instances.
The function passed to `mx` eliminates these instances from expressions,
since they are only locally valid inside this context.
-/
def withSubsingletonAsFast {α : Type} [Inhabited α] (mx : (Expr → Expr) → MetaM α) : MetaM α := do
let insts1 := (← getLocalInstances).filter fun inst => inst.className == ``Subsingleton
let insts2 := (← getLocalInstances).filter fun inst => inst.className == ``IsEmpty
let mkInst (f : Name) (inst : Expr) : MetaM Expr := do
forallTelescopeReducing (← inferType inst) fun args _ => do
mkLambdaFVars args <| ← mkAppOptM f #[none, mkAppN inst args]
let vals := (← insts1.mapM fun inst => mkInst ``FastSubsingleton.mk inst.fvar)
++ (← insts2.mapM fun inst => mkInst ``FastIsEmpty.mk inst.fvar)
let tys ← vals.mapM inferType
withLocalDeclsD (tys.map fun ty => (`inst, fun _ => pure ty)) fun args =>
withNewLocalInstances args 0 do
let elim (e : Expr) : Expr := e.replaceFVars args vals
mx elim
/-- Like `subsingletonElim` but uses `FastSubsingleton` to fail fast. -/
def fastSubsingletonElim (mvarId : MVarId) : MetaM Bool :=
mvarId.withContext do
let res ← observing? do
mvarId.checkNotAssigned `fastSubsingletonElim
let tgt ← withReducible mvarId.getType'
let some (_, lhs, rhs) := tgt.eq? | failure
-- Note: `mkAppM` uses `withNewMCtxDepth`, which prevents `Sort _` from specializing to `Prop`
let pf ← withSubsingletonAsFast fun elim =>
elim <$> mkAppM ``FastSubsingleton.elim #[lhs, rhs]
mvarId.assign pf
return true
return res.getD false
/--
`mkRichHCongr fType funInfo fixedFun fixedParams forceHEq`
create a congruence lemma to prove that `Eq/HEq (f a₁ ... aₙ) (f' a₁' ... aₙ')`.
The functions have type `fType` and the number of arguments is governed by the `funInfo` data.
Each argument produces an `Eq/HEq aᵢ aᵢ'` hypothesis, but we also provide these hypotheses
the additional facts that the preceding equalities have been proved (unlike in `mkHCongrWithArity`).
The first two arguments of the resulting theorem are for `f` and `f'`, followed by a proof
of `f = f'`, unless `fixedFun` is `true` (see below).
When including hypotheses about previous hypotheses, we make use of dependency information
and only include relevant equalities.
The argument `fty` denotes the type of `f`. The arity of the resulting congruence lemma is
controlled by the size of the `info` array.
For the purpose of generating nicer lemmas (to help `to_additive` for example),
this function supports generating lemmas where certain parameters
are meant to be fixed:
* If `fixedFun` is `false` (the default) then the lemma starts with three arguments for `f`, `f'`,
and `h : f = f'`. Otherwise, if `fixedFun` is `true` then the lemma starts with just `f`.
* If the `fixedParams` argument has `true` for a particular argument index, then this is a hint
that the congruence lemma may use the same parameter for both sides of the equality. There is
no guarantee -- it respects it if the types are equal for that parameter (i.e., if the parameter
does not depend on non-fixed parameters).
If `forceHEq` is `true` then the conclusion of the generated theorem is a `HEq`.
Otherwise it might be an `Eq` if the equality is homogeneous.
This is the interpretation of the `CongrArgKind`s in the generated congruence theorem:
* `.eq` corresponds to having three arguments `(x : α) (x' : α) (h : x = x')`.
Note that `h` might have additional hypotheses.
* `.heq` corresponds to having three arguments `(x : α) (x' : α') (h : HEq x x')`
Note that `h` might have additional hypotheses.
* `.fixed` corresponds to having a single argument `(x : α)` that is fixed between the LHS and RHS
* `.subsingletonInst` corresponds to having two arguments `(x : α) (x' : α')` for which the
congruence generator was able to prove that `HEq x x'` already. This is a slight abuse of
this `CongrArgKind` since this is used even for types that are not subsingleton typeclasses.
Note that the first entry in this array is for the function itself.
-/
partial def mkRichHCongr (fType : Expr) (info : FunInfo)
(fixedFun : Bool := false) (fixedParams : Array Bool := #[])
(forceHEq : Bool := false) :
MetaM CongrTheorem := do
trace[Meta.CongrTheorems] "ftype: {fType}"
trace[Meta.CongrTheorems] "deps: {info.paramInfo.map (fun p => p.backDeps)}"
trace[Meta.CongrTheorems] "fixedFun={fixedFun}, fixedParams={fixedParams}"
doubleTelescope fType info.getArity fixedParams fun xs ys fixedParams => do
trace[Meta.CongrTheorems] "xs = {xs}"
trace[Meta.CongrTheorems] "ys = {ys}"
trace[Meta.CongrTheorems] "computed fixedParams={fixedParams}"
let lctx := (← getLCtx) -- checkpoint for a local context that only has the parameters
withLocalDeclD `f fType fun ef => withLocalDeclD `f' fType fun pef' => do
let ef' := if fixedFun then ef else pef'
withLocalDeclD `e (← mkEq ef ef') fun ee => do
withNewEqs xs ys fixedParams fun kinds eqs => do
let fParams := if fixedFun then #[ef] else #[ef, ef', ee]
let mut hs := fParams -- parameters to the basic congruence lemma
let mut hs' := fParams -- parameters to the richer congruence lemma
let mut vals' := fParams -- how to calculate the basic parameters from the richer ones
for i in [0 : info.getArity] do
hs := hs.push xs[i]!
hs' := hs'.push xs[i]!
vals' := vals'.push xs[i]!
if let some (eq, eq', val) := eqs[i]! then
-- Not a fixed argument
hs := hs.push ys[i]! |>.push eq
hs' := hs'.push ys[i]! |>.push eq'
vals' := vals'.push ys[i]! |>.push val
-- Generate the theorem with respect to the simpler hypotheses
let mkConcl := if forceHEq then mkHEq else mkEqHEq
let congrType ← mkForallFVars hs (← mkConcl (mkAppN ef xs) (mkAppN ef' ys))
trace[Meta.CongrTheorems] "simple congrType: {congrType}"
let some proof ← withLCtx lctx (← getLocalInstances) <| trySolve congrType
| throwError "Internal error when constructing congruence lemma proof"
-- At this point, `mkLambdaFVars hs' (mkAppN proof vals')` is the richer proof.
-- We try to precompute some of the arguments using `trySolve`.
let mut hs'' := #[] -- eq' parameters that are actually used beyond those in `fParams`
let mut pfVars := #[] -- eq' parameters that can be solved for already
let mut pfVals := #[] -- the values to use for these parameters
let mut kinds' : Array CongrArgKind := #[if fixedFun then .fixed else .eq]
for i in [0 : info.getArity] do
hs'' := hs''.push xs[i]!
if let some (_, eq', _) := eqs[i]! then
-- Not a fixed argument
hs'' := hs''.push ys[i]!
let pf? ← withLCtx lctx (← getLocalInstances) <| trySolve (← inferType eq')
if let some pf := pf? then
pfVars := pfVars.push eq'
pfVals := pfVals.push pf
kinds' := kinds'.push .subsingletonInst
else
hs'' := hs''.push eq'
kinds' := kinds'.push kinds[i]!
else
kinds' := kinds'.push .fixed
trace[Meta.CongrTheorems] "CongrArgKinds: {repr kinds'}"
-- Take `proof`, abstract the pfVars and provide the solved-for proofs (as an
-- optimization for proof term size) then abstract the remaining variables.
-- The `usedOnly` probably has no affect.
-- Note that since we are doing `proof.beta vals'` there is technically some quadratic
-- complexity, but it shouldn't be too bad since they're some applications of just variables.
let proof' ← mkLambdaFVars fParams (← mkLambdaFVars (usedOnly := true) hs''
(mkAppN (← mkLambdaFVars pfVars (proof.beta vals')) pfVals))
let congrType' ← inferType proof'
trace[Meta.CongrTheorems] "rich congrType: {congrType'}"
return {proof := proof', type := congrType', argKinds := kinds'}
where
/-- Similar to doing `forallBoundedTelescope` twice, but makes use of the `fixed` array, which
is used as a hint for whether both variables should be the same. This is only a hint though,
since we respect it only if the binding domains are equal.
We affix `'` to the second list of variables, and all the variables are introduced
with default binder info. Calls `k` with the xs, ys, and a revised `fixed` array -/
doubleTelescope {α} (fty : Expr) (numVars : Nat) (fixed : Array Bool)
(k : Array Expr → Array Expr → Array Bool → MetaM α) : MetaM α := do
let rec loop (i : Nat)
(ftyx ftyy : Expr) (xs ys : Array Expr) (fixed' : Array Bool) : MetaM α := do
if i < numVars then
let ftyx ← whnf ftyx
let ftyy ← whnf ftyy
unless ftyx.isForall do
throwError "doubleTelescope: function doesn't have enough parameters"
withLocalDeclD ftyx.bindingName! ftyx.bindingDomain! fun fvarx => do
let ftyx' := ftyx.bindingBody!.instantiate1 fvarx
if fixed.getD i false && ftyx.bindingDomain! == ftyy.bindingDomain! then
-- Fixed: use the same variable for both
let ftyy' := ftyy.bindingBody!.instantiate1 fvarx
loop (i + 1) ftyx' ftyy' (xs.push fvarx) (ys.push fvarx) (fixed'.push true)
else
-- Not fixed: use different variables
let yname := ftyy.bindingName!.appendAfter "'"
withLocalDeclD yname ftyy.bindingDomain! fun fvary => do
let ftyy' := ftyy.bindingBody!.instantiate1 fvary
loop (i + 1) ftyx' ftyy' (xs.push fvarx) (ys.push fvary) (fixed'.push false)
else
k xs ys fixed'
loop 0 fty fty #[] #[] #[]
/-- Introduce variables for equalities between the arrays of variables. Uses `fixedParams`
to control whether to introduce an equality for each pair. The array of triples passed to `k`
consists of (1) the simple congr lemma HEq arg, (2) the richer HEq arg, and (3) how to
compute 1 in terms of 2. -/
withNewEqs {α} (xs ys : Array Expr) (fixedParams : Array Bool)
(k : Array CongrArgKind → Array (Option (Expr × Expr × Expr)) → MetaM α) : MetaM α :=
let rec loop (i : Nat)
(kinds : Array CongrArgKind) (eqs : Array (Option (Expr × Expr × Expr))) := do
if i < xs.size then
let x := xs[i]!
let y := ys[i]!
if fixedParams[i]! then
loop (i+1) (kinds.push .fixed) (eqs.push none)
else
let deps := info.paramInfo[i]!.backDeps.filterMap (fun j => eqs[j]!)
let eq' ← mkForallFVars (deps.map fun (eq, _, _) => eq) (← mkEqHEq x y)
withLocalDeclD ((`e).appendIndexAfter (i+1)) (← mkEqHEq x y) fun h =>
withLocalDeclD ((`e').appendIndexAfter (i+1)) eq' fun h' => do
let v := mkAppN h' (deps.map fun (_, _, val) => val)
let kind := if (← inferType h).eq?.isSome then .eq else .heq
loop (i+1) (kinds.push kind) (eqs.push (h, h', v))
else
k kinds eqs
loop 0 #[] #[]
/-- Given a type that is a bunch of equalities implying a goal (for example, a basic
congruence lemma), prove it if possible. Basic congruence lemmas should be provable by this.
There are some extra tricks for handling arguments to richer congruence lemmas. -/
trySolveCore (mvarId : MVarId) : MetaM Unit := do
-- First cleanup the context since we're going to do `substEqs` and we don't want to
-- accidentally use variables not actually used by the theorem.
let mvarId ← mvarId.cleanup
let (_, mvarId) ← mvarId.intros
let mvarId := (← mvarId.substEqs).getD mvarId
try mvarId.refl; return catch _ => pure ()
try mvarId.hrefl; return catch _ => pure ()
if ← mvarId.proofIrrelHeq then return
-- Make the goal be an eq and then try `Subsingleton.elim`
let mvarId ← mvarId.heqOfEq
if ← fastSubsingletonElim mvarId then return
-- We have no more tricks.
throwError "was not able to solve for proof"
/-- Driver for `trySolveCore`. -/
trySolve (ty : Expr) : MetaM (Option Expr) := observing? do
let mvar ← mkFreshExprMVar ty
trace[Meta.CongrTheorems] "trySolve {mvar.mvarId!}"
-- The proofs we generate shouldn't require unfolding anything.
withReducible <| trySolveCore mvar.mvarId!
trace[Meta.CongrTheorems] "trySolve success!"
let pf ← instantiateMVars mvar
return pf
end Lean.Meta
|
Lean\Meta\DiscrTree.lean | /-
Copyright (c) 2023 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Lean.Meta.DiscrTree
/-!
# Additions to `Lean.Meta.DiscrTree`
-/
namespace Lean.Meta.DiscrTree
/--
Find keys which match the expression, or some subexpression.
Note that repeated subexpressions will be visited each time they appear,
making this operation potentially very expensive.
It would be good to solve this problem!
Implementation: we reverse the results from `getMatch`,
so that we return lemmas matching larger subexpressions first,
and amongst those we return more specific lemmas first.
-/
partial def getSubexpressionMatches {α : Type}
(d : DiscrTree α) (e : Expr) (config : WhnfCoreConfig) : MetaM (Array α) := do
match e with
| .bvar _ => return #[]
| .forallE _ _ _ _ => forallTelescope e (fun args body => do
args.foldlM (fun acc arg => do
pure <| acc ++ (← d.getSubexpressionMatches (← inferType arg) config))
(← d.getSubexpressionMatches body config).reverse)
| .lam _ _ _ _
| .letE _ _ _ _ _ => lambdaLetTelescope e (fun args body => do
args.foldlM (fun acc arg => do
pure <| acc ++ (← d.getSubexpressionMatches (← inferType arg) config))
(← d.getSubexpressionMatches body config).reverse)
| _ =>
e.foldlM (fun a f => do
pure <| a ++ (← d.getSubexpressionMatches f config)) (← d.getMatch e config).reverse
/--
Check if a `keys : Array DiscTree.Key` is "specific",
i.e. something other than `[*]` or `[=, *, *, *]`.
-/
def keysSpecific (keys : Array DiscrTree.Key) : Bool :=
keys != #[Key.star] && keys != #[Key.const `Eq 3, Key.star, Key.star, Key.star]
end Lean.Meta.DiscrTree
|
Lean\Meta\KAbstractPositions.lean | /-
Copyright (c) 2023 Jovan Gerbscheid. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jovan Gerbscheid
-/
import Lean.HeadIndex
import Lean.Meta.ExprLens
import Lean.Meta.Check
/-!
# Find the positions of a pattern in an expression
This file defines some tools for dealing with sub expressions and occurrence numbers.
This is used for creating a `rw` tactic call that rewrites a selected expression.
`viewKAbstractSubExpr` takes an expression and a position in the expression, and returns
the sub-expression together with an optional occurrence number that would be required to find
the sub-expression using `kabstract` (which is what `rw` uses to find the position of the rewrite)
`rw` can fail if the motive is not type correct. `kabstractIsTypeCorrect` checks
whether this is the case.
-/
namespace Lean.Meta
/-- Return the positions that `kabstract` would abstract for pattern `p` in expression `e`.
i.e. the positions that unify with `p`. -/
def kabstractPositions (p e : Expr) : MetaM (Array SubExpr.Pos) := do
let e ← instantiateMVars e
let mctx ← getMCtx
let pHeadIdx := p.toHeadIndex
let pNumArgs := p.headNumArgs
let rec
/-- The main loop that loops through all subexpressions -/
visit (e : Expr) (pos : SubExpr.Pos) (positions : Array SubExpr.Pos) :
MetaM (Array SubExpr.Pos) := do
let visitChildren : Array SubExpr.Pos → MetaM (Array SubExpr.Pos) :=
match e with
| .app fn arg => visit fn pos.pushAppFn
>=> visit arg pos.pushAppArg
| .mdata _ expr => visit expr pos
| .proj _ _ struct => visit struct pos.pushProj
| .letE _ type value body _ => visit type pos.pushLetVarType
>=> visit value pos.pushLetValue
>=> visit body pos.pushLetBody
| .lam _ binderType body _ => visit binderType pos.pushBindingDomain
>=> visit body pos.pushBindingBody
| .forallE _ binderType body _ => visit binderType pos.pushBindingDomain
>=> visit body pos.pushBindingBody
| _ => pure
if e.hasLooseBVars then
visitChildren positions
else if e.toHeadIndex != pHeadIdx || e.headNumArgs != pNumArgs then
visitChildren positions
else
if ← isDefEq e p then
setMCtx mctx -- reset the `MetavarContext` because `isDefEq` can modify it if it succeeds
visitChildren (positions.push pos)
else
visitChildren positions
visit e .root #[]
/-- Return the subexpression at position `pos` in `e` together with an occurrence number
that allows the expression to be found by `kabstract`.
Return `none` when the subexpression contains loose bound variables. -/
def viewKAbstractSubExpr (e : Expr) (pos : SubExpr.Pos) : MetaM (Option (Expr × Option Nat)) := do
let subExpr ← Core.viewSubexpr pos e
if subExpr.hasLooseBVars then
return none
let positions ← kabstractPositions subExpr e
let some n := positions.getIdx? pos | unreachable!
return some (subExpr, if positions.size == 1 then none else some (n + 1))
/-- Determine whether the result of abstracting `subExpr` from `e` at position `pos` results
in a well typed expression. This is important if you want to rewrite at this position.
Here is an example of what goes wrong with an ill-typed kabstract result:
```
example (h : [5] ≠ []) : List.getLast [5] h = 5 := by
rw [show [5] = [5] from rfl] -- tactic 'rewrite' failed, motive is not type correct
```
-/
def kabstractIsTypeCorrect (e subExpr : Expr) (pos : SubExpr.Pos) : MetaM Bool := do
withLocalDeclD `_a (← inferType subExpr) fun fvar => do
isTypeCorrect (← replaceSubexpr (fun _ => pure fvar) pos e)
|
Lean\Meta\Simp.lean | /-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Gabriel Ebner, Floris van Doorn
-/
import Lean.Elab.Tactic.Simp
/-!
# Helper functions for using the simplifier.
[TODO] Needs documentation, cleanup, and possibly reunification of `mkSimpContext'` with core.
-/
open Lean Elab.Tactic
def Lean.PHashSet.toList.{u} {α : Type u} [BEq α] [Hashable α] (s : Lean.PHashSet α) : List α :=
s.1.toList.map (·.1)
namespace Lean
namespace Meta.Simp
open Elab.Tactic
instance : ToFormat SimpTheorems where
format s :=
f!"pre:
{s.pre.values.toList}
post:
{s.post.values.toList}
lemmaNames:
{s.lemmaNames.toList.map (·.key)}
toUnfold: {s.toUnfold.toList}
erased: {s.erased.toList.map (·.key)}
toUnfoldThms: {s.toUnfoldThms.toList}"
/--
Constructs a proof that the original expression is true
given a simp result which simplifies the target to `True`.
-/
def Result.ofTrue (r : Simp.Result) : MetaM (Option Expr) :=
if r.expr.isConstOf ``True then
some <$> match r.proof? with
| some proof => mkOfEqTrue proof
| none => pure (mkConst ``True.intro)
else
pure none
/-- Return all propositions in the local context. -/
def getPropHyps : MetaM (Array FVarId) := do
let mut result := #[]
for localDecl in (← getLCtx) do
unless localDecl.isAuxDecl do
if (← isProp localDecl.type) then
result := result.push localDecl.fvarId
return result
end Simp
/-- Construct a `SimpTheorems` from a list of names. -/
def simpTheoremsOfNames (lemmas : List Name := []) (simpOnly : Bool := false) :
MetaM SimpTheorems := do
lemmas.foldlM (·.addConst ·)
(← if simpOnly then
simpOnlyBuiltins.foldlM (·.addConst ·) {}
else
getSimpTheorems)
-- TODO We need to write a `mkSimpContext` in `MetaM`
-- that supports all the bells and whistles in `simp`.
-- It should generalize this, and another partial implementation in `Tactic.Simps.Basic`.
/-- Construct a `Simp.Context` from a list of names. -/
def Simp.Context.ofNames (lemmas : List Name := []) (simpOnly : Bool := false)
(config : Simp.Config := {}) : MetaM Simp.Context := do pure <|
{ simpTheorems := #[← simpTheoremsOfNames lemmas simpOnly],
congrTheorems := ← Lean.Meta.getSimpCongrTheorems,
config := config }
/-- Simplify an expression using only a list of lemmas specified by name. -/
def simpOnlyNames (lemmas : List Name) (e : Expr) (config : Simp.Config := {}) :
MetaM Simp.Result := do
(·.1) <$> simp e (← Simp.Context.ofNames lemmas true config)
/--
Given a simplifier `S : Expr → MetaM Simp.Result`,
and an expression `e : Expr`, run `S` on the type of `e`, and then
convert `e` into that simplified type,
using a combination of type hints as well as casting if the proof is not definitional `Eq.mp`.
The optional argument `type?`, if present, must be definitionally equal to the type of `e`.
When it is specified we simplify this type rather than the inferred type of `e`.
-/
def simpType (S : Expr → MetaM Simp.Result) (e : Expr) (type? : Option Expr := none) :
MetaM Expr := do
let type ← type?.getDM (inferType e)
match ← S type with
| ⟨ty', none, _⟩ => mkExpectedTypeHint e ty'
-- We use `mkExpectedTypeHint` in this branch as well, in order to preserve the binder types.
| ⟨ty', some prf, _⟩ => mkExpectedTypeHint (← mkEqMP prf e) ty'
/-- Independently simplify both the left-hand side and the right-hand side
of an equality. The equality is allowed to be under binders.
Returns the simplified equality and a proof of it. -/
def simpEq (S : Expr → MetaM Simp.Result) (type pf : Expr) : MetaM (Expr × Expr) := do
forallTelescope type fun fvars type => do
let .app (.app (.app (.const `Eq [u]) α) lhs) rhs := type | throwError "simpEq expecting Eq"
let ⟨lhs', lhspf?, _⟩ ← S lhs
let ⟨rhs', rhspf?, _⟩ ← S rhs
let mut pf' := mkAppN pf fvars
if let some lhspf := lhspf? then
pf' ← mkEqTrans (← mkEqSymm lhspf) pf'
if let some rhspf := rhspf? then
pf' ← mkEqTrans pf' rhspf
let type' := mkApp3 (mkConst ``Eq [u]) α lhs' rhs'
return (← mkForallFVars fvars type', ← mkLambdaFVars fvars pf')
/-- Checks whether `declName` is in `SimpTheorems` as either a lemma or definition to unfold. -/
def SimpTheorems.contains (d : SimpTheorems) (declName : Name) :=
d.isLemma (.decl declName) || d.isDeclToUnfold declName
/-- Tests whether `decl` has `simp`-attribute `simpAttr`. Returns `false` is `simpAttr` is not a
valid simp-attribute. -/
def isInSimpSet (simpAttr decl : Name) : CoreM Bool := do
let .some simpDecl ← getSimpExtension? simpAttr | return false
return (← simpDecl.getTheorems).contains decl
/-- Returns all declarations with the `simp`-attribute `simpAttr`.
Note: this also returns many auxiliary declarations. -/
def getAllSimpDecls (simpAttr : Name) : CoreM (List Name) := do
let .some simpDecl ← getSimpExtension? simpAttr | return []
let thms ← simpDecl.getTheorems
return thms.toUnfold.toList ++ thms.lemmaNames.toList.filterMap fun
| .decl decl => some decl
| _ => none
/-- Gets all simp-attributes given to declaration `decl`. -/
def getAllSimpAttrs (decl : Name) : CoreM (Array Name) := do
let mut simpAttrs := #[]
for (simpAttr, simpDecl) in (← simpExtensionMapRef.get).toList do
if (← simpDecl.getTheorems).contains decl then
simpAttrs := simpAttrs.push simpAttr
return simpAttrs
end Lean.Meta
|
Lean\PrettyPrinter\Delaborator.lean | /-
Copyright (c) 2023 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Lean.PrettyPrinter.Delaborator.Basic
/-!
# Additions to the delaborator
-/
namespace Lean.PrettyPrinter.Delaborator
open Lean.Meta Lean.SubExpr SubExpr
namespace SubExpr
variable {α : Type} [Inhabited α]
variable {m : Type → Type} [Monad m]
end SubExpr
/-- Assuming the current expression in a lambda or pi,
descend into the body using an unused name generated from the binder's name.
Provides `d` with both `Syntax` for the bound name as an identifier
as well as the fresh fvar for the bound variable.
See also `Lean.PrettyPrinter.Delaborator.withBindingBodyUnusedName`. -/
def withBindingBodyUnusedName' {α} (d : Syntax → Expr → DelabM α) : DelabM α := do
let n ← getUnusedName (← getExpr).bindingName! (← getExpr).bindingBody!
withBindingBody' n (fun fvar => return (← mkAnnotatedIdent n fvar, fvar))
(fun (stxN, fvar) => d stxN fvar)
/-- Update `OptionsPerPos` at the given position, setting the key `n`
to have the boolean value `v`. -/
def OptionsPerPos.setBool (opts : OptionsPerPos) (p : SubExpr.Pos) (n : Name) (v : Bool) :
OptionsPerPos :=
let e := opts.findD p {} |>.setBool n v
opts.insert p e
|
LinearAlgebra\AnnihilatingPolynomial.lean | /-
Copyright (c) 2022 Justin Thomas. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Justin Thomas
-/
import Mathlib.FieldTheory.Minpoly.Field
import Mathlib.RingTheory.PrincipalIdealDomain
import Mathlib.Algebra.Polynomial.Module.AEval
/-!
# Annihilating Ideal
Given a commutative ring `R` and an `R`-algebra `A`
Every element `a : A` defines
an ideal `Polynomial.annIdeal a ⊆ R[X]`.
Simply put, this is the set of polynomials `p` where
the polynomial evaluation `p(a)` is 0.
## Special case where the ground ring is a field
In the special case that `R` is a field, we use the notation `R = 𝕜`.
Here `𝕜[X]` is a PID, so there is a polynomial `g ∈ Polynomial.annIdeal a`
which generates the ideal. We show that if this generator is
chosen to be monic, then it is the minimal polynomial of `a`,
as defined in `FieldTheory.Minpoly`.
## Special case: endomorphism algebra
Given an `R`-module `M` (`[AddCommGroup M] [Module R M]`)
there are some common specializations which may be more familiar.
* Example 1: `A = M →ₗ[R] M`, the endomorphism algebra of an `R`-module M.
* Example 2: `A = n × n` matrices with entries in `R`.
-/
open Polynomial
namespace Polynomial
section Semiring
variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]
variable (R)
/-- `annIdeal R a` is the *annihilating ideal* of all `p : R[X]` such that `p(a) = 0`.
The informal notation `p(a)` stand for `Polynomial.aeval a p`.
Again informally, the annihilating ideal of `a` is
`{ p ∈ R[X] | p(a) = 0 }`. This is an ideal in `R[X]`.
The formal definition uses the kernel of the aeval map. -/
noncomputable def annIdeal (a : A) : Ideal R[X] :=
RingHom.ker ((aeval a).toRingHom : R[X] →+* A)
variable {R}
/-- It is useful to refer to ideal membership sometimes
and the annihilation condition other times. -/
theorem mem_annIdeal_iff_aeval_eq_zero {a : A} {p : R[X]} : p ∈ annIdeal R a ↔ aeval a p = 0 :=
Iff.rfl
end Semiring
section Field
variable {𝕜 A : Type*} [Field 𝕜] [Ring A] [Algebra 𝕜 A]
variable (𝕜)
open Submodule
/-- `annIdealGenerator 𝕜 a` is the monic generator of `annIdeal 𝕜 a`
if one exists, otherwise `0`.
Since `𝕜[X]` is a principal ideal domain there is a polynomial `g` such that
`span 𝕜 {g} = annIdeal a`. This picks some generator.
We prefer the monic generator of the ideal. -/
noncomputable def annIdealGenerator (a : A) : 𝕜[X] :=
let g := IsPrincipal.generator <| annIdeal 𝕜 a
g * C g.leadingCoeff⁻¹
section
variable {𝕜}
@[simp]
theorem annIdealGenerator_eq_zero_iff {a : A} : annIdealGenerator 𝕜 a = 0 ↔ annIdeal 𝕜 a = ⊥ := by
simp only [annIdealGenerator, mul_eq_zero, IsPrincipal.eq_bot_iff_generator_eq_zero,
Polynomial.C_eq_zero, inv_eq_zero, Polynomial.leadingCoeff_eq_zero, or_self_iff]
end
/-- `annIdealGenerator 𝕜 a` is indeed a generator. -/
@[simp]
theorem span_singleton_annIdealGenerator (a : A) :
Ideal.span {annIdealGenerator 𝕜 a} = annIdeal 𝕜 a := by
by_cases h : annIdealGenerator 𝕜 a = 0
· rw [h, annIdealGenerator_eq_zero_iff.mp h, Set.singleton_zero, Ideal.span_zero]
· rw [annIdealGenerator, Ideal.span_singleton_mul_right_unit, Ideal.span_singleton_generator]
apply Polynomial.isUnit_C.mpr
apply IsUnit.mk0
apply inv_eq_zero.not.mpr
apply Polynomial.leadingCoeff_eq_zero.not.mpr
apply (mul_ne_zero_iff.mp h).1
/-- The annihilating ideal generator is a member of the annihilating ideal. -/
theorem annIdealGenerator_mem (a : A) : annIdealGenerator 𝕜 a ∈ annIdeal 𝕜 a :=
Ideal.mul_mem_right _ _ (Submodule.IsPrincipal.generator_mem _)
theorem mem_iff_eq_smul_annIdealGenerator {p : 𝕜[X]} (a : A) :
p ∈ annIdeal 𝕜 a ↔ ∃ s : 𝕜[X], p = s • annIdealGenerator 𝕜 a := by
simp_rw [@eq_comm _ p, ← mem_span_singleton, ← span_singleton_annIdealGenerator 𝕜 a, Ideal.span]
/-- The generator we chose for the annihilating ideal is monic when the ideal is non-zero. -/
theorem monic_annIdealGenerator (a : A) (hg : annIdealGenerator 𝕜 a ≠ 0) :
Monic (annIdealGenerator 𝕜 a) :=
monic_mul_leadingCoeff_inv (mul_ne_zero_iff.mp hg).1
/-! We are working toward showing the generator of the annihilating ideal
in the field case is the minimal polynomial. We are going to use a uniqueness
theorem of the minimal polynomial.
This is the first condition: it must annihilate the original element `a : A`. -/
theorem annIdealGenerator_aeval_eq_zero (a : A) : aeval a (annIdealGenerator 𝕜 a) = 0 :=
mem_annIdeal_iff_aeval_eq_zero.mp (annIdealGenerator_mem 𝕜 a)
variable {𝕜}
theorem mem_iff_annIdealGenerator_dvd {p : 𝕜[X]} {a : A} :
p ∈ annIdeal 𝕜 a ↔ annIdealGenerator 𝕜 a ∣ p := by
rw [← Ideal.mem_span_singleton, span_singleton_annIdealGenerator]
/-- The generator of the annihilating ideal has minimal degree among
the non-zero members of the annihilating ideal -/
theorem degree_annIdealGenerator_le_of_mem (a : A) (p : 𝕜[X]) (hp : p ∈ annIdeal 𝕜 a)
(hpn0 : p ≠ 0) : degree (annIdealGenerator 𝕜 a) ≤ degree p :=
degree_le_of_dvd (mem_iff_annIdealGenerator_dvd.1 hp) hpn0
variable (𝕜)
/-- The generator of the annihilating ideal is the minimal polynomial. -/
theorem annIdealGenerator_eq_minpoly (a : A) : annIdealGenerator 𝕜 a = minpoly 𝕜 a := by
by_cases h : annIdealGenerator 𝕜 a = 0
· rw [h, minpoly.eq_zero]
rintro ⟨p, p_monic, hp : aeval a p = 0⟩
refine p_monic.ne_zero (Ideal.mem_bot.mp ?_)
simpa only [annIdealGenerator_eq_zero_iff.mp h] using mem_annIdeal_iff_aeval_eq_zero.mpr hp
· exact minpoly.unique _ _ (monic_annIdealGenerator _ _ h) (annIdealGenerator_aeval_eq_zero _ _)
fun q q_monic hq =>
degree_annIdealGenerator_le_of_mem a q (mem_annIdeal_iff_aeval_eq_zero.mpr hq)
q_monic.ne_zero
/-- If a monic generates the annihilating ideal, it must match our choice
of the annihilating ideal generator. -/
theorem monic_generator_eq_minpoly (a : A) (p : 𝕜[X]) (p_monic : p.Monic)
(p_gen : Ideal.span {p} = annIdeal 𝕜 a) : annIdealGenerator 𝕜 a = p := by
by_cases h : p = 0
· rwa [h, annIdealGenerator_eq_zero_iff, ← p_gen, Ideal.span_singleton_eq_bot.mpr]
· rw [← span_singleton_annIdealGenerator, Ideal.span_singleton_eq_span_singleton] at p_gen
rw [eq_comm]
apply eq_of_monic_of_associated p_monic _ p_gen
apply monic_annIdealGenerator _ _ ((Associated.ne_zero_iff p_gen).mp h)
theorem span_minpoly_eq_annihilator {M} [AddCommGroup M] [Module 𝕜 M] (f : Module.End 𝕜 M) :
Ideal.span {minpoly 𝕜 f} = Module.annihilator 𝕜[X] (Module.AEval' f) := by
rw [← annIdealGenerator_eq_minpoly, span_singleton_annIdealGenerator]; ext
rw [mem_annIdeal_iff_aeval_eq_zero, DFunLike.ext_iff, Module.mem_annihilator]; rfl
end Field
end Polynomial
|
LinearAlgebra\Basis.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Alexander Bentkamp
-/
import Mathlib.Algebra.BigOperators.Finsupp
import Mathlib.Algebra.BigOperators.Finprod
import Mathlib.Data.Fintype.BigOperators
import Mathlib.LinearAlgebra.Finsupp
import Mathlib.LinearAlgebra.LinearIndependent
import Mathlib.SetTheory.Cardinal.Cofinality
/-!
# Bases
This file defines bases in a module or vector space.
It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light.
## 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.
* `Basis ι R M` is the type of `ι`-indexed `R`-bases for a module `M`,
represented by a linear equiv `M ≃ₗ[R] ι →₀ R`.
* the basis vectors of a basis `b : Basis ι R M` are available as `b i`, where `i : ι`
* `Basis.repr` is the isomorphism sending `x : M` to its coordinates `Basis.repr x : ι →₀ R`.
The converse, turning this isomorphism into a basis, is called `Basis.ofRepr`.
* If `ι` is finite, there is a variant of `repr` called `Basis.equivFun b : M ≃ₗ[R] ι → R`
(saving you from having to work with `Finsupp`). The converse, turning this isomorphism into
a basis, is called `Basis.ofEquivFun`.
* `Basis.constr b R f` constructs a linear map `M₁ →ₗ[R] M₂` given the values `f : ι → M₂` at the
basis elements `⇑b : ι → M₁`.
* `Basis.reindex` uses an equiv to map a basis to a different indexing set.
* `Basis.map` uses a linear equiv to map a basis to a different module.
## Main statements
* `Basis.mk`: a linear independent set of vectors spanning the whole module determines a basis
* `Basis.ext` states that two linear maps are equal if they coincide on a basis.
Similar results are available for linear equivs (if they coincide on the basis vectors),
elements (if their coordinates coincide) and the functions `b.repr` and `⇑b`.
## Implementation notes
We use families instead of sets because it allows us to say that two identical vectors are linearly
dependent. For bases, this is useful as well because we can easily derive ordered bases by using an
ordered index type `ι`.
## Tags
basis, bases
-/
noncomputable section
universe u
open Function Set Submodule
variable {ι : Type*} {ι' : Type*} {R : Type*} {R₂ : Type*} {K : Type*}
variable {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*}
section Module
variable [Semiring R]
variable [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
section
variable (ι R M)
/-- A `Basis ι R M` for a module `M` is the type of `ι`-indexed `R`-bases of `M`.
The basis vectors are available as `DFunLike.coe (b : Basis ι R M) : ι → M`.
To turn a linear independent family of vectors spanning `M` into a basis, use `Basis.mk`.
They are internally represented as linear equivs `M ≃ₗ[R] (ι →₀ R)`,
available as `Basis.repr`.
-/
structure Basis where
/-- `Basis.ofRepr` constructs a basis given an assignment of coordinates to each vector. -/
ofRepr ::
/-- `repr` is the linear equivalence sending a vector `x` to its coordinates:
the `c`s such that `x = ∑ i, c i`. -/
repr : M ≃ₗ[R] ι →₀ R
end
instance uniqueBasis [Subsingleton R] : Unique (Basis ι R M) :=
⟨⟨⟨default⟩⟩, fun ⟨b⟩ => by rw [Subsingleton.elim b]⟩
namespace Basis
instance : Inhabited (Basis ι R (ι →₀ R)) :=
⟨.ofRepr (LinearEquiv.refl _ _)⟩
variable (b b₁ : Basis ι R M) (i : ι) (c : R) (x : M)
section repr
theorem repr_injective : Injective (repr : Basis ι R M → M ≃ₗ[R] ι →₀ R) := fun f g h => by
cases f; cases g; congr
/-- `b i` is the `i`th basis vector. -/
instance instFunLike : FunLike (Basis ι R M) ι M where
coe b i := b.repr.symm (Finsupp.single i 1)
coe_injective' f g h := repr_injective <| LinearEquiv.symm_bijective.injective <|
LinearEquiv.toLinearMap_injective <| by ext; exact congr_fun h _
@[simp]
theorem coe_ofRepr (e : M ≃ₗ[R] ι →₀ R) : ⇑(ofRepr e) = fun i => e.symm (Finsupp.single i 1) :=
rfl
protected theorem injective [Nontrivial R] : Injective b :=
b.repr.symm.injective.comp fun _ _ => (Finsupp.single_left_inj (one_ne_zero : (1 : R) ≠ 0)).mp
theorem repr_symm_single_one : b.repr.symm (Finsupp.single i 1) = b i :=
rfl
theorem repr_symm_single : b.repr.symm (Finsupp.single i c) = c • b i :=
calc
b.repr.symm (Finsupp.single i c) = b.repr.symm (c • Finsupp.single i (1 : R)) := by
{ rw [Finsupp.smul_single', mul_one] }
_ = c • b i := by rw [LinearEquiv.map_smul, repr_symm_single_one]
@[simp]
theorem repr_self : b.repr (b i) = Finsupp.single i 1 :=
LinearEquiv.apply_symm_apply _ _
theorem repr_self_apply (j) [Decidable (i = j)] : b.repr (b i) j = if i = j then 1 else 0 := by
rw [repr_self, Finsupp.single_apply]
@[simp]
theorem repr_symm_apply (v) : b.repr.symm v = Finsupp.total ι M R b v :=
calc
b.repr.symm v = b.repr.symm (v.sum Finsupp.single) := by simp
_ = v.sum fun i vi => b.repr.symm (Finsupp.single i vi) := map_finsupp_sum ..
_ = Finsupp.total ι M R b v := by simp only [repr_symm_single, Finsupp.total_apply]
@[simp]
theorem coe_repr_symm : ↑b.repr.symm = Finsupp.total ι M R b :=
LinearMap.ext fun v => b.repr_symm_apply v
@[simp]
theorem repr_total (v) : b.repr (Finsupp.total _ _ _ b v) = v := by
rw [← b.coe_repr_symm]
exact b.repr.apply_symm_apply v
@[simp]
theorem total_repr : Finsupp.total _ _ _ b (b.repr x) = x := by
rw [← b.coe_repr_symm]
exact b.repr.symm_apply_apply x
theorem repr_range : LinearMap.range (b.repr : M →ₗ[R] ι →₀ R) = Finsupp.supported R R univ := by
rw [LinearEquiv.range, Finsupp.supported_univ]
theorem mem_span_repr_support (m : M) : m ∈ span R (b '' (b.repr m).support) :=
(Finsupp.mem_span_image_iff_total _).2 ⟨b.repr m, by simp [Finsupp.mem_supported_support]⟩
theorem repr_support_subset_of_mem_span (s : Set ι) {m : M}
(hm : m ∈ span R (b '' s)) : ↑(b.repr m).support ⊆ s := by
rcases (Finsupp.mem_span_image_iff_total _).1 hm with ⟨l, hl, rfl⟩
rwa [repr_total, ← Finsupp.mem_supported R l]
theorem mem_span_image {m : M} {s : Set ι} : m ∈ span R (b '' s) ↔ ↑(b.repr m).support ⊆ s :=
⟨repr_support_subset_of_mem_span _ _, fun h ↦
span_mono (image_subset _ h) (mem_span_repr_support b _)⟩
@[simp]
theorem self_mem_span_image [Nontrivial R] {i : ι} {s : Set ι} :
b i ∈ span R (b '' s) ↔ i ∈ s := by
simp [mem_span_image, Finsupp.support_single_ne_zero]
end repr
section Coord
/-- `b.coord i` is the linear function giving the `i`'th coordinate of a vector
with respect to the basis `b`.
`b.coord i` is an element of the dual space. In particular, for
finite-dimensional spaces it is the `ι`th basis vector of the dual space.
-/
@[simps!]
def coord : M →ₗ[R] R :=
Finsupp.lapply i ∘ₗ ↑b.repr
theorem forall_coord_eq_zero_iff {x : M} : (∀ i, b.coord i x = 0) ↔ x = 0 :=
Iff.trans (by simp only [b.coord_apply, DFunLike.ext_iff, Finsupp.zero_apply])
b.repr.map_eq_zero_iff
/-- The sum of the coordinates of an element `m : M` with respect to a basis. -/
noncomputable def sumCoords : M →ₗ[R] R :=
(Finsupp.lsum ℕ fun _ => LinearMap.id) ∘ₗ (b.repr : M →ₗ[R] ι →₀ R)
@[simp]
theorem coe_sumCoords : (b.sumCoords : M → R) = fun m => (b.repr m).sum fun _ => id :=
rfl
theorem coe_sumCoords_eq_finsum : (b.sumCoords : M → R) = fun m => ∑ᶠ i, b.coord i m := by
ext m
simp only [Basis.sumCoords, Basis.coord, Finsupp.lapply_apply, LinearMap.id_coe,
LinearEquiv.coe_coe, Function.comp_apply, Finsupp.coe_lsum, LinearMap.coe_comp,
finsum_eq_sum _ (b.repr m).finite_support, Finsupp.sum, Finset.finite_toSet_toFinset, id,
Finsupp.fun_support_eq]
@[simp high]
theorem coe_sumCoords_of_fintype [Fintype ι] : (b.sumCoords : M → R) = ∑ i, b.coord i := by
ext m
-- Porting note: - `eq_self_iff_true`
-- + `comp_apply` `LinearMap.coeFn_sum`
simp only [sumCoords, Finsupp.sum_fintype, LinearMap.id_coe, LinearEquiv.coe_coe, coord_apply,
id, Fintype.sum_apply, imp_true_iff, Finsupp.coe_lsum, LinearMap.coe_comp, comp_apply,
LinearMap.coeFn_sum]
@[simp]
theorem sumCoords_self_apply : b.sumCoords (b i) = 1 := by
simp only [Basis.sumCoords, LinearMap.id_coe, LinearEquiv.coe_coe, id, Basis.repr_self,
Function.comp_apply, Finsupp.coe_lsum, LinearMap.coe_comp, Finsupp.sum_single_index]
theorem dvd_coord_smul (i : ι) (m : M) (r : R) : r ∣ b.coord i (r • m) :=
⟨b.coord i m, by simp⟩
theorem coord_repr_symm (b : Basis ι R M) (i : ι) (f : ι →₀ R) :
b.coord i (b.repr.symm f) = f i := by
simp only [repr_symm_apply, coord_apply, repr_total]
end Coord
section Ext
variable {R₁ : Type*} [Semiring R₁] {σ : R →+* R₁} {σ' : R₁ →+* R}
variable [RingHomInvPair σ σ'] [RingHomInvPair σ' σ]
variable {M₁ : Type*} [AddCommMonoid M₁] [Module R₁ M₁]
/-- Two linear maps are equal if they are equal on basis vectors. -/
theorem ext {f₁ f₂ : M →ₛₗ[σ] M₁} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := by
ext x
rw [← b.total_repr x, Finsupp.total_apply, Finsupp.sum]
simp only [map_sum, LinearMap.map_smulₛₗ, h]
/-- Two linear equivs are equal if they are equal on basis vectors. -/
theorem ext' {f₁ f₂ : M ≃ₛₗ[σ] M₁} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := by
ext x
rw [← b.total_repr x, Finsupp.total_apply, Finsupp.sum]
simp only [map_sum, LinearEquiv.map_smulₛₗ, h]
/-- Two elements are equal iff their coordinates are equal. -/
theorem ext_elem_iff {x y : M} : x = y ↔ ∀ i, b.repr x i = b.repr y i := by
simp only [← DFunLike.ext_iff, EmbeddingLike.apply_eq_iff_eq]
alias ⟨_, _root_.Basis.ext_elem⟩ := ext_elem_iff
theorem repr_eq_iff {b : Basis ι R M} {f : M →ₗ[R] ι →₀ R} :
↑b.repr = f ↔ ∀ i, f (b i) = Finsupp.single i 1 :=
⟨fun h i => h ▸ b.repr_self i, fun h => b.ext fun i => (b.repr_self i).trans (h i).symm⟩
theorem repr_eq_iff' {b : Basis ι R M} {f : M ≃ₗ[R] ι →₀ R} :
b.repr = f ↔ ∀ i, f (b i) = Finsupp.single i 1 :=
⟨fun h i => h ▸ b.repr_self i, fun h => b.ext' fun i => (b.repr_self i).trans (h i).symm⟩
theorem apply_eq_iff {b : Basis ι R M} {x : M} {i : ι} : b i = x ↔ b.repr x = Finsupp.single i 1 :=
⟨fun h => h ▸ b.repr_self i, fun h => b.repr.injective ((b.repr_self i).trans h.symm)⟩
/-- An unbundled version of `repr_eq_iff` -/
theorem repr_apply_eq (f : M → ι → R) (hadd : ∀ x y, f (x + y) = f x + f y)
(hsmul : ∀ (c : R) (x : M), f (c • x) = c • f x) (f_eq : ∀ i, f (b i) = Finsupp.single i 1)
(x : M) (i : ι) : b.repr x i = f x i := by
let f_i : M →ₗ[R] R :=
{ toFun := fun x => f x i
-- Porting note(#12129): additional beta reduction needed
map_add' := fun _ _ => by beta_reduce; rw [hadd, Pi.add_apply]
map_smul' := fun _ _ => by simp [hsmul, Pi.smul_apply] }
have : Finsupp.lapply i ∘ₗ ↑b.repr = f_i := by
refine b.ext fun j => ?_
show b.repr (b j) i = f (b j) i
rw [b.repr_self, f_eq]
calc
b.repr x i = f_i x := by
{ rw [← this]
rfl }
_ = f x i := rfl
/-- Two bases are equal if they assign the same coordinates. -/
theorem eq_ofRepr_eq_repr {b₁ b₂ : Basis ι R M} (h : ∀ x i, b₁.repr x i = b₂.repr x i) : b₁ = b₂ :=
repr_injective <| by ext; apply h
/-- Two bases are equal if their basis vectors are the same. -/
@[ext]
theorem eq_of_apply_eq {b₁ b₂ : Basis ι R M} : (∀ i, b₁ i = b₂ i) → b₁ = b₂ :=
DFunLike.ext _ _
end Ext
section Map
variable (f : M ≃ₗ[R] M')
/-- Apply the linear equivalence `f` to the basis vectors. -/
@[simps]
protected def map : Basis ι R M' :=
ofRepr (f.symm.trans b.repr)
@[simp]
theorem map_apply (i) : b.map f i = f (b i) :=
rfl
theorem coe_map : (b.map f : ι → M') = f ∘ b :=
rfl
end Map
section SMul
variable {G G'}
variable [Group G] [Group G']
variable [DistribMulAction G M] [DistribMulAction G' M]
variable [SMulCommClass G R M] [SMulCommClass G' R M]
/-- The action on a `Basis` by acting on each element.
See also `Basis.unitsSMul` and `Basis.groupSMul`, for the cases when a different action is applied
to each basis element. -/
instance : SMul G (Basis ι R M) where
smul g b := b.map <| DistribMulAction.toLinearEquiv _ _ g
@[simp]
theorem smul_apply (g : G) (b : Basis ι R M) (i : ι) : (g • b) i = g • b i := rfl
@[norm_cast] theorem coe_smul (g : G) (b : Basis ι R M) : ⇑(g • b) = g • ⇑b := rfl
/-- When the group in question is the automorphisms, `•` coincides with `Basis.map`. -/
@[simp]
theorem smul_eq_map (g : M ≃ₗ[R] M) (b : Basis ι R M) : g • b = b.map g := rfl
@[simp] theorem repr_smul (g : G) (b : Basis ι R M) :
(g • b).repr = (DistribMulAction.toLinearEquiv _ _ g).symm.trans b.repr := rfl
instance : MulAction G (Basis ι R M) :=
Function.Injective.mulAction _ DFunLike.coe_injective coe_smul
instance [SMulCommClass G G' M] : SMulCommClass G G' (Basis ι R M) where
smul_comm _g _g' _b := DFunLike.ext _ _ fun _ => smul_comm _ _ _
instance [SMul G G'] [IsScalarTower G G' M] : IsScalarTower G G' (Basis ι R M) where
smul_assoc _g _g' _b := DFunLike.ext _ _ fun _ => smul_assoc _ _ _
end SMul
section MapCoeffs
variable {R' : Type*} [Semiring R'] [Module R' M] (f : R ≃+* R')
attribute [local instance] SMul.comp.isScalarTower
/-- If `R` and `R'` are isomorphic rings that act identically on a module `M`,
then a basis for `M` as `R`-module is also a basis for `M` as `R'`-module.
See also `Basis.algebraMapCoeffs` for the case where `f` is equal to `algebraMap`.
-/
@[simps (config := { simpRhs := true })]
def mapCoeffs (h : ∀ (c) (x : M), f c • x = c • x) : Basis ι R' M := by
letI : Module R' R := Module.compHom R (↑f.symm : R' →+* R)
haveI : IsScalarTower R' R M :=
{ smul_assoc := fun x y z => by
-- Porting note: `dsimp [(· • ·)]` is unavailable because
-- `HSMul.hsmul` becomes `SMul.smul`.
change (f.symm x * y) • z = x • (y • z)
rw [mul_smul, ← h, f.apply_symm_apply] }
exact ofRepr <| (b.repr.restrictScalars R').trans <|
Finsupp.mapRange.linearEquiv (Module.compHom.toLinearEquiv f.symm).symm
variable (h : ∀ (c) (x : M), f c • x = c • x)
theorem mapCoeffs_apply (i : ι) : b.mapCoeffs f h i = b i :=
apply_eq_iff.mpr <| by
-- Porting note: in Lean 3, these were automatically inferred from the definition of
-- `mapCoeffs`.
letI : Module R' R := Module.compHom R (↑f.symm : R' →+* R)
haveI : IsScalarTower R' R M :=
{ smul_assoc := fun x y z => by
-- Porting note: `dsimp [(· • ·)]` is unavailable because
-- `HSMul.hsmul` becomes `SMul.smul`.
change (f.symm x * y) • z = x • (y • z)
rw [mul_smul, ← h, f.apply_symm_apply] }
simp
@[simp]
theorem coe_mapCoeffs : (b.mapCoeffs f h : ι → M) = b :=
funext <| b.mapCoeffs_apply f h
end MapCoeffs
section Reindex
variable (b' : Basis ι' R M')
variable (e : ι ≃ ι')
/-- `b.reindex (e : ι ≃ ι')` is a basis indexed by `ι'` -/
def reindex : Basis ι' R M :=
.ofRepr (b.repr.trans (Finsupp.domLCongr e))
theorem reindex_apply (i' : ι') : b.reindex e i' = b (e.symm i') :=
show (b.repr.trans (Finsupp.domLCongr e)).symm (Finsupp.single i' 1) =
b.repr.symm (Finsupp.single (e.symm i') 1)
by rw [LinearEquiv.symm_trans_apply, Finsupp.domLCongr_symm, Finsupp.domLCongr_single]
@[simp]
theorem coe_reindex : (b.reindex e : ι' → M) = b ∘ e.symm :=
funext (b.reindex_apply e)
theorem repr_reindex_apply (i' : ι') : (b.reindex e).repr x i' = b.repr x (e.symm i') :=
show (Finsupp.domLCongr e : _ ≃ₗ[R] _) (b.repr x) i' = _ by simp
@[simp]
theorem repr_reindex : (b.reindex e).repr x = (b.repr x).mapDomain e :=
DFunLike.ext _ _ <| by simp [repr_reindex_apply]
@[simp]
theorem reindex_refl : b.reindex (Equiv.refl ι) = b :=
eq_of_apply_eq fun i => by simp
/-- `simp` can prove this as `Basis.coe_reindex` + `EquivLike.range_comp` -/
theorem range_reindex : Set.range (b.reindex e) = Set.range b := by
simp [coe_reindex, range_comp]
@[simp]
theorem sumCoords_reindex : (b.reindex e).sumCoords = b.sumCoords := by
ext x
simp only [coe_sumCoords, repr_reindex]
exact Finsupp.sum_mapDomain_index (fun _ => rfl) fun _ _ _ => rfl
/-- `b.reindex_range` is a basis indexed by `range b`, the basis vectors themselves. -/
def reindexRange : Basis (range b) R M :=
haveI := Classical.dec (Nontrivial R)
if h : Nontrivial R then
letI := h
b.reindex (Equiv.ofInjective b (Basis.injective b))
else
letI : Subsingleton R := not_nontrivial_iff_subsingleton.mp h
.ofRepr (Module.subsingletonEquiv R M (range b))
theorem reindexRange_self (i : ι) (h := Set.mem_range_self i) : b.reindexRange ⟨b i, h⟩ = b i := by
by_cases htr : Nontrivial R
· letI := htr
simp [htr, reindexRange, reindex_apply, Equiv.apply_ofInjective_symm b.injective,
Subtype.coe_mk]
· letI : Subsingleton R := not_nontrivial_iff_subsingleton.mp htr
letI := Module.subsingleton R M
simp [reindexRange, eq_iff_true_of_subsingleton]
theorem reindexRange_repr_self (i : ι) :
b.reindexRange.repr (b i) = Finsupp.single ⟨b i, mem_range_self i⟩ 1 :=
calc
b.reindexRange.repr (b i) = b.reindexRange.repr (b.reindexRange ⟨b i, mem_range_self i⟩) :=
congr_arg _ (b.reindexRange_self _ _).symm
_ = Finsupp.single ⟨b i, mem_range_self i⟩ 1 := b.reindexRange.repr_self _
@[simp]
theorem reindexRange_apply (x : range b) : b.reindexRange x = x := by
rcases x with ⟨bi, ⟨i, rfl⟩⟩
exact b.reindexRange_self i
theorem reindexRange_repr' (x : M) {bi : M} {i : ι} (h : b i = bi) :
b.reindexRange.repr x ⟨bi, ⟨i, h⟩⟩ = b.repr x i := by
nontriviality
subst h
apply (b.repr_apply_eq (fun x i => b.reindexRange.repr x ⟨b i, _⟩) _ _ _ x i).symm
· intro x y
ext i
simp only [Pi.add_apply, LinearEquiv.map_add, Finsupp.coe_add]
· intro c x
ext i
simp only [Pi.smul_apply, LinearEquiv.map_smul, Finsupp.coe_smul]
· intro i
ext j
simp only [reindexRange_repr_self]
apply Finsupp.single_apply_left (f := fun i => (⟨b i, _⟩ : Set.range b))
exact fun i j h => b.injective (Subtype.mk.inj h)
@[simp]
theorem reindexRange_repr (x : M) (i : ι) (h := Set.mem_range_self i) :
b.reindexRange.repr x ⟨b i, h⟩ = b.repr x i :=
b.reindexRange_repr' _ rfl
section Fintype
variable [Fintype ι] [DecidableEq M]
/-- `b.reindexFinsetRange` is a basis indexed by `Finset.univ.image b`,
the finite set of basis vectors themselves. -/
def reindexFinsetRange : Basis (Finset.univ.image b) R M :=
b.reindexRange.reindex ((Equiv.refl M).subtypeEquiv (by simp))
theorem reindexFinsetRange_self (i : ι) (h := Finset.mem_image_of_mem b (Finset.mem_univ i)) :
b.reindexFinsetRange ⟨b i, h⟩ = b i := by
rw [reindexFinsetRange, reindex_apply, reindexRange_apply]
rfl
@[simp]
theorem reindexFinsetRange_apply (x : Finset.univ.image b) : b.reindexFinsetRange x = x := by
rcases x with ⟨bi, hbi⟩
rcases Finset.mem_image.mp hbi with ⟨i, -, rfl⟩
exact b.reindexFinsetRange_self i
theorem reindexFinsetRange_repr_self (i : ι) :
b.reindexFinsetRange.repr (b i) =
Finsupp.single ⟨b i, Finset.mem_image_of_mem b (Finset.mem_univ i)⟩ 1 := by
ext ⟨bi, hbi⟩
rw [reindexFinsetRange, repr_reindex, Finsupp.mapDomain_equiv_apply, reindexRange_repr_self]
-- Porting note: replaced a `convert; refl` with `simp`
simp [Finsupp.single_apply]
@[simp]
theorem reindexFinsetRange_repr (x : M) (i : ι)
(h := Finset.mem_image_of_mem b (Finset.mem_univ i)) :
b.reindexFinsetRange.repr x ⟨b i, h⟩ = b.repr x i := by simp [reindexFinsetRange]
end Fintype
end Reindex
protected theorem linearIndependent : LinearIndependent R b :=
linearIndependent_iff.mpr fun l hl =>
calc
l = b.repr (Finsupp.total _ _ _ b l) := (b.repr_total l).symm
_ = 0 := by rw [hl, LinearEquiv.map_zero]
protected theorem ne_zero [Nontrivial R] (i) : b i ≠ 0 :=
b.linearIndependent.ne_zero i
protected theorem mem_span (x : M) : x ∈ span R (range b) :=
span_mono (image_subset_range _ _) (mem_span_repr_support b x)
@[simp]
protected theorem span_eq : span R (range b) = ⊤ :=
eq_top_iff.mpr fun x _ => b.mem_span x
theorem index_nonempty (b : Basis ι R M) [Nontrivial M] : Nonempty ι := by
obtain ⟨x, y, ne⟩ : ∃ x y : M, x ≠ y := Nontrivial.exists_pair_ne
obtain ⟨i, _⟩ := not_forall.mp (mt b.ext_elem_iff.2 ne)
exact ⟨i⟩
/-- If the submodule `P` has a basis, `x ∈ P` iff it is a linear combination of basis vectors. -/
theorem mem_submodule_iff {P : Submodule R M} (b : Basis ι R P) {x : M} :
x ∈ P ↔ ∃ c : ι →₀ R, x = Finsupp.sum c fun i x => x • (b i : M) := by
conv_lhs =>
rw [← P.range_subtype, ← Submodule.map_top, ← b.span_eq, Submodule.map_span, ← Set.range_comp,
← Finsupp.range_total]
simp [@eq_comm _ x, Function.comp, Finsupp.total_apply]
section Constr
variable (S : Type*) [Semiring S] [Module S M']
variable [SMulCommClass R S M']
/-- Construct a linear map given the value at the basis, called `Basis.constr b S f` where `b` is
a basis, `f` is the value of the linear map over the elements of the basis, and `S` is an
extra semiring (typically `S = R` or `S = ℕ`).
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].
-/
def constr : (ι → M') ≃ₗ[S] M →ₗ[R] M' where
toFun f := (Finsupp.total M' M' R id).comp <| Finsupp.lmapDomain R R f ∘ₗ ↑b.repr
invFun f i := f (b i)
left_inv f := by
ext
simp
right_inv f := by
refine b.ext fun i => ?_
simp
map_add' f g := by
refine b.ext fun i => ?_
simp
map_smul' c f := by
refine b.ext fun i => ?_
simp
theorem constr_def (f : ι → M') :
constr (M' := M') b S f = Finsupp.total M' M' R id ∘ₗ Finsupp.lmapDomain R R f ∘ₗ ↑b.repr :=
rfl
theorem constr_apply (f : ι → M') (x : M) :
constr (M' := M') b S f x = (b.repr x).sum fun b a => a • f b := by
simp only [constr_def, LinearMap.comp_apply, Finsupp.lmapDomain_apply, Finsupp.total_apply]
rw [Finsupp.sum_mapDomain_index] <;> simp [add_smul]
@[simp]
theorem constr_basis (f : ι → M') (i : ι) : (constr (M' := M') b S f : M → M') (b i) = f i := by
simp [Basis.constr_apply, b.repr_self]
theorem constr_eq {g : ι → M'} {f : M →ₗ[R] M'} (h : ∀ i, g i = f (b i)) :
constr (M' := M') b S g = f :=
b.ext fun i => (b.constr_basis S g i).trans (h i)
theorem constr_self (f : M →ₗ[R] M') : (constr (M' := M') b S fun i => f (b i)) = f :=
b.constr_eq S fun _ => rfl
theorem constr_range {f : ι → M'} :
LinearMap.range (constr (M' := M') b S f) = span R (range f) := by
rw [b.constr_def S f, LinearMap.range_comp, LinearMap.range_comp, LinearEquiv.range, ←
Finsupp.supported_univ, Finsupp.lmapDomain_supported, ← Set.image_univ, ←
Finsupp.span_image_eq_map_total, Set.image_id]
@[simp]
theorem constr_comp (f : M' →ₗ[R] M') (v : ι → M') :
constr (M' := M') b S (f ∘ v) = f.comp (constr (M' := M') b S v) :=
b.ext fun i => by simp only [Basis.constr_basis, LinearMap.comp_apply, Function.comp]
end Constr
section Equiv
variable (b' : Basis ι' R M') (e : ι ≃ ι')
variable [AddCommMonoid M''] [Module R M'']
/-- If `b` is a basis for `M` and `b'` a basis for `M'`, and the index types are equivalent,
`b.equiv b' e` is a linear equivalence `M ≃ₗ[R] M'`, mapping `b i` to `b' (e i)`. -/
protected def equiv : M ≃ₗ[R] M' :=
b.repr.trans (b'.reindex e.symm).repr.symm
@[simp]
theorem equiv_apply : b.equiv b' e (b i) = b' (e i) := by simp [Basis.equiv]
@[simp]
theorem equiv_refl : b.equiv b (Equiv.refl ι) = LinearEquiv.refl R M :=
b.ext' fun i => by simp
@[simp]
theorem equiv_symm : (b.equiv b' e).symm = b'.equiv b e.symm :=
b'.ext' fun i => (b.equiv b' e).injective (by simp)
@[simp]
theorem equiv_trans {ι'' : Type*} (b'' : Basis ι'' R M'') (e : ι ≃ ι') (e' : ι' ≃ ι'') :
(b.equiv b' e).trans (b'.equiv b'' e') = b.equiv b'' (e.trans e') :=
b.ext' fun i => by simp
@[simp]
theorem map_equiv (b : Basis ι R M) (b' : Basis ι' R M') (e : ι ≃ ι') :
b.map (b.equiv b' e) = b'.reindex e.symm := by
ext i
simp
end Equiv
section Prod
variable (b' : Basis ι' R M')
/-- `Basis.prod` maps an `ι`-indexed basis for `M` and an `ι'`-indexed basis for `M'`
to an `ι ⊕ ι'`-index basis for `M × M'`.
For the specific case of `R × R`, see also `Basis.finTwoProd`. -/
protected def prod : Basis (ι ⊕ ι') R (M × M') :=
ofRepr ((b.repr.prod b'.repr).trans (Finsupp.sumFinsuppLEquivProdFinsupp R).symm)
@[simp]
theorem prod_repr_inl (x) (i) : (b.prod b').repr x (Sum.inl i) = b.repr x.1 i :=
rfl
@[simp]
theorem prod_repr_inr (x) (i) : (b.prod b').repr x (Sum.inr i) = b'.repr x.2 i :=
rfl
theorem prod_apply_inl_fst (i) : (b.prod b' (Sum.inl i)).1 = b i :=
b.repr.injective <| by
ext j
simp only [Basis.prod, Basis.coe_ofRepr, LinearEquiv.symm_trans_apply, LinearEquiv.prod_symm,
LinearEquiv.prod_apply, b.repr.apply_symm_apply, LinearEquiv.symm_symm, repr_self,
Equiv.toFun_as_coe, Finsupp.fst_sumFinsuppLEquivProdFinsupp]
apply Finsupp.single_apply_left Sum.inl_injective
theorem prod_apply_inr_fst (i) : (b.prod b' (Sum.inr i)).1 = 0 :=
b.repr.injective <| by
ext i
simp only [Basis.prod, Basis.coe_ofRepr, LinearEquiv.symm_trans_apply, LinearEquiv.prod_symm,
LinearEquiv.prod_apply, b.repr.apply_symm_apply, LinearEquiv.symm_symm, repr_self,
Equiv.toFun_as_coe, Finsupp.fst_sumFinsuppLEquivProdFinsupp, LinearEquiv.map_zero,
Finsupp.zero_apply]
apply Finsupp.single_eq_of_ne Sum.inr_ne_inl
theorem prod_apply_inl_snd (i) : (b.prod b' (Sum.inl i)).2 = 0 :=
b'.repr.injective <| by
ext j
simp only [Basis.prod, Basis.coe_ofRepr, LinearEquiv.symm_trans_apply, LinearEquiv.prod_symm,
LinearEquiv.prod_apply, b'.repr.apply_symm_apply, LinearEquiv.symm_symm, repr_self,
Equiv.toFun_as_coe, Finsupp.snd_sumFinsuppLEquivProdFinsupp, LinearEquiv.map_zero,
Finsupp.zero_apply]
apply Finsupp.single_eq_of_ne Sum.inl_ne_inr
theorem prod_apply_inr_snd (i) : (b.prod b' (Sum.inr i)).2 = b' i :=
b'.repr.injective <| by
ext i
simp only [Basis.prod, Basis.coe_ofRepr, LinearEquiv.symm_trans_apply, LinearEquiv.prod_symm,
LinearEquiv.prod_apply, b'.repr.apply_symm_apply, LinearEquiv.symm_symm, repr_self,
Equiv.toFun_as_coe, Finsupp.snd_sumFinsuppLEquivProdFinsupp]
apply Finsupp.single_apply_left Sum.inr_injective
@[simp]
theorem prod_apply (i) :
b.prod b' i = Sum.elim (LinearMap.inl R M M' ∘ b) (LinearMap.inr R M M' ∘ b') i := by
ext <;> cases i <;>
simp only [prod_apply_inl_fst, Sum.elim_inl, LinearMap.inl_apply, prod_apply_inr_fst,
Sum.elim_inr, LinearMap.inr_apply, prod_apply_inl_snd, prod_apply_inr_snd, Function.comp]
end Prod
section NoZeroSMulDivisors
-- Can't be an instance because the basis can't be inferred.
protected theorem noZeroSMulDivisors [NoZeroDivisors R] (b : Basis ι R M) :
NoZeroSMulDivisors R M :=
⟨fun {c x} hcx => by
exact or_iff_not_imp_right.mpr fun hx => by
rw [← b.total_repr x, ← LinearMap.map_smul] at hcx
have := linearIndependent_iff.mp b.linearIndependent (c • b.repr x) hcx
rw [smul_eq_zero] at this
exact this.resolve_right fun hr => hx (b.repr.map_eq_zero_iff.mp hr)⟩
protected theorem smul_eq_zero [NoZeroDivisors R] (b : Basis ι R M) {c : R} {x : M} :
c • x = 0 ↔ c = 0 ∨ x = 0 :=
@smul_eq_zero _ _ _ _ _ b.noZeroSMulDivisors _ _
theorem eq_bot_of_rank_eq_zero [NoZeroDivisors R] (b : Basis ι R M) (N : Submodule R M)
(rank_eq : ∀ {m : ℕ} (v : Fin m → N), LinearIndependent R ((↑) ∘ v : Fin m → M) → m = 0) :
N = ⊥ := by
rw [Submodule.eq_bot_iff]
intro x hx
contrapose! rank_eq with x_ne
refine ⟨1, fun _ => ⟨x, hx⟩, ?_, one_ne_zero⟩
rw [Fintype.linearIndependent_iff]
rintro g sum_eq i
cases' i with _ hi
simp only [Function.const_apply, Fin.default_eq_zero, Submodule.coe_mk, Finset.univ_unique,
Function.comp_const, Finset.sum_singleton] at sum_eq
convert (b.smul_eq_zero.mp sum_eq).resolve_right x_ne
end NoZeroSMulDivisors
section Singleton
/-- `Basis.singleton ι R` is the basis sending the unique element of `ι` to `1 : R`. -/
protected def singleton (ι R : Type*) [Unique ι] [Semiring R] : Basis ι R R :=
ofRepr
{ toFun := fun x => Finsupp.single default x
invFun := fun f => f default
left_inv := fun x => by simp
right_inv := fun f => Finsupp.unique_ext (by simp)
map_add' := fun x y => by simp
map_smul' := fun c x => by simp }
@[simp]
theorem singleton_apply (ι R : Type*) [Unique ι] [Semiring R] (i) : Basis.singleton ι R i = 1 :=
apply_eq_iff.mpr (by simp [Basis.singleton])
@[simp]
theorem singleton_repr (ι R : Type*) [Unique ι] [Semiring R] (x i) :
(Basis.singleton ι R).repr x i = x := by simp [Basis.singleton, Unique.eq_default i]
theorem basis_singleton_iff {R M : Type*} [Ring R] [Nontrivial R] [AddCommGroup M] [Module R M]
[NoZeroSMulDivisors R M] (ι : Type*) [Unique ι] :
Nonempty (Basis ι R M) ↔ ∃ x ≠ 0, ∀ y : M, ∃ r : R, r • x = y := by
constructor
· rintro ⟨b⟩
refine ⟨b default, b.linearIndependent.ne_zero _, ?_⟩
simpa [span_singleton_eq_top_iff, Set.range_unique] using b.span_eq
· rintro ⟨x, nz, w⟩
refine ⟨ofRepr <| LinearEquiv.symm
{ toFun := fun f => f default • x
invFun := fun y => Finsupp.single default (w y).choose
left_inv := fun f => Finsupp.unique_ext ?_
right_inv := fun y => ?_
map_add' := fun y z => ?_
map_smul' := fun c y => ?_ }⟩
· simp [Finsupp.add_apply, add_smul]
· simp only [Finsupp.coe_smul, Pi.smul_apply, RingHom.id_apply]
rw [← smul_assoc]
· refine smul_left_injective _ nz ?_
simp only [Finsupp.single_eq_same]
exact (w (f default • x)).choose_spec
· simp only [Finsupp.single_eq_same]
exact (w y).choose_spec
end Singleton
section Empty
variable (M)
/-- If `M` is a subsingleton and `ι` is empty, this is the unique `ι`-indexed basis for `M`. -/
protected def empty [Subsingleton M] [IsEmpty ι] : Basis ι R M :=
ofRepr 0
instance emptyUnique [Subsingleton M] [IsEmpty ι] : Unique (Basis ι R M) where
default := Basis.empty M
uniq := fun _ => congr_arg ofRepr <| Subsingleton.elim _ _
end Empty
end Basis
section Fintype
open Basis
open Fintype
/-- A module over `R` with a finite basis is linearly equivalent to functions from its basis to `R`.
-/
def Basis.equivFun [Finite ι] (b : Basis ι R M) : M ≃ₗ[R] ι → R :=
LinearEquiv.trans b.repr
({ Finsupp.equivFunOnFinite with
toFun := (↑)
map_add' := Finsupp.coe_add
map_smul' := Finsupp.coe_smul } :
(ι →₀ R) ≃ₗ[R] ι → R)
/-- A module over a finite ring that admits a finite basis is finite. -/
def Module.fintypeOfFintype [Fintype ι] (b : Basis ι R M) [Fintype R] : Fintype M :=
haveI := Classical.decEq ι
Fintype.ofEquiv _ b.equivFun.toEquiv.symm
theorem Module.card_fintype [Fintype ι] (b : Basis ι R M) [Fintype R] [Fintype M] :
card M = card R ^ card ι := by
classical
calc
card M = card (ι → R) := card_congr b.equivFun.toEquiv
_ = card R ^ card ι := card_fun
/-- Given a basis `v` indexed by `ι`, the canonical linear equivalence between `ι → R` and `M` maps
a function `x : ι → R` to the linear combination `∑_i x i • v i`. -/
@[simp]
theorem Basis.equivFun_symm_apply [Fintype ι] (b : Basis ι R M) (x : ι → R) :
b.equivFun.symm x = ∑ i, x i • b i := by
simp [Basis.equivFun, Finsupp.total_apply, Finsupp.sum_fintype, Finsupp.equivFunOnFinite]
@[simp]
theorem Basis.equivFun_apply [Finite ι] (b : Basis ι R M) (u : M) : b.equivFun u = b.repr u :=
rfl
@[simp]
theorem Basis.map_equivFun [Finite ι] (b : Basis ι R M) (f : M ≃ₗ[R] M') :
(b.map f).equivFun = f.symm.trans b.equivFun :=
rfl
theorem Basis.sum_equivFun [Fintype ι] (b : Basis ι R M) (u : M) :
∑ i, b.equivFun u i • b i = u := by
rw [← b.equivFun_symm_apply, b.equivFun.symm_apply_apply]
theorem Basis.sum_repr [Fintype ι] (b : Basis ι R M) (u : M) : ∑ i, b.repr u i • b i = u :=
b.sum_equivFun u
@[simp]
theorem Basis.equivFun_self [Finite ι] [DecidableEq ι] (b : Basis ι R M) (i j : ι) :
b.equivFun (b i) j = if i = j then 1 else 0 := by rw [b.equivFun_apply, b.repr_self_apply]
theorem Basis.repr_sum_self [Fintype ι] (b : Basis ι R M) (c : ι → R) :
b.repr (∑ i, c i • b i) = c := by
simp_rw [← b.equivFun_symm_apply, ← b.equivFun_apply, b.equivFun.apply_symm_apply]
/-- Define a basis by mapping each vector `x : M` to its coordinates `e x : ι → R`,
as long as `ι` is finite. -/
def Basis.ofEquivFun [Finite ι] (e : M ≃ₗ[R] ι → R) : Basis ι R M :=
.ofRepr <| e.trans <| LinearEquiv.symm <| Finsupp.linearEquivFunOnFinite R R ι
@[simp]
theorem Basis.ofEquivFun_repr_apply [Finite ι] (e : M ≃ₗ[R] ι → R) (x : M) (i : ι) :
(Basis.ofEquivFun e).repr x i = e x i :=
rfl
@[simp]
theorem Basis.coe_ofEquivFun [Finite ι] [DecidableEq ι] (e : M ≃ₗ[R] ι → R) :
(Basis.ofEquivFun e : ι → M) = fun i => e.symm (Function.update 0 i 1) :=
funext fun i =>
e.injective <|
funext fun j => by
simp [Basis.ofEquivFun, ← Finsupp.single_eq_pi_single, Finsupp.single_eq_update]
@[simp]
theorem Basis.ofEquivFun_equivFun [Finite ι] (v : Basis ι R M) :
Basis.ofEquivFun v.equivFun = v :=
Basis.repr_injective <| by ext; rfl
@[simp]
theorem Basis.equivFun_ofEquivFun [Finite ι] (e : M ≃ₗ[R] ι → R) :
(Basis.ofEquivFun e).equivFun = e := by
ext j
simp_rw [Basis.equivFun_apply, Basis.ofEquivFun_repr_apply]
variable (S : Type*) [Semiring S] [Module S M']
variable [SMulCommClass R S M']
@[simp]
theorem Basis.constr_apply_fintype [Fintype ι] (b : Basis ι R M) (f : ι → M') (x : M) :
(constr (M' := M') b S f : M → M') x = ∑ i, b.equivFun x i • f i := by
simp [b.constr_apply, b.equivFun_apply, Finsupp.sum_fintype]
/-- If the submodule `P` has a finite basis,
`x ∈ P` iff it is a linear combination of basis vectors. -/
theorem Basis.mem_submodule_iff' [Fintype ι] {P : Submodule R M} (b : Basis ι R P) {x : M} :
x ∈ P ↔ ∃ c : ι → R, x = ∑ i, c i • (b i : M) :=
b.mem_submodule_iff.trans <|
Finsupp.equivFunOnFinite.exists_congr_left.trans <|
exists_congr fun c => by simp [Finsupp.sum_fintype, Finsupp.equivFunOnFinite]
theorem Basis.coord_equivFun_symm [Finite ι] (b : Basis ι R M) (i : ι) (f : ι → R) :
b.coord i (b.equivFun.symm f) = f i :=
b.coord_repr_symm i (Finsupp.equivFunOnFinite.symm f)
end Fintype
end Module
section CommSemiring
namespace Basis
variable [CommSemiring R]
variable [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
variable (b : Basis ι R M) (b' : Basis ι' R M')
/-- If `b` is a basis for `M` and `b'` a basis for `M'`,
and `f`, `g` form a bijection between the basis vectors,
`b.equiv' b' f g hf hg hgf hfg` is a linear equivalence `M ≃ₗ[R] M'`, mapping `b i` to `f (b i)`.
-/
def equiv' (f : M → M') (g : M' → M) (hf : ∀ i, f (b i) ∈ range b') (hg : ∀ i, g (b' i) ∈ range b)
(hgf : ∀ i, g (f (b i)) = b i) (hfg : ∀ i, f (g (b' i)) = b' i) : M ≃ₗ[R] M' :=
{ constr (M' := M') b R (f ∘ b) with
invFun := constr (M' := M) b' R (g ∘ b')
left_inv :=
have : (constr (M' := M) b' R (g ∘ b')).comp (constr (M' := M') b R (f ∘ b)) = LinearMap.id :=
b.ext fun i =>
Exists.elim (hf i) fun i' hi' => by
rw [LinearMap.comp_apply, b.constr_basis, Function.comp_apply, ← hi', b'.constr_basis,
Function.comp_apply, hi', hgf, LinearMap.id_apply]
fun x => congr_arg (fun h : M →ₗ[R] M => h x) this
right_inv :=
have : (constr (M' := M') b R (f ∘ b)).comp (constr (M' := M) b' R (g ∘ b')) = LinearMap.id :=
b'.ext fun i =>
Exists.elim (hg i) fun i' hi' => by
rw [LinearMap.comp_apply, b'.constr_basis, Function.comp_apply, ← hi', b.constr_basis,
Function.comp_apply, hi', hfg, LinearMap.id_apply]
fun x => congr_arg (fun h : M' →ₗ[R] M' => h x) this }
@[simp]
theorem equiv'_apply (f : M → M') (g : M' → M) (hf hg hgf hfg) (i : ι) :
b.equiv' b' f g hf hg hgf hfg (b i) = f (b i) :=
b.constr_basis R _ _
@[simp]
theorem equiv'_symm_apply (f : M → M') (g : M' → M) (hf hg hgf hfg) (i : ι') :
(b.equiv' b' f g hf hg hgf hfg).symm (b' i) = g (b' i) :=
b'.constr_basis R _ _
theorem sum_repr_mul_repr {ι'} [Fintype ι'] (b' : Basis ι' R M) (x : M) (i : ι) :
(∑ j : ι', b.repr (b' j) i * b'.repr x j) = b.repr x i := by
conv_rhs => rw [← b'.sum_repr x]
simp_rw [map_sum, map_smul, Finset.sum_apply']
refine Finset.sum_congr rfl fun j _ => ?_
rw [Finsupp.smul_apply, smul_eq_mul, mul_comm]
end Basis
end CommSemiring
section Module
open LinearMap
variable {v : ι → M}
variable [Ring R] [CommRing R₂] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M'']
variable [Module R M] [Module R₂ M] [Module R M'] [Module R M'']
variable {c d : R} {x y : M}
variable (b : Basis ι R M)
namespace Basis
/-- Any basis is a maximal linear independent set.
-/
theorem maximal [Nontrivial R] (b : Basis ι R M) : b.linearIndependent.Maximal := fun w hi h => by
-- If `w` is strictly bigger than `range b`,
apply le_antisymm h
-- then choose some `x ∈ w \ range b`,
intro x p
by_contra q
-- and write it in terms of the basis.
have e := b.total_repr x
-- This then expresses `x` as a linear combination
-- of elements of `w` which are in the range of `b`,
let u : ι ↪ w :=
⟨fun i => ⟨b i, h ⟨i, rfl⟩⟩, fun i i' r =>
b.injective (by simpa only [Subtype.mk_eq_mk] using r)⟩
simp_rw [Finsupp.total_apply] at e
change ((b.repr x).sum fun (i : ι) (a : R) ↦ a • (u i : M)) = ((⟨x, p⟩ : w) : M) at e
rw [← Finsupp.sum_embDomain (f := u) (g := fun x r ↦ r • (x : M)), ← Finsupp.total_apply] at e
-- Now we can contradict the linear independence of `hi`
refine hi.total_ne_of_not_mem_support _ ?_ e
simp only [Finset.mem_map, Finsupp.support_embDomain]
rintro ⟨j, -, W⟩
simp only [u, Embedding.coeFn_mk, Subtype.mk_eq_mk] at W
apply q ⟨j, W⟩
section Mk
variable (hli : LinearIndependent R v) (hsp : ⊤ ≤ span R (range v))
/-- A linear independent family of vectors spanning the whole module is a basis. -/
protected noncomputable def mk : Basis ι R M :=
.ofRepr
{ hli.repr.comp (LinearMap.id.codRestrict _ fun _ => hsp Submodule.mem_top) with
invFun := Finsupp.total _ _ _ v
left_inv := fun x => hli.total_repr ⟨x, _⟩
right_inv := fun _ => hli.repr_eq rfl }
@[simp]
theorem mk_repr : (Basis.mk hli hsp).repr x = hli.repr ⟨x, hsp Submodule.mem_top⟩ :=
rfl
theorem mk_apply (i : ι) : Basis.mk hli hsp i = v i :=
show Finsupp.total _ _ _ v _ = v i by simp
@[simp]
theorem coe_mk : ⇑(Basis.mk hli hsp) = v :=
funext (mk_apply _ _)
variable {hli hsp}
/-- Given a basis, the `i`th element of the dual basis evaluates to 1 on the `i`th element of the
basis. -/
theorem mk_coord_apply_eq (i : ι) : (Basis.mk hli hsp).coord i (v i) = 1 :=
show hli.repr ⟨v i, Submodule.subset_span (mem_range_self i)⟩ i = 1 by simp [hli.repr_eq_single i]
/-- Given a basis, the `i`th element of the dual basis evaluates to 0 on the `j`th element of the
basis if `j ≠ i`. -/
theorem mk_coord_apply_ne {i j : ι} (h : j ≠ i) : (Basis.mk hli hsp).coord i (v j) = 0 :=
show hli.repr ⟨v j, Submodule.subset_span (mem_range_self j)⟩ i = 0 by
simp [hli.repr_eq_single j, h]
/-- Given a basis, the `i`th element of the dual basis evaluates to the Kronecker delta on the
`j`th element of the basis. -/
theorem mk_coord_apply [DecidableEq ι] {i j : ι} :
(Basis.mk hli hsp).coord i (v j) = if j = i then 1 else 0 := by
rcases eq_or_ne j i with h | h
· simp only [h, if_true, eq_self_iff_true, mk_coord_apply_eq i]
· simp only [h, if_false, mk_coord_apply_ne h]
end Mk
section Span
variable (hli : LinearIndependent R v)
/-- A linear independent family of vectors is a basis for their span. -/
protected noncomputable def span : Basis ι R (span R (range v)) :=
Basis.mk (linearIndependent_span hli) <| by
intro x _
have : ∀ i, v i ∈ span R (range v) := fun i ↦ subset_span (Set.mem_range_self _)
have h₁ : (((↑) : span R (range v) → M) '' range fun i => ⟨v i, this i⟩) = range v := by
simp only [SetLike.coe_sort_coe, ← Set.range_comp]
rfl
have h₂ : map (Submodule.subtype (span R (range v))) (span R (range fun i => ⟨v i, this i⟩)) =
span R (range v) := by
rw [← span_image, Submodule.coeSubtype]
-- Porting note: why doesn't `rw [h₁]` work here?
exact congr_arg _ h₁
have h₃ : (x : M) ∈ map (Submodule.subtype (span R (range v)))
(span R (Set.range fun i => Subtype.mk (v i) (this i))) := by
rw [h₂]
apply Subtype.mem x
rcases mem_map.1 h₃ with ⟨y, hy₁, hy₂⟩
have h_x_eq_y : x = y := by
rw [Subtype.ext_iff, ← hy₂]
simp
rwa [h_x_eq_y]
protected theorem span_apply (i : ι) : (Basis.span hli i : M) = v i :=
congr_arg ((↑) : span R (range v) → M) <| Basis.mk_apply _ _ _
end Span
theorem groupSMul_span_eq_top {G : Type*} [Group G] [DistribMulAction G R] [DistribMulAction G M]
[IsScalarTower G R M] {v : ι → M} (hv : Submodule.span R (Set.range v) = ⊤) {w : ι → G} :
Submodule.span R (Set.range (w • v)) = ⊤ := by
rw [eq_top_iff]
intro j hj
rw [← hv] at hj
rw [Submodule.mem_span] at hj ⊢
refine fun p hp => hj p fun u hu => ?_
obtain ⟨i, rfl⟩ := hu
have : ((w i)⁻¹ • (1 : R)) • w i • v i ∈ p := p.smul_mem ((w i)⁻¹ • (1 : R)) (hp ⟨i, rfl⟩)
rwa [smul_one_smul, inv_smul_smul] at this
/-- Given a basis `v` and a map `w` such that for all `i`, `w i` are elements of a group,
`groupSMul` provides the basis corresponding to `w • v`. -/
def groupSMul {G : Type*} [Group G] [DistribMulAction G R] [DistribMulAction G M]
[IsScalarTower G R M] [SMulCommClass G R M] (v : Basis ι R M) (w : ι → G) : Basis ι R M :=
Basis.mk (LinearIndependent.group_smul v.linearIndependent w) (groupSMul_span_eq_top v.span_eq).ge
theorem groupSMul_apply {G : Type*} [Group G] [DistribMulAction G R] [DistribMulAction G M]
[IsScalarTower G R M] [SMulCommClass G R M] {v : Basis ι R M} {w : ι → G} (i : ι) :
v.groupSMul w i = (w • (v : ι → M)) i :=
mk_apply (LinearIndependent.group_smul v.linearIndependent w)
(groupSMul_span_eq_top v.span_eq).ge i
theorem units_smul_span_eq_top {v : ι → M} (hv : Submodule.span R (Set.range v) = ⊤) {w : ι → Rˣ} :
Submodule.span R (Set.range (w • v)) = ⊤ :=
groupSMul_span_eq_top hv
/-- Given a basis `v` and a map `w` such that for all `i`, `w i` is a unit, `unitsSMul`
provides the basis corresponding to `w • v`. -/
def unitsSMul (v : Basis ι R M) (w : ι → Rˣ) : Basis ι R M :=
Basis.mk (LinearIndependent.units_smul v.linearIndependent w)
(units_smul_span_eq_top v.span_eq).ge
theorem unitsSMul_apply {v : Basis ι R M} {w : ι → Rˣ} (i : ι) : unitsSMul v w i = w i • v i :=
mk_apply (LinearIndependent.units_smul v.linearIndependent w)
(units_smul_span_eq_top v.span_eq).ge i
@[simp]
theorem coord_unitsSMul (e : Basis ι R₂ M) (w : ι → R₂ˣ) (i : ι) :
(unitsSMul e w).coord i = (w i)⁻¹ • e.coord i := by
classical
apply e.ext
intro j
trans ((unitsSMul e w).coord i) ((w j)⁻¹ • (unitsSMul e w) j)
· congr
simp [Basis.unitsSMul, ← mul_smul]
simp only [Basis.coord_apply, LinearMap.smul_apply, Basis.repr_self, Units.smul_def,
map_smul, Finsupp.single_apply]
split_ifs with h <;> simp [h]
@[simp]
theorem repr_unitsSMul (e : Basis ι R₂ M) (w : ι → R₂ˣ) (v : M) (i : ι) :
(e.unitsSMul w).repr v i = (w i)⁻¹ • e.repr v i :=
congr_arg (fun f : M →ₗ[R₂] R₂ => f v) (e.coord_unitsSMul w i)
/-- A version of `unitsSMul` that uses `IsUnit`. -/
def isUnitSMul (v : Basis ι R M) {w : ι → R} (hw : ∀ i, IsUnit (w i)) : Basis ι R M :=
unitsSMul v fun i => (hw i).unit
theorem isUnitSMul_apply {v : Basis ι R M} {w : ι → R} (hw : ∀ i, IsUnit (w i)) (i : ι) :
v.isUnitSMul hw i = w i • v i :=
unitsSMul_apply i
section Fin
/-- Let `b` be a basis for a submodule `N` of `M`. If `y : M` is linear independent of `N`
and `y` and `N` together span the whole of `M`, then there is a basis for `M`
whose basis vectors are given by `Fin.cons y b`. -/
noncomputable def mkFinCons {n : ℕ} {N : Submodule R M} (y : M) (b : Basis (Fin n) R N)
(hli : ∀ (c : R), ∀ x ∈ N, c • y + x = 0 → c = 0) (hsp : ∀ z : M, ∃ c : R, z + c • y ∈ N) :
Basis (Fin (n + 1)) R M :=
have span_b : Submodule.span R (Set.range (N.subtype ∘ b)) = N := by
rw [Set.range_comp, Submodule.span_image, b.span_eq, Submodule.map_subtype_top]
Basis.mk (v := Fin.cons y (N.subtype ∘ b))
((b.linearIndependent.map' N.subtype (Submodule.ker_subtype _)).fin_cons' _ _
(by
rintro c ⟨x, hx⟩ hc
rw [span_b] at hx
exact hli c x hx hc))
fun x _ => by
rw [Fin.range_cons, Submodule.mem_span_insert', span_b]
exact hsp x
@[simp]
theorem coe_mkFinCons {n : ℕ} {N : Submodule R M} (y : M) (b : Basis (Fin n) R N)
(hli : ∀ (c : R), ∀ x ∈ N, c • y + x = 0 → c = 0) (hsp : ∀ z : M, ∃ c : R, z + c • y ∈ N) :
(mkFinCons y b hli hsp : Fin (n + 1) → M) = Fin.cons y ((↑) ∘ b) := by
-- Porting note: without `unfold`, Lean can't reuse the proofs included in the definition
-- `mkFinCons`
unfold mkFinCons
exact coe_mk (v := Fin.cons y (N.subtype ∘ b)) _ _
/-- Let `b` be a basis for a submodule `N ≤ O`. If `y ∈ O` is linear independent of `N`
and `y` and `N` together span the whole of `O`, then there is a basis for `O`
whose basis vectors are given by `Fin.cons y b`. -/
noncomputable def mkFinConsOfLE {n : ℕ} {N O : Submodule R M} (y : M) (yO : y ∈ O)
(b : Basis (Fin n) R N) (hNO : N ≤ O) (hli : ∀ (c : R), ∀ x ∈ N, c • y + x = 0 → c = 0)
(hsp : ∀ z ∈ O, ∃ c : R, z + c • y ∈ N) : Basis (Fin (n + 1)) R O :=
mkFinCons ⟨y, yO⟩ (b.map (Submodule.comapSubtypeEquivOfLe hNO).symm)
(fun c x hc hx => hli c x (Submodule.mem_comap.mp hc) (congr_arg ((↑) : O → M) hx))
fun z => hsp z z.2
@[simp]
theorem coe_mkFinConsOfLE {n : ℕ} {N O : Submodule R M} (y : M) (yO : y ∈ O) (b : Basis (Fin n) R N)
(hNO : N ≤ O) (hli : ∀ (c : R), ∀ x ∈ N, c • y + x = 0 → c = 0)
(hsp : ∀ z ∈ O, ∃ c : R, z + c • y ∈ N) :
(mkFinConsOfLE y yO b hNO hli hsp : Fin (n + 1) → O) =
Fin.cons ⟨y, yO⟩ (Submodule.inclusion hNO ∘ b) :=
coe_mkFinCons _ _ _ _
/-- The basis of `R × R` given by the two vectors `(1, 0)` and `(0, 1)`. -/
protected def finTwoProd (R : Type*) [Semiring R] : Basis (Fin 2) R (R × R) :=
Basis.ofEquivFun (LinearEquiv.finTwoArrow R R).symm
@[simp]
theorem finTwoProd_zero (R : Type*) [Semiring R] : Basis.finTwoProd R 0 = (1, 0) := by
simp [Basis.finTwoProd, LinearEquiv.finTwoArrow]
@[simp]
theorem finTwoProd_one (R : Type*) [Semiring R] : Basis.finTwoProd R 1 = (0, 1) := by
simp [Basis.finTwoProd, LinearEquiv.finTwoArrow]
@[simp]
theorem coe_finTwoProd_repr {R : Type*} [Semiring R] (x : R × R) :
⇑((Basis.finTwoProd R).repr x) = ![x.fst, x.snd] :=
rfl
end Fin
end Basis
end Module
section Induction
variable [Ring R] [IsDomain R]
variable [AddCommGroup M] [Module R M] {b : ι → M}
/-- If `N` is a submodule with finite rank, do induction on adjoining a linear independent
element to a submodule. -/
def Submodule.inductionOnRankAux (b : Basis ι R M) (P : Submodule R M → Sort*)
(ih : ∀ N : Submodule R M,
(∀ N' ≤ N, ∀ x ∈ N, (∀ (c : R), ∀ y ∈ N', c • x + y = (0 : M) → c = 0) → P N') → P N)
(n : ℕ) (N : Submodule R M)
(rank_le : ∀ {m : ℕ} (v : Fin m → N), LinearIndependent R ((↑) ∘ v : Fin m → M) → m ≤ n) :
P N := by
haveI : DecidableEq M := Classical.decEq M
have Pbot : P ⊥ := by
apply ih
intro N _ x x_mem x_ortho
exfalso
rw [mem_bot] at x_mem
simpa [x_mem] using x_ortho 1 0 N.zero_mem
induction' n with n rank_ih generalizing N
· suffices N = ⊥ by rwa [this]
apply Basis.eq_bot_of_rank_eq_zero b _ fun m hv => Nat.le_zero.mp (rank_le _ hv)
apply ih
intro N' N'_le x x_mem x_ortho
apply rank_ih
intro m v hli
refine Nat.succ_le_succ_iff.mp (rank_le (Fin.cons ⟨x, x_mem⟩ fun i => ⟨v i, N'_le (v i).2⟩) ?_)
convert hli.fin_cons' x _ ?_
· ext i
refine Fin.cases ?_ ?_ i <;> simp
· intro c y hcy
refine x_ortho c y (Submodule.span_le.mpr ?_ y.2) hcy
rintro _ ⟨z, rfl⟩
exact (v z).2
end Induction
/-- An element of a non-unital-non-associative algebra is in the center exactly when it commutes
with the basis elements. -/
lemma Basis.mem_center_iff {A}
[Semiring R] [NonUnitalNonAssocSemiring A]
[Module R A] [SMulCommClass R A A] [SMulCommClass R R A] [IsScalarTower R A A]
(b : Basis ι R A) {z : A} :
z ∈ Set.center A ↔
(∀ i, Commute (b i) z) ∧ ∀ i j,
z * (b i * b j) = (z * b i) * b j
∧ (b i * z) * b j = b i * (z * b j)
∧ (b i * b j) * z = b i * (b j * z) := by
constructor
· intro h
constructor
· intro i
apply (h.1 (b i)).symm
· intros
exact ⟨h.2 _ _, ⟨h.3 _ _, h.4 _ _⟩⟩
· intro h
rw [center, mem_setOf_eq]
constructor
case comm =>
intro y
rw [← b.total_repr y, Finsupp.total_apply, Finsupp.sum, Finset.sum_mul, Finset.mul_sum]
simp_rw [mul_smul_comm, smul_mul_assoc, (h.1 _).eq]
case left_assoc =>
intro c d
rw [← b.total_repr c, ← b.total_repr d, Finsupp.total_apply, Finsupp.total_apply, Finsupp.sum,
Finsupp.sum, Finset.sum_mul, Finset.mul_sum, Finset.mul_sum, Finset.mul_sum]
simp_rw [smul_mul_assoc, Finset.mul_sum, Finset.sum_mul, mul_smul_comm, Finset.mul_sum,
Finset.smul_sum, smul_mul_assoc, mul_smul_comm, (h.2 _ _).1,
(@SMulCommClass.smul_comm R R A)]
rw [Finset.sum_comm]
case mid_assoc =>
intro c d
rw [← b.total_repr c, ← b.total_repr d, Finsupp.total_apply, Finsupp.total_apply, Finsupp.sum,
Finsupp.sum, Finset.sum_mul, Finset.mul_sum, Finset.mul_sum, Finset.mul_sum]
simp_rw [smul_mul_assoc, Finset.sum_mul, mul_smul_comm, smul_mul_assoc, (h.2 _ _).2.1]
case right_assoc =>
intro c d
rw [← b.total_repr c, ← b.total_repr d, Finsupp.total_apply, Finsupp.total_apply, Finsupp.sum,
Finsupp.sum, Finset.sum_mul]
simp_rw [smul_mul_assoc, Finset.mul_sum, Finset.sum_mul, mul_smul_comm, Finset.mul_sum,
Finset.smul_sum, smul_mul_assoc, mul_smul_comm, Finset.sum_mul, smul_mul_assoc,
(h.2 _ _).2.2]
section RestrictScalars
variable {S : Type*} [CommRing R] [Ring S] [Nontrivial S] [AddCommGroup M]
variable [Algebra R S] [Module S M] [Module R M]
variable [IsScalarTower R S M] [NoZeroSMulDivisors R S] (b : Basis ι S M)
variable (R)
open Submodule
/-- Let `b` be an `S`-basis of `M`. Let `R` be a CommRing such that `Algebra R S` has no zero smul
divisors, then the submodule of `M` spanned by `b` over `R` admits `b` as an `R`-basis. -/
noncomputable def Basis.restrictScalars : Basis ι R (span R (Set.range b)) :=
Basis.span (b.linearIndependent.restrict_scalars (smul_left_injective R one_ne_zero))
@[simp]
theorem Basis.restrictScalars_apply (i : ι) : (b.restrictScalars R i : M) = b i := by
simp only [Basis.restrictScalars, Basis.span_apply]
@[simp]
theorem Basis.restrictScalars_repr_apply (m : span R (Set.range b)) (i : ι) :
algebraMap R S ((b.restrictScalars R).repr m i) = b.repr m i := by
suffices
Finsupp.mapRange.linearMap (Algebra.linearMap R S) ∘ₗ (b.restrictScalars R).repr.toLinearMap =
((b.repr : M →ₗ[S] ι →₀ S).restrictScalars R).domRestrict _
by exact DFunLike.congr_fun (LinearMap.congr_fun this m) i
refine Basis.ext (b.restrictScalars R) fun _ => ?_
simp only [LinearMap.coe_comp, LinearEquiv.coe_toLinearMap, Function.comp_apply, map_one,
Basis.repr_self, Finsupp.mapRange.linearMap_apply, Finsupp.mapRange_single,
Algebra.linearMap_apply, LinearMap.domRestrict_apply, LinearEquiv.coe_coe,
Basis.restrictScalars_apply, LinearMap.coe_restrictScalars]
/-- Let `b` be an `S`-basis of `M`. Then `m : M` lies in the `R`-module spanned by `b` iff all the
coordinates of `m` on the basis `b` are in `R` (see `Basis.mem_span` for the case `R = S`). -/
theorem Basis.mem_span_iff_repr_mem (m : M) :
m ∈ span R (Set.range b) ↔ ∀ i, b.repr m i ∈ Set.range (algebraMap R S) := by
refine
⟨fun hm i => ⟨(b.restrictScalars R).repr ⟨m, hm⟩ i, b.restrictScalars_repr_apply R ⟨m, hm⟩ i⟩,
fun h => ?_⟩
rw [← b.total_repr m, Finsupp.total_apply S _]
refine sum_mem fun i _ => ?_
obtain ⟨_, h⟩ := h i
simp_rw [← h, algebraMap_smul]
exact smul_mem _ _ (subset_span (Set.mem_range_self i))
end RestrictScalars
section Finite
open Basis Cardinal
universe v v' v'' u₁' w w'
variable {R : Type u} {M M₁ : Type v} {M' : Type v'} {ι : Type w}
variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁] [Nontrivial R]
variable [Module R M] [Module R M'] [Module R M₁]
-- One might hope that a finite spanning set implies that any linearly independent set is finite.
-- While this is true over a division ring
-- (simply because any linearly independent set can be extended to a basis),
-- or more generally over a ring satisfying the strong rank condition
-- (which covers all commutative rings; see `LinearIndependent.finite_of_le_span_finite`),
-- this is not true in general.
-- For example, the left ideal generated by the variables in a noncommutative polynomial ring
-- (`FreeAlgebra R ι`) in infinitely many variables (indexed by `ι`) is free
-- with an infinite basis (consisting of the variables).
-- As another example, for any commutative ring R, the ring of column-finite matrices
-- `Module.End R (ℕ →₀ R)` is isomorphic to `ℕ → Module.End R (ℕ →₀ R)` as a module over itself,
-- which also clearly contains an infinite linearly independent set.
/--
Over any nontrivial ring, the existence of a finite spanning set implies that any basis is finite.
-/
lemma basis_finite_of_finite_spans (w : Set M) (hw : w.Finite) (s : span R w = ⊤) {ι : Type w}
(b : Basis ι R M) : Finite ι := by
classical
haveI := hw.to_subtype
cases nonempty_fintype w
-- We'll work by contradiction, assuming `ι` is infinite.
rw [← not_infinite_iff_finite]
intro i
-- Let `S` be the union of the supports of `x ∈ w` expressed as linear combinations of `b`.
-- This is a finite set since `w` is finite.
let S : Finset ι := Finset.univ.sup fun x : w => (b.repr x).support
let bS : Set M := b '' S
have h : ∀ x ∈ w, x ∈ span R bS := by
intro x m
rw [← b.total_repr x, Finsupp.span_image_eq_map_total, Submodule.mem_map]
use b.repr x
simp only [and_true_iff, eq_self_iff_true, Finsupp.mem_supported]
rw [Finset.coe_subset, ← Finset.le_iff_subset]
exact Finset.le_sup (f := fun x : w ↦ (b.repr ↑x).support) (Finset.mem_univ (⟨x, m⟩ : w))
-- Thus this finite subset of the basis elements spans the entire module.
have k : span R bS = ⊤ := eq_top_iff.2 (le_trans s.ge (span_le.2 h))
-- Now there is some `x : ι` not in `S`, since `ι` is infinite.
obtain ⟨x, nm⟩ := Infinite.exists_not_mem_finset S
-- However it must be in the span of the finite subset,
have k' : b x ∈ span R bS := by
rw [k]
exact mem_top
-- giving the desire contradiction.
exact b.linearIndependent.not_mem_span_image nm k'
-- From [Les familles libres maximales d'un module ont-elles le meme cardinal?][lazarus1973]
/-- Over any ring `R`, if `b` is a basis for a module `M`,
and `s` is a maximal linearly independent set,
then the union of the supports of `x ∈ s` (when written out in the basis `b`) is all of `b`.
-/
theorem union_support_maximal_linearIndependent_eq_range_basis {ι : Type w} (b : Basis ι R M)
{κ : Type w'} (v : κ → M) (i : LinearIndependent R v) (m : i.Maximal) :
⋃ k, ((b.repr (v k)).support : Set ι) = Set.univ := by
-- If that's not the case,
by_contra h
simp only [← Ne.eq_def, ne_univ_iff_exists_not_mem, mem_iUnion, not_exists_not,
Finsupp.mem_support_iff, Finset.mem_coe] at h
-- We have some basis element `b b'` which is not in the support of any of the `v i`.
obtain ⟨b', w⟩ := h
-- Using this, we'll construct a linearly independent family strictly larger than `v`,
-- by also using this `b b'`.
let v' : Option κ → M := fun o => o.elim (b b') v
have r : range v ⊆ range v' := by
rintro - ⟨k, rfl⟩
use some k
simp only [v', Option.elim_some]
have r' : b b' ∉ range v := by
rintro ⟨k, p⟩
simpa [w] using congr_arg (fun m => (b.repr m) b') p
have r'' : range v ≠ range v' := by
intro e
have p : b b' ∈ range v' := by
use none
simp only [v', Option.elim_none]
rw [← e] at p
exact r' p
-- The key step in the proof is checking that this strictly larger family is linearly independent.
have i' : LinearIndependent R ((↑) : range v' → M) := by
apply LinearIndependent.to_subtype_range
rw [linearIndependent_iff]
intro l z
rw [Finsupp.total_option] at z
simp only [v', Option.elim'] at z
change _ + Finsupp.total κ M R v l.some = 0 at z
-- We have some linear combination of `b b'` and the `v i`, which we want to show is trivial.
-- We'll first show the coefficient of `b b'` is zero,
-- by expressing the `v i` in the basis `b`, and using that the `v i` have no `b b'` term.
have l₀ : l none = 0 := by
rw [← eq_neg_iff_add_eq_zero] at z
replace z := neg_eq_iff_eq_neg.mpr z
apply_fun fun x => b.repr x b' at z
simp only [repr_self, map_smul, mul_one, Finsupp.single_eq_same, Pi.neg_apply,
Finsupp.smul_single', map_neg, Finsupp.coe_neg] at z
erw [DFunLike.congr_fun (Finsupp.apply_total R (b.repr : M →ₗ[R] ι →₀ R) v l.some) b'] at z
simpa [Finsupp.total_apply, w] using z
-- Then all the other coefficients are zero, because `v` is linear independent.
have l₁ : l.some = 0 := by
rw [l₀, zero_smul, zero_add] at z
exact linearIndependent_iff.mp i _ z
-- Finally we put those facts together to show the linear combination is trivial.
ext (_ | a)
· simp only [l₀, Finsupp.coe_zero, Pi.zero_apply]
· erw [DFunLike.congr_fun l₁ a]
simp only [Finsupp.coe_zero, Pi.zero_apply]
rw [LinearIndependent.Maximal] at m
specialize m (range v') i' r
exact r'' m
/-- Over any ring `R`, if `b` is an infinite basis for a module `M`,
and `s` is a maximal linearly independent set,
then the cardinality of `b` is bounded by the cardinality of `s`.
-/
theorem infinite_basis_le_maximal_linearIndependent' {ι : Type w} (b : Basis ι R M) [Infinite ι]
{κ : Type w'} (v : κ → M) (i : LinearIndependent R v) (m : i.Maximal) :
Cardinal.lift.{w'} #ι ≤ Cardinal.lift.{w} #κ := by
let Φ := fun k : κ => (b.repr (v k)).support
have w₁ : #ι ≤ #(Set.range Φ) := by
apply Cardinal.le_range_of_union_finset_eq_top
exact union_support_maximal_linearIndependent_eq_range_basis b v i m
have w₂ : Cardinal.lift.{w'} #(Set.range Φ) ≤ Cardinal.lift.{w} #κ := Cardinal.mk_range_le_lift
exact (Cardinal.lift_le.mpr w₁).trans w₂
-- (See `infinite_basis_le_maximal_linearIndependent'` for the more general version
-- where the index types can live in different universes.)
/-- Over any ring `R`, if `b` is an infinite basis for a module `M`,
and `s` is a maximal linearly independent set,
then the cardinality of `b` is bounded by the cardinality of `s`.
-/
theorem infinite_basis_le_maximal_linearIndependent {ι : Type w} (b : Basis ι R M) [Infinite ι]
{κ : Type w} (v : κ → M) (i : LinearIndependent R v) (m : i.Maximal) : #ι ≤ #κ :=
Cardinal.lift_le.mp (infinite_basis_le_maximal_linearIndependent' b v i m)
end Finite
|
LinearAlgebra\BilinearMap.lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro
-/
import Mathlib.Algebra.Module.Submodule.Ker
/-!
# Basics on bilinear maps
This file provides basics on bilinear maps. The most general form considered are maps that are
semilinear in both arguments. They are of type `M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P`, where `M` and `N`
are modules over `R` and `S` respectively, `P` is a module over both `R₂` and `S₂` with
commuting actions, and `ρ₁₂ : R →+* R₂` and `σ₁₂ : S →+* S₂`.
## Main declarations
* `LinearMap.mk₂`: a constructor for bilinear maps,
taking an unbundled function together with proof witnesses of bilinearity
* `LinearMap.flip`: turns a bilinear map `M × N → P` into `N × M → P`
* `LinearMap.lcomp` and `LinearMap.llcomp`: composition of linear maps as a bilinear map
* `LinearMap.compl₂`: composition of a bilinear map `M × N → P` with a linear map `Q → M`
* `LinearMap.compr₂`: composition of a bilinear map `M × N → P` with a linear map `Q → N`
* `LinearMap.lsmul`: scalar multiplication as a bilinear map `R × M → M`
## Tags
bilinear
-/
namespace LinearMap
section Semiring
-- the `ₗ` subscript variables are for special cases about linear (as opposed to semilinear) maps
variable {R : Type*} [Semiring R] {S : Type*} [Semiring S]
variable {R₂ : Type*} [Semiring R₂] {S₂ : Type*} [Semiring S₂]
variable {M : Type*} {N : Type*} {P : Type*}
variable {M₂ : Type*} {N₂ : Type*} {P₂ : Type*}
variable {Nₗ : Type*} {Pₗ : Type*}
variable {M' : Type*} {N' : Type*} {P' : Type*}
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P]
variable [AddCommMonoid M₂] [AddCommMonoid N₂] [AddCommMonoid P₂]
variable [AddCommMonoid Nₗ] [AddCommMonoid Pₗ]
variable [AddCommGroup M'] [AddCommGroup N'] [AddCommGroup P']
variable [Module R M] [Module S N] [Module R₂ P] [Module S₂ P]
variable [Module R M₂] [Module S N₂] [Module R P₂] [Module S₂ P₂]
variable [Module R Pₗ] [Module S Pₗ]
variable [Module R M'] [Module S N'] [Module R₂ P'] [Module S₂ P']
variable [SMulCommClass S₂ R₂ P] [SMulCommClass S R Pₗ] [SMulCommClass S₂ R₂ P']
variable [SMulCommClass S₂ R P₂]
variable {ρ₁₂ : R →+* R₂} {σ₁₂ : S →+* S₂}
variable (ρ₁₂ σ₁₂)
/-- Create a bilinear map from a function that is semilinear in each component.
See `mk₂'` and `mk₂` for the linear case. -/
def mk₂'ₛₗ (f : M → N → P) (H1 : ∀ m₁ m₂ n, f (m₁ + m₂) n = f m₁ n + f m₂ n)
(H2 : ∀ (c : R) (m n), f (c • m) n = ρ₁₂ c • f m n)
(H3 : ∀ m n₁ n₂, f m (n₁ + n₂) = f m n₁ + f m n₂)
(H4 : ∀ (c : S) (m n), f m (c • n) = σ₁₂ c • f m n) : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P where
toFun m :=
{ toFun := f m
map_add' := H3 m
map_smul' := fun c => H4 c m }
map_add' m₁ m₂ := LinearMap.ext <| H1 m₁ m₂
map_smul' c m := LinearMap.ext <| H2 c m
variable {ρ₁₂ σ₁₂}
@[simp]
theorem mk₂'ₛₗ_apply (f : M → N → P) {H1 H2 H3 H4} (m : M) (n : N) :
(mk₂'ₛₗ ρ₁₂ σ₁₂ f H1 H2 H3 H4 : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P) m n = f m n := rfl
variable (R S)
/-- Create a bilinear map from a function that is linear in each component.
See `mk₂` for the special case where both arguments come from modules over the same ring. -/
def mk₂' (f : M → N → Pₗ) (H1 : ∀ m₁ m₂ n, f (m₁ + m₂) n = f m₁ n + f m₂ n)
(H2 : ∀ (c : R) (m n), f (c • m) n = c • f m n)
(H3 : ∀ m n₁ n₂, f m (n₁ + n₂) = f m n₁ + f m n₂)
(H4 : ∀ (c : S) (m n), f m (c • n) = c • f m n) : M →ₗ[R] N →ₗ[S] Pₗ :=
mk₂'ₛₗ (RingHom.id R) (RingHom.id S) f H1 H2 H3 H4
variable {R S}
@[simp]
theorem mk₂'_apply (f : M → N → Pₗ) {H1 H2 H3 H4} (m : M) (n : N) :
(mk₂' R S f H1 H2 H3 H4 : M →ₗ[R] N →ₗ[S] Pₗ) m n = f m n := rfl
theorem ext₂ {f g : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P} (H : ∀ m n, f m n = g m n) : f = g :=
LinearMap.ext fun m => LinearMap.ext fun n => H m n
theorem congr_fun₂ {f g : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P} (h : f = g) (x y) : f x y = g x y :=
LinearMap.congr_fun (LinearMap.congr_fun h x) y
theorem ext_iff₂ {f g : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P} : f = g ↔ ∀ m n, f m n = g m n :=
⟨congr_fun₂, ext₂⟩
section
attribute [local instance] SMulCommClass.symm
/-- Given a linear map from `M` to linear maps from `N` to `P`, i.e., a bilinear map from `M × N` to
`P`, change the order of variables and get a linear map from `N` to linear maps from `M` to `P`. -/
def flip (f : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P) : N →ₛₗ[σ₁₂] M →ₛₗ[ρ₁₂] P :=
mk₂'ₛₗ σ₁₂ ρ₁₂ (fun n m => f m n) (fun n₁ n₂ m => (f m).map_add _ _)
(fun c n m => (f m).map_smulₛₗ _ _)
(fun n m₁ m₂ => by simp only [map_add, add_apply])
-- Note: #8386 changed `map_smulₛₗ` into `map_smulₛₗ _`.
-- It looks like we now run out of assignable metavariables.
(fun c n m => by simp only [map_smulₛₗ _, smul_apply])
end
@[simp]
theorem flip_apply (f : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P) (m : M) (n : N) : flip f n m = f m n := rfl
attribute [local instance] SMulCommClass.symm
@[simp]
theorem flip_flip (f : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P) : f.flip.flip = f :=
LinearMap.ext₂ fun _x _y => (f.flip.flip_apply _ _).trans (f.flip_apply _ _)
theorem flip_inj {f g : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P} (H : flip f = flip g) : f = g :=
ext₂ fun m n => show flip f n m = flip g n m by rw [H]
theorem map_zero₂ (f : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P) (y) : f 0 y = 0 :=
(flip f y).map_zero
theorem map_neg₂ (f : M' →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P') (x y) : f (-x) y = -f x y :=
(flip f y).map_neg _
theorem map_sub₂ (f : M' →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P') (x y z) : f (x - y) z = f x z - f y z :=
(flip f z).map_sub _ _
theorem map_add₂ (f : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P) (x₁ x₂ y) : f (x₁ + x₂) y = f x₁ y + f x₂ y :=
(flip f y).map_add _ _
theorem map_smul₂ (f : M₂ →ₗ[R] N₂ →ₛₗ[σ₁₂] P₂) (r : R) (x y) : f (r • x) y = r • f x y :=
(flip f y).map_smul _ _
theorem map_smulₛₗ₂ (f : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P) (r : R) (x y) : f (r • x) y = ρ₁₂ r • f x y :=
(flip f y).map_smulₛₗ _ _
theorem map_sum₂ {ι : Type*} (f : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P) (t : Finset ι) (x : ι → M) (y) :
f (∑ i ∈ t, x i) y = ∑ i ∈ t, f (x i) y :=
_root_.map_sum (flip f y) _ _
/-- Restricting a bilinear map in the second entry -/
def domRestrict₂ (f : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P) (q : Submodule S N) : M →ₛₗ[ρ₁₂] q →ₛₗ[σ₁₂] P where
toFun m := (f m).domRestrict q
map_add' m₁ m₂ := LinearMap.ext fun _ => by simp only [map_add, domRestrict_apply, add_apply]
map_smul' c m :=
LinearMap.ext fun _ => by simp only [f.map_smulₛₗ, domRestrict_apply, smul_apply]
theorem domRestrict₂_apply (f : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P) (q : Submodule S N) (x : M) (y : q) :
f.domRestrict₂ q x y = f x y := rfl
/-- Restricting a bilinear map in both components -/
def domRestrict₁₂ (f : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P) (p : Submodule R M) (q : Submodule S N) :
p →ₛₗ[ρ₁₂] q →ₛₗ[σ₁₂] P :=
(f.domRestrict p).domRestrict₂ q
theorem domRestrict₁₂_apply (f : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P) (p : Submodule R M) (q : Submodule S N)
(x : p) (y : q) : f.domRestrict₁₂ p q x y = f x y := rfl
section restrictScalars
variable (R' S' : Type*)
variable [Semiring R'] [Semiring S'] [Module R' M] [Module S' N] [Module R' Pₗ] [Module S' Pₗ]
variable [SMulCommClass S' R' Pₗ]
variable [SMul S' S] [IsScalarTower S' S N] [IsScalarTower S' S Pₗ]
variable [SMul R' R] [IsScalarTower R' R M] [IsScalarTower R' R Pₗ]
/-- If `B : M → N → Pₗ` is `R`-`S` bilinear and `R'` and `S'` are compatible scalar multiplications,
then the restriction of scalars is a `R'`-`S'` bilinear map. -/
@[simps!]
def restrictScalars₁₂ (B : M →ₗ[R] N →ₗ[S] Pₗ) : M →ₗ[R'] N →ₗ[S'] Pₗ :=
LinearMap.mk₂' R' S'
(B · ·)
B.map_add₂
(fun r' m _ ↦ by
dsimp only
rw [← smul_one_smul R r' m, map_smul₂, smul_one_smul])
(fun _ ↦ map_add _)
(fun _ x ↦ (B x).map_smul_of_tower _)
theorem restrictScalars₁₂_injective : Function.Injective
(LinearMap.restrictScalars₁₂ R' S' : (M →ₗ[R] N →ₗ[S] Pₗ) → (M →ₗ[R'] N →ₗ[S'] Pₗ)) :=
fun _ _ h ↦ ext₂ (congr_fun₂ h : _)
@[simp]
theorem restrictScalars₁₂_inj {B B' : M →ₗ[R] N →ₗ[S] Pₗ} :
B.restrictScalars₁₂ R' S' = B'.restrictScalars₁₂ R' S' ↔ B = B' :=
(restrictScalars₁₂_injective R' S').eq_iff
end restrictScalars
end Semiring
section CommSemiring
variable {R : Type*} [CommSemiring R] {R₂ : Type*} [CommSemiring R₂]
variable {R₃ : Type*} [CommSemiring R₃] {R₄ : Type*} [CommSemiring R₄]
variable {M : Type*} {N : Type*} {P : Type*} {Q : Type*}
variable {Mₗ : Type*} {Nₗ : Type*} {Pₗ : Type*} {Qₗ Qₗ' : Type*}
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q]
variable [AddCommMonoid Mₗ] [AddCommMonoid Nₗ] [AddCommMonoid Pₗ]
variable [AddCommMonoid Qₗ] [AddCommMonoid Qₗ']
variable [Module R M] [Module R₂ N] [Module R₃ P] [Module R₄ Q]
variable [Module R Mₗ] [Module R Nₗ] [Module R Pₗ] [Module R Qₗ] [Module R Qₗ']
variable {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃}
variable {σ₄₂ : R₄ →+* R₂} {σ₄₃ : R₄ →+* R₃}
variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [RingHomCompTriple σ₄₂ σ₂₃ σ₄₃]
variable (R)
/-- Create a bilinear map from a function that is linear in each component.
This is a shorthand for `mk₂'` for the common case when `R = S`. -/
def mk₂ (f : M → Nₗ → Pₗ) (H1 : ∀ m₁ m₂ n, f (m₁ + m₂) n = f m₁ n + f m₂ n)
(H2 : ∀ (c : R) (m n), f (c • m) n = c • f m n)
(H3 : ∀ m n₁ n₂, f m (n₁ + n₂) = f m n₁ + f m n₂)
(H4 : ∀ (c : R) (m n), f m (c • n) = c • f m n) : M →ₗ[R] Nₗ →ₗ[R] Pₗ :=
mk₂' R R f H1 H2 H3 H4
@[simp]
theorem mk₂_apply (f : M → Nₗ → Pₗ) {H1 H2 H3 H4} (m : M) (n : Nₗ) :
(mk₂ R f H1 H2 H3 H4 : M →ₗ[R] Nₗ →ₗ[R] Pₗ) m n = f m n := rfl
variable {R}
/-- Given a linear map from `M` to linear maps from `N` to `P`, i.e., a bilinear map `M → N → P`,
change the order of variables and get a linear map from `N` to linear maps from `M` to `P`. -/
def lflip : (M →ₛₗ[σ₁₃] N →ₛₗ[σ₂₃] P) →ₗ[R₃] N →ₛₗ[σ₂₃] M →ₛₗ[σ₁₃] P where
toFun := flip
map_add' _ _ := rfl
map_smul' _ _ := rfl
variable (f : M →ₛₗ[σ₁₃] N →ₛₗ[σ₂₃] P)
@[simp]
theorem lflip_apply (m : M) (n : N) : lflip f n m = f m n := rfl
variable (R Pₗ)
/-- Composing a linear map `M → N` and a linear map `N → P` to form a linear map `M → P`. -/
def lcomp (f : M →ₗ[R] Nₗ) : (Nₗ →ₗ[R] Pₗ) →ₗ[R] M →ₗ[R] Pₗ :=
flip <| LinearMap.comp (flip id) f
variable {R Pₗ}
@[simp]
theorem lcomp_apply (f : M →ₗ[R] Nₗ) (g : Nₗ →ₗ[R] Pₗ) (x : M) : lcomp _ _ f g x = g (f x) := rfl
theorem lcomp_apply' (f : M →ₗ[R] Nₗ) (g : Nₗ →ₗ[R] Pₗ) : lcomp R Pₗ f g = g ∘ₗ f := rfl
variable (P σ₂₃)
/-- Composing a semilinear map `M → N` and a semilinear map `N → P` to form a semilinear map
`M → P` is itself a linear map. -/
def lcompₛₗ (f : M →ₛₗ[σ₁₂] N) : (N →ₛₗ[σ₂₃] P) →ₗ[R₃] M →ₛₗ[σ₁₃] P :=
flip <| LinearMap.comp (flip id) f
variable {P σ₂₃}
@[simp]
theorem lcompₛₗ_apply (f : M →ₛₗ[σ₁₂] N) (g : N →ₛₗ[σ₂₃] P) (x : M) :
lcompₛₗ P σ₂₃ f g x = g (f x) := rfl
variable (R M Nₗ Pₗ)
/-- Composing a linear map `M → N` and a linear map `N → P` to form a linear map `M → P`. -/
def llcomp : (Nₗ →ₗ[R] Pₗ) →ₗ[R] (M →ₗ[R] Nₗ) →ₗ[R] M →ₗ[R] Pₗ :=
flip
{ toFun := lcomp R Pₗ
map_add' := fun _f _f' => ext₂ fun g _x => g.map_add _ _
map_smul' := fun (_c : R) _f => ext₂ fun g _x => g.map_smul _ _ }
variable {R M Nₗ Pₗ}
section
@[simp]
theorem llcomp_apply (f : Nₗ →ₗ[R] Pₗ) (g : M →ₗ[R] Nₗ) (x : M) :
llcomp R M Nₗ Pₗ f g x = f (g x) := rfl
theorem llcomp_apply' (f : Nₗ →ₗ[R] Pₗ) (g : M →ₗ[R] Nₗ) : llcomp R M Nₗ Pₗ f g = f ∘ₗ g := rfl
end
/-- Composing a linear map `Q → N` and a bilinear map `M → N → P` to
form a bilinear map `M → Q → P`. -/
def compl₂ {R₅ : Type*} [CommSemiring R₅] [Module R₅ P] [SMulCommClass R₃ R₅ P] {σ₁₅ : R →+* R₅}
(h : M →ₛₗ[σ₁₅] N →ₛₗ[σ₂₃] P) (g : Q →ₛₗ[σ₄₂] N) : M →ₛₗ[σ₁₅] Q →ₛₗ[σ₄₃] P where
toFun a := (lcompₛₗ P σ₂₃ g) (h a)
map_add' _ _ := by
simp [map_add]
map_smul' _ _ := by
simp only [LinearMap.map_smulₛₗ, lcompₛₗ]
rfl
@[simp]
theorem compl₂_apply (g : Q →ₛₗ[σ₄₂] N) (m : M) (q : Q) : f.compl₂ g m q = f m (g q) := rfl
@[simp]
theorem compl₂_id : f.compl₂ LinearMap.id = f := by
ext
rw [compl₂_apply, id_coe, _root_.id]
/-- Composing linear maps `Q → M` and `Q' → N` with a bilinear map `M → N → P` to
form a bilinear map `Q → Q' → P`. -/
def compl₁₂ {R₁ : Type*} [CommSemiring R₁] [Module R₂ N] [Module R₂ Pₗ] [Module R₁ Pₗ]
[Module R₁ Mₗ] [SMulCommClass R₂ R₁ Pₗ] [Module R₁ Qₗ] [Module R₂ Qₗ']
(f : Mₗ →ₗ[R₁] N →ₗ[R₂] Pₗ) (g : Qₗ →ₗ[R₁] Mₗ) (g' : Qₗ' →ₗ[R₂] N) :
Qₗ →ₗ[R₁] Qₗ' →ₗ[R₂] Pₗ :=
(f.comp g).compl₂ g'
@[simp]
theorem compl₁₂_apply (f : Mₗ →ₗ[R] Nₗ →ₗ[R] Pₗ) (g : Qₗ →ₗ[R] Mₗ) (g' : Qₗ' →ₗ[R] Nₗ) (x : Qₗ)
(y : Qₗ') : f.compl₁₂ g g' x y = f (g x) (g' y) := rfl
@[simp]
theorem compl₁₂_id_id (f : Mₗ →ₗ[R] Nₗ →ₗ[R] Pₗ) : f.compl₁₂ LinearMap.id LinearMap.id = f := by
ext
simp_rw [compl₁₂_apply, id_coe, _root_.id]
theorem compl₁₂_inj {f₁ f₂ : Mₗ →ₗ[R] Nₗ →ₗ[R] Pₗ} {g : Qₗ →ₗ[R] Mₗ} {g' : Qₗ' →ₗ[R] Nₗ}
(hₗ : Function.Surjective g) (hᵣ : Function.Surjective g') :
f₁.compl₁₂ g g' = f₂.compl₁₂ g g' ↔ f₁ = f₂ := by
constructor <;> intro h
· -- B₁.comp l r = B₂.comp l r → B₁ = B₂
ext x y
cases' hₗ x with x' hx
subst hx
cases' hᵣ y with y' hy
subst hy
convert LinearMap.congr_fun₂ h x' y' using 0
· -- B₁ = B₂ → B₁.comp l r = B₂.comp l r
subst h; rfl
/-- Composing a linear map `P → Q` and a bilinear map `M → N → P` to
form a bilinear map `M → N → Q`. -/
def compr₂ (f : M →ₗ[R] Nₗ →ₗ[R] Pₗ) (g : Pₗ →ₗ[R] Qₗ) : M →ₗ[R] Nₗ →ₗ[R] Qₗ :=
llcomp R Nₗ Pₗ Qₗ g ∘ₗ f
@[simp]
theorem compr₂_apply (f : M →ₗ[R] Nₗ →ₗ[R] Pₗ) (g : Pₗ →ₗ[R] Qₗ) (m : M) (n : Nₗ) :
f.compr₂ g m n = g (f m n) := rfl
variable (R M)
/-- Scalar multiplication as a bilinear map `R → M → M`. -/
def lsmul : R →ₗ[R] M →ₗ[R] M :=
mk₂ R (· • ·) add_smul (fun _ _ _ => mul_smul _ _ _) smul_add fun r s m => by
simp only [smul_smul, smul_eq_mul, mul_comm]
variable {R}
lemma lsmul_eq_DistribMulAction_toLinearMap (r : R) :
lsmul R M r = DistribMulAction.toLinearMap R M r := rfl
variable {M}
@[simp]
theorem lsmul_apply (r : R) (m : M) : lsmul R M r m = r • m := rfl
variable (R M Nₗ) in
/-- A shorthand for the type of `R`-bilinear `Nₗ`-valued maps on `M`. -/
protected abbrev BilinMap : Type _ := M →ₗ[R] M →ₗ[R] Nₗ
variable (R M) in
/-- For convenience, a shorthand for the type of bilinear forms from `M` to `R`. -/
protected abbrev BilinForm : Type _ := LinearMap.BilinMap R M R
end CommSemiring
section CommRing
variable {R R₂ S S₂ M N P : Type*}
variable {Mₗ Nₗ Pₗ : Type*}
variable [CommRing R] [CommRing S] [CommRing R₂] [CommRing S₂]
section AddCommGroup
variable [AddCommGroup M] [AddCommGroup N] [AddCommGroup P]
variable [Module R M] [Module S N] [Module R₂ P] [Module S₂ P]
theorem lsmul_injective [NoZeroSMulDivisors R M] {x : R} (hx : x ≠ 0) :
Function.Injective (lsmul R M x) :=
smul_right_injective _ hx
theorem ker_lsmul [NoZeroSMulDivisors R M] {a : R} (ha : a ≠ 0) :
LinearMap.ker (LinearMap.lsmul R M a) = ⊥ :=
LinearMap.ker_eq_bot_of_injective (LinearMap.lsmul_injective ha)
end AddCommGroup
end CommRing
end LinearMap
|
LinearAlgebra\Coevaluation.lean | /-
Copyright (c) 2021 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer
-/
import Mathlib.LinearAlgebra.Contraction
/-!
# The coevaluation map on finite dimensional vector spaces
Given a finite dimensional vector space `V` over a field `K` this describes the canonical linear map
from `K` to `V ⊗ Dual K V` which corresponds to the identity function on `V`.
## Tags
coevaluation, dual module, tensor product
## Future work
* Prove that this is independent of the choice of basis on `V`.
-/
noncomputable section
section coevaluation
open TensorProduct FiniteDimensional
open TensorProduct
universe u v
variable (K : Type u) [Field K]
variable (V : Type v) [AddCommGroup V] [Module K V] [FiniteDimensional K V]
/-- The coevaluation map is a linear map from a field `K` to a finite dimensional
vector space `V`. -/
def coevaluation : K →ₗ[K] V ⊗[K] Module.Dual K V :=
let bV := Basis.ofVectorSpace K V
(Basis.singleton Unit K).constr K fun _ =>
∑ i : Basis.ofVectorSpaceIndex K V, bV i ⊗ₜ[K] bV.coord i
theorem coevaluation_apply_one :
(coevaluation K V) (1 : K) =
let bV := Basis.ofVectorSpace K V
∑ i : Basis.ofVectorSpaceIndex K V, bV i ⊗ₜ[K] bV.coord i := by
simp only [coevaluation, id]
rw [(Basis.singleton Unit K).constr_apply_fintype K]
simp only [Fintype.univ_punit, Finset.sum_const, one_smul, Basis.singleton_repr,
Basis.equivFun_apply, Basis.coe_ofVectorSpace, one_nsmul, Finset.card_singleton]
open TensorProduct
/-- This lemma corresponds to one of the coherence laws for duals in rigid categories, see
`CategoryTheory.Monoidal.Rigid`. -/
theorem contractLeft_assoc_coevaluation :
(contractLeft K V).rTensor _ ∘ₗ
(TensorProduct.assoc K _ _ _).symm.toLinearMap ∘ₗ
(coevaluation K V).lTensor (Module.Dual K V) =
(TensorProduct.lid K _).symm.toLinearMap ∘ₗ (TensorProduct.rid K _).toLinearMap := by
letI := Classical.decEq (Basis.ofVectorSpaceIndex K V)
apply TensorProduct.ext
apply (Basis.ofVectorSpace K V).dualBasis.ext; intro j; apply LinearMap.ext_ring
rw [LinearMap.compr₂_apply, LinearMap.compr₂_apply, TensorProduct.mk_apply]
simp only [LinearMap.coe_comp, Function.comp_apply, LinearEquiv.coe_toLinearMap]
rw [rid_tmul, one_smul, lid_symm_apply]
simp only [LinearEquiv.coe_toLinearMap, LinearMap.lTensor_tmul, coevaluation_apply_one]
rw [TensorProduct.tmul_sum, map_sum]; simp only [assoc_symm_tmul]
rw [map_sum]; simp only [LinearMap.rTensor_tmul, contractLeft_apply]
simp only [Basis.coe_dualBasis, Basis.coord_apply, Basis.repr_self_apply, TensorProduct.ite_tmul]
rw [Finset.sum_ite_eq']; simp only [Finset.mem_univ, if_true]
/-- This lemma corresponds to one of the coherence laws for duals in rigid categories, see
`CategoryTheory.Monoidal.Rigid`. -/
theorem contractLeft_assoc_coevaluation' :
(contractLeft K V).lTensor _ ∘ₗ
(TensorProduct.assoc K _ _ _).toLinearMap ∘ₗ (coevaluation K V).rTensor V =
(TensorProduct.rid K _).symm.toLinearMap ∘ₗ (TensorProduct.lid K _).toLinearMap := by
letI := Classical.decEq (Basis.ofVectorSpaceIndex K V)
apply TensorProduct.ext
apply LinearMap.ext_ring; apply (Basis.ofVectorSpace K V).ext; intro j
rw [LinearMap.compr₂_apply, LinearMap.compr₂_apply, TensorProduct.mk_apply]
simp only [LinearMap.coe_comp, Function.comp_apply, LinearEquiv.coe_toLinearMap]
rw [lid_tmul, one_smul, rid_symm_apply]
simp only [LinearEquiv.coe_toLinearMap, LinearMap.rTensor_tmul, coevaluation_apply_one]
rw [TensorProduct.sum_tmul, map_sum]; simp only [assoc_tmul]
rw [map_sum]; simp only [LinearMap.lTensor_tmul, contractLeft_apply]
simp only [Basis.coord_apply, Basis.repr_self_apply, TensorProduct.tmul_ite]
rw [Finset.sum_ite_eq]; simp only [Finset.mem_univ, if_true]
end coevaluation
|
LinearAlgebra\Contraction.lean | /-
Copyright (c) 2020 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash, Antoine Labelle
-/
import Mathlib.LinearAlgebra.Dual
import Mathlib.LinearAlgebra.Matrix.ToLin
/-!
# Contractions
Given modules $M, N$ over a commutative ring $R$, this file defines the natural linear maps:
$M^* \otimes M \to R$, $M \otimes M^* \to R$, and $M^* \otimes N → Hom(M, N)$, as well as proving
some basic properties of these maps.
## Tags
contraction, dual module, tensor product
-/
suppress_compilation
-- Porting note: universe metavariables behave oddly
universe w u v₁ v₂ v₃ v₄
variable {ι : Type w} (R : Type u) (M : Type v₁) (N : Type v₂)
(P : Type v₃) (Q : Type v₄)
-- Porting note: we need high priority for this to fire first; not the case in ML3
attribute [local ext high] TensorProduct.ext
section Contraction
open TensorProduct LinearMap Matrix Module
open TensorProduct
section CommSemiring
variable [CommSemiring R]
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q]
variable [Module R M] [Module R N] [Module R P] [Module R Q]
variable [DecidableEq ι] [Fintype ι] (b : Basis ι R M)
-- Porting note: doesn't like implicit ring in the tensor product
/-- The natural left-handed pairing between a module and its dual. -/
def contractLeft : Module.Dual R M ⊗[R] M →ₗ[R] R :=
(uncurry _ _ _ _).toFun LinearMap.id
-- Porting note: doesn't like implicit ring in the tensor product
/-- The natural right-handed pairing between a module and its dual. -/
def contractRight : M ⊗[R] Module.Dual R M →ₗ[R] R :=
(uncurry _ _ _ _).toFun (LinearMap.flip LinearMap.id)
-- Porting note: doesn't like implicit ring in the tensor product
/-- The natural map associating a linear map to the tensor product of two modules. -/
def dualTensorHom : Module.Dual R M ⊗[R] N →ₗ[R] M →ₗ[R] N :=
let M' := Module.Dual R M
(uncurry R M' N (M →ₗ[R] N) : _ → M' ⊗ N →ₗ[R] M →ₗ[R] N) LinearMap.smulRightₗ
variable {R M N P Q}
@[simp]
theorem contractLeft_apply (f : Module.Dual R M) (m : M) : contractLeft R M (f ⊗ₜ m) = f m :=
rfl
@[simp]
theorem contractRight_apply (f : Module.Dual R M) (m : M) : contractRight R M (m ⊗ₜ f) = f m :=
rfl
@[simp]
theorem dualTensorHom_apply (f : Module.Dual R M) (m : M) (n : N) :
dualTensorHom R M N (f ⊗ₜ n) m = f m • n :=
rfl
@[simp]
theorem transpose_dualTensorHom (f : Module.Dual R M) (m : M) :
Dual.transpose (R := R) (dualTensorHom R M M (f ⊗ₜ m)) =
dualTensorHom R _ _ (Dual.eval R M m ⊗ₜ f) := by
ext f' m'
simp only [Dual.transpose_apply, coe_comp, Function.comp_apply, dualTensorHom_apply,
LinearMap.map_smulₛₗ, RingHom.id_apply, Algebra.id.smul_eq_mul, Dual.eval_apply,
LinearMap.smul_apply]
exact mul_comm _ _
@[simp]
theorem dualTensorHom_prodMap_zero (f : Module.Dual R M) (p : P) :
((dualTensorHom R M P) (f ⊗ₜ[R] p)).prodMap (0 : N →ₗ[R] Q) =
dualTensorHom R (M × N) (P × Q) ((f ∘ₗ fst R M N) ⊗ₜ inl R P Q p) := by
ext <;>
simp only [coe_comp, coe_inl, Function.comp_apply, prodMap_apply, dualTensorHom_apply,
fst_apply, Prod.smul_mk, LinearMap.zero_apply, smul_zero]
@[simp]
theorem zero_prodMap_dualTensorHom (g : Module.Dual R N) (q : Q) :
(0 : M →ₗ[R] P).prodMap ((dualTensorHom R N Q) (g ⊗ₜ[R] q)) =
dualTensorHom R (M × N) (P × Q) ((g ∘ₗ snd R M N) ⊗ₜ inr R P Q q) := by
ext <;>
simp only [coe_comp, coe_inr, Function.comp_apply, prodMap_apply, dualTensorHom_apply,
snd_apply, Prod.smul_mk, LinearMap.zero_apply, smul_zero]
theorem map_dualTensorHom (f : Module.Dual R M) (p : P) (g : Module.Dual R N) (q : Q) :
TensorProduct.map (dualTensorHom R M P (f ⊗ₜ[R] p)) (dualTensorHom R N Q (g ⊗ₜ[R] q)) =
dualTensorHom R (M ⊗[R] N) (P ⊗[R] Q) (dualDistrib R M N (f ⊗ₜ g) ⊗ₜ[R] p ⊗ₜ[R] q) := by
ext m n
simp only [compr₂_apply, mk_apply, map_tmul, dualTensorHom_apply, dualDistrib_apply, ←
smul_tmul_smul]
@[simp]
theorem comp_dualTensorHom (f : Module.Dual R M) (n : N) (g : Module.Dual R N) (p : P) :
dualTensorHom R N P (g ⊗ₜ[R] p) ∘ₗ dualTensorHom R M N (f ⊗ₜ[R] n) =
g n • dualTensorHom R M P (f ⊗ₜ p) := by
ext m
simp only [coe_comp, Function.comp_apply, dualTensorHom_apply, LinearMap.map_smul,
RingHom.id_apply, LinearMap.smul_apply]
rw [smul_comm]
/-- As a matrix, `dualTensorHom` evaluated on a basis element of `M* ⊗ N` is a matrix with a
single one and zeros elsewhere -/
theorem toMatrix_dualTensorHom {m : Type*} {n : Type*} [Fintype m] [Finite n] [DecidableEq m]
[DecidableEq n] (bM : Basis m R M) (bN : Basis n R N) (j : m) (i : n) :
toMatrix bM bN (dualTensorHom R M N (bM.coord j ⊗ₜ bN i)) = stdBasisMatrix i j 1 := by
ext i' j'
by_cases hij : i = i' ∧ j = j' <;>
simp [LinearMap.toMatrix_apply, Finsupp.single_eq_pi_single, hij]
rw [and_iff_not_or_not, Classical.not_not] at hij
cases' hij with hij hij <;> simp [hij]
end CommSemiring
section CommRing
variable [CommRing R]
variable [AddCommGroup M] [AddCommGroup N] [AddCommGroup P] [AddCommGroup Q]
variable [Module R M] [Module R N] [Module R P] [Module R Q]
variable [DecidableEq ι] [Fintype ι] (b : Basis ι R M)
variable {R M N P Q}
/-- If `M` is free, the natural linear map $M^* ⊗ N → Hom(M, N)$ is an equivalence. This function
provides this equivalence in return for a basis of `M`. -/
-- @[simps! apply] -- Porting note: removed and created manually; malformed
noncomputable def dualTensorHomEquivOfBasis : Module.Dual R M ⊗[R] N ≃ₗ[R] M →ₗ[R] N :=
LinearEquiv.ofLinear (dualTensorHom R M N)
(∑ i, TensorProduct.mk R _ N (b.dualBasis i) ∘ₗ (LinearMap.applyₗ (R := R) (b i)))
(by
ext f m
simp only [applyₗ_apply_apply, coeFn_sum, dualTensorHom_apply, mk_apply, id_coe, _root_.id,
Fintype.sum_apply, Function.comp_apply, Basis.coe_dualBasis, coe_comp, Basis.coord_apply, ←
f.map_smul, _root_.map_sum (dualTensorHom R M N), ← _root_.map_sum f, b.sum_repr])
(by
ext f m
simp only [applyₗ_apply_apply, coeFn_sum, dualTensorHom_apply, mk_apply, id_coe, _root_.id,
Fintype.sum_apply, Function.comp_apply, Basis.coe_dualBasis, coe_comp, compr₂_apply,
tmul_smul, smul_tmul', ← sum_tmul, Basis.sum_dual_apply_smul_coord])
@[simp]
theorem dualTensorHomEquivOfBasis_apply (x : Module.Dual R M ⊗[R] N) :
(dualTensorHomEquivOfBasis (N := N) b :
Module.Dual R M ⊗[R] N → (M →ₗ[R] N)) x = (dualTensorHom R M N) x := by
ext; rfl
@[simp]
theorem dualTensorHomEquivOfBasis_toLinearMap :
(dualTensorHomEquivOfBasis b : Module.Dual R M ⊗[R] N ≃ₗ[R] M →ₗ[R] N).toLinearMap =
dualTensorHom R M N :=
rfl
-- Porting note: should N be explicit in dualTensorHomEquivOfBasis?
@[simp]
theorem dualTensorHomEquivOfBasis_symm_cancel_left (x : Module.Dual R M ⊗[R] N) :
(dualTensorHomEquivOfBasis (N := N) b).symm (dualTensorHom R M N x) = x := by
rw [← dualTensorHomEquivOfBasis_apply b,
LinearEquiv.symm_apply_apply <| dualTensorHomEquivOfBasis (N := N) b]
@[simp]
theorem dualTensorHomEquivOfBasis_symm_cancel_right (x : M →ₗ[R] N) :
dualTensorHom R M N ((dualTensorHomEquivOfBasis (N := N) b).symm x) = x := by
rw [← dualTensorHomEquivOfBasis_apply b, LinearEquiv.apply_symm_apply]
variable (R M N P Q)
variable [Module.Free R M] [Module.Finite R M]
/-- If `M` is finite free, the natural map $M^* ⊗ N → Hom(M, N)$ is an
equivalence. -/
@[simp]
noncomputable def dualTensorHomEquiv : Module.Dual R M ⊗[R] N ≃ₗ[R] M →ₗ[R] N :=
dualTensorHomEquivOfBasis (Module.Free.chooseBasis R M)
end CommRing
end Contraction
section HomTensorHom
open TensorProduct
open Module TensorProduct LinearMap
section CommRing
variable [CommRing R]
variable [AddCommGroup M] [AddCommGroup N] [AddCommGroup P] [AddCommGroup Q]
variable [Module R M] [Module R N] [Module R P] [Module R Q]
variable [Free R M] [Finite R M] [Free R N] [Finite R N] [Nontrivial R]
/-- When `M` is a finite free module, the map `lTensorHomToHomLTensor` is an equivalence. Note
that `lTensorHomEquivHomLTensor` is not defined directly in terms of
`lTensorHomToHomLTensor`, but the equivalence between the two is given by
`lTensorHomEquivHomLTensor_toLinearMap` and `lTensorHomEquivHomLTensor_apply`. -/
noncomputable def lTensorHomEquivHomLTensor : P ⊗[R] (M →ₗ[R] Q) ≃ₗ[R] M →ₗ[R] P ⊗[R] Q :=
congr (LinearEquiv.refl R P) (dualTensorHomEquiv R M Q).symm ≪≫ₗ
TensorProduct.leftComm R P _ Q ≪≫ₗ
dualTensorHomEquiv R M _
/-- When `M` is a finite free module, the map `rTensorHomToHomRTensor` is an equivalence. Note
that `rTensorHomEquivHomRTensor` is not defined directly in terms of
`rTensorHomToHomRTensor`, but the equivalence between the two is given by
`rTensorHomEquivHomRTensor_toLinearMap` and `rTensorHomEquivHomRTensor_apply`. -/
noncomputable def rTensorHomEquivHomRTensor : (M →ₗ[R] P) ⊗[R] Q ≃ₗ[R] M →ₗ[R] P ⊗[R] Q :=
congr (dualTensorHomEquiv R M P).symm (LinearEquiv.refl R Q) ≪≫ₗ TensorProduct.assoc R _ P Q ≪≫ₗ
dualTensorHomEquiv R M _
@[simp]
theorem lTensorHomEquivHomLTensor_toLinearMap :
(lTensorHomEquivHomLTensor R M P Q).toLinearMap = lTensorHomToHomLTensor R M P Q := by
classical -- Porting note: missing decidable for choosing basis
let e := congr (LinearEquiv.refl R P) (dualTensorHomEquiv R M Q)
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext f q m
simp only [e, lTensorHomEquivHomLTensor, dualTensorHomEquiv, LinearEquiv.comp_coe, compr₂_apply,
mk_apply, LinearEquiv.coe_coe, LinearEquiv.trans_apply, congr_tmul, LinearEquiv.refl_apply,
dualTensorHomEquivOfBasis_apply, dualTensorHomEquivOfBasis_symm_cancel_left, leftComm_tmul,
dualTensorHom_apply, coe_comp, Function.comp_apply, lTensorHomToHomLTensor_apply, tmul_smul]
@[simp]
theorem rTensorHomEquivHomRTensor_toLinearMap :
(rTensorHomEquivHomRTensor R M P Q).toLinearMap = rTensorHomToHomRTensor R M P Q := by
classical -- Porting note: missing decidable for choosing basis
let e := congr (dualTensorHomEquiv R M P) (LinearEquiv.refl R Q)
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext f p q m
simp only [e, rTensorHomEquivHomRTensor, dualTensorHomEquiv, compr₂_apply, mk_apply, coe_comp,
LinearEquiv.coe_toLinearMap, Function.comp_apply, map_tmul, LinearEquiv.coe_coe,
dualTensorHomEquivOfBasis_apply, LinearEquiv.trans_apply, congr_tmul,
dualTensorHomEquivOfBasis_symm_cancel_left, LinearEquiv.refl_apply, assoc_tmul,
dualTensorHom_apply, rTensorHomToHomRTensor_apply, smul_tmul']
variable {R M N P Q}
@[simp]
theorem lTensorHomEquivHomLTensor_apply (x : P ⊗[R] (M →ₗ[R] Q)) :
lTensorHomEquivHomLTensor R M P Q x = lTensorHomToHomLTensor R M P Q x := by
rw [← LinearEquiv.coe_toLinearMap, lTensorHomEquivHomLTensor_toLinearMap]
@[simp]
theorem rTensorHomEquivHomRTensor_apply (x : (M →ₗ[R] P) ⊗[R] Q) :
rTensorHomEquivHomRTensor R M P Q x = rTensorHomToHomRTensor R M P Q x := by
rw [← LinearEquiv.coe_toLinearMap, rTensorHomEquivHomRTensor_toLinearMap]
variable (R M N P Q)
/-- When `M` and `N` are free `R` modules, the map `homTensorHomMap` is an equivalence. Note that
`homTensorHomEquiv` is not defined directly in terms of `homTensorHomMap`, but the equivalence
between the two is given by `homTensorHomEquiv_toLinearMap` and `homTensorHomEquiv_apply`.
-/
noncomputable def homTensorHomEquiv : (M →ₗ[R] P) ⊗[R] (N →ₗ[R] Q) ≃ₗ[R] M ⊗[R] N →ₗ[R] P ⊗[R] Q :=
rTensorHomEquivHomRTensor R M P _ ≪≫ₗ
(LinearEquiv.refl R M).arrowCongr (lTensorHomEquivHomLTensor R N _ Q) ≪≫ₗ
lift.equiv R M N _
@[simp]
theorem homTensorHomEquiv_toLinearMap :
(homTensorHomEquiv R M N P Q).toLinearMap = homTensorHomMap R M N P Q := by
ext m n
simp only [homTensorHomEquiv, compr₂_apply, mk_apply, LinearEquiv.coe_toLinearMap,
LinearEquiv.trans_apply, lift.equiv_apply, LinearEquiv.arrowCongr_apply, LinearEquiv.refl_symm,
LinearEquiv.refl_apply, rTensorHomEquivHomRTensor_apply, lTensorHomEquivHomLTensor_apply,
lTensorHomToHomLTensor_apply, rTensorHomToHomRTensor_apply, homTensorHomMap_apply,
map_tmul]
variable {R M N P Q}
@[simp]
theorem homTensorHomEquiv_apply (x : (M →ₗ[R] P) ⊗[R] (N →ₗ[R] Q)) :
homTensorHomEquiv R M N P Q x = homTensorHomMap R M N P Q x := by
rw [← LinearEquiv.coe_toLinearMap, homTensorHomEquiv_toLinearMap]
end CommRing
end HomTensorHom
|
LinearAlgebra\CrossProduct.lean | /-
Copyright (c) 2021 Martin Dvorak. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Martin Dvorak, Kyle Miller, Eric Wieser
-/
import Mathlib.Data.Matrix.Notation
import Mathlib.LinearAlgebra.BilinearMap
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.Algebra.Lie.Basic
/-!
# Cross products
This module defines the cross product of vectors in $R^3$ for $R$ a commutative ring,
as a bilinear map.
## Main definitions
* `crossProduct` is the cross product of pairs of vectors in $R^3$.
## Main results
* `triple_product_eq_det`
* `cross_dot_cross`
* `jacobi_cross`
## Notation
The locale `Matrix` gives the following notation:
* `×₃` for the cross product
## Tags
crossproduct
-/
open Matrix
open Matrix
variable {R : Type*} [CommRing R]
/-- The cross product of two vectors in $R^3$ for $R$ a commutative ring. -/
def crossProduct : (Fin 3 → R) →ₗ[R] (Fin 3 → R) →ₗ[R] Fin 3 → R := by
apply LinearMap.mk₂ R fun a b : Fin 3 → R =>
![a 1 * b 2 - a 2 * b 1, a 2 * b 0 - a 0 * b 2, a 0 * b 1 - a 1 * b 0]
· intros
simp_rw [vec3_add, Pi.add_apply]
apply vec3_eq <;> ring
· intros
simp_rw [smul_vec3, Pi.smul_apply, smul_sub, smul_mul_assoc]
· intros
simp_rw [vec3_add, Pi.add_apply]
apply vec3_eq <;> ring
· intros
simp_rw [smul_vec3, Pi.smul_apply, smul_sub, mul_smul_comm]
scoped[Matrix] infixl:74 " ×₃ " => crossProduct
theorem cross_apply (a b : Fin 3 → R) :
a ×₃ b = ![a 1 * b 2 - a 2 * b 1, a 2 * b 0 - a 0 * b 2, a 0 * b 1 - a 1 * b 0] := rfl
section ProductsProperties
@[simp]
theorem cross_anticomm (v w : Fin 3 → R) : -(v ×₃ w) = w ×₃ v := by
simp [cross_apply, mul_comm]
alias neg_cross := cross_anticomm
@[simp]
theorem cross_anticomm' (v w : Fin 3 → R) : v ×₃ w + w ×₃ v = 0 := by
rw [add_eq_zero_iff_eq_neg, cross_anticomm]
@[simp]
theorem cross_self (v : Fin 3 → R) : v ×₃ v = 0 := by
simp [cross_apply, mul_comm]
/-- The cross product of two vectors is perpendicular to the first vector. -/
@[simp 1100] -- Porting note: increase priority so that the LHS doesn't simplify
theorem dot_self_cross (v w : Fin 3 → R) : v ⬝ᵥ v ×₃ w = 0 := by
rw [cross_apply, vec3_dotProduct]
norm_num
ring
/-- The cross product of two vectors is perpendicular to the second vector. -/
@[simp 1100] -- Porting note: increase priority so that the LHS doesn't simplify
theorem dot_cross_self (v w : Fin 3 → R) : w ⬝ᵥ v ×₃ w = 0 := by
rw [← cross_anticomm, Matrix.dotProduct_neg, dot_self_cross, neg_zero]
/-- Cyclic permutations preserve the triple product. See also `triple_product_eq_det`. -/
theorem triple_product_permutation (u v w : Fin 3 → R) : u ⬝ᵥ v ×₃ w = v ⬝ᵥ w ×₃ u := by
simp_rw [cross_apply, vec3_dotProduct]
norm_num
ring
/-- The triple product of `u`, `v`, and `w` is equal to the determinant of the matrix
with those vectors as its rows. -/
theorem triple_product_eq_det (u v w : Fin 3 → R) : u ⬝ᵥ v ×₃ w = Matrix.det ![u, v, w] := by
rw [vec3_dotProduct, cross_apply, det_fin_three]
norm_num
ring
/-- The scalar quadruple product identity, related to the Binet-Cauchy identity. -/
theorem cross_dot_cross (u v w x : Fin 3 → R) :
u ×₃ v ⬝ᵥ w ×₃ x = u ⬝ᵥ w * v ⬝ᵥ x - u ⬝ᵥ x * v ⬝ᵥ w := by
simp_rw [cross_apply, vec3_dotProduct]
norm_num
ring
end ProductsProperties
section LeibnizProperties
/-- The cross product satisfies the Leibniz lie property. -/
theorem leibniz_cross (u v w : Fin 3 → R) : u ×₃ (v ×₃ w) = u ×₃ v ×₃ w + v ×₃ (u ×₃ w) := by
simp_rw [cross_apply, vec3_add]
apply vec3_eq <;> norm_num <;> ring
/-- The three-dimensional vectors together with the operations + and ×₃ form a Lie ring.
Note we do not make this an instance as a conflicting one already exists
via `LieRing.ofAssociativeRing`. -/
def Cross.lieRing : LieRing (Fin 3 → R) :=
{ Pi.addCommGroup with
bracket := fun u v => u ×₃ v
add_lie := LinearMap.map_add₂ _
lie_add := fun _ => LinearMap.map_add _
lie_self := cross_self
leibniz_lie := leibniz_cross }
attribute [local instance] Cross.lieRing
theorem cross_cross (u v w : Fin 3 → R) : u ×₃ v ×₃ w = u ×₃ (v ×₃ w) - v ×₃ (u ×₃ w) :=
lie_lie u v w
/-- **Jacobi identity**: For a cross product of three vectors,
their sum over the three even permutations is equal to the zero vector. -/
theorem jacobi_cross (u v w : Fin 3 → R) : u ×₃ (v ×₃ w) + v ×₃ (w ×₃ u) + w ×₃ (u ×₃ v) = 0 :=
lie_jacobi u v w
end LeibnizProperties
|
LinearAlgebra\Determinant.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.Tactic.FieldSimp
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.Basis
/-!
# Determinant of families of vectors
This file defines the determinant of an endomorphism, and of a family of vectors
with respect to some basis. For the determinant of a matrix, see the file
`LinearAlgebra.Matrix.Determinant`.
## Main definitions
In the list below, and in all this file, `R` is a commutative ring (semiring
is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite
types used for indexing.
* `Basis.det`: the determinant of a family of vectors with respect to a basis,
as a multilinear map
* `LinearMap.det`: the determinant of an endomorphism `f : End R M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
* `LinearEquiv.det`: the determinant of an isomorphism `f : M ≃ₗ[R] M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
## Tags
basis, det, determinant
-/
noncomputable section
open Matrix LinearMap Submodule Set Function
universe u v w
variable {R : Type*} [CommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable {M' : Type*} [AddCommGroup M'] [Module R M']
variable {ι : Type*} [DecidableEq ι] [Fintype ι]
variable (e : Basis ι R M)
section Conjugate
variable {A : Type*} [CommRing A]
variable {m n : Type*}
/-- If `R^m` and `R^n` are linearly equivalent, then `m` and `n` are also equivalent. -/
def equivOfPiLEquivPi {R : Type*} [Finite m] [Finite n] [CommRing R] [Nontrivial R]
(e : (m → R) ≃ₗ[R] n → R) : m ≃ n :=
Basis.indexEquiv (Basis.ofEquivFun e.symm) (Pi.basisFun _ _)
namespace Matrix
variable [Fintype m] [Fintype n]
/-- If `M` and `M'` are each other's inverse matrices, they are square matrices up to
equivalence of types. -/
def indexEquivOfInv [Nontrivial A] [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : m ≃ n :=
equivOfPiLEquivPi (toLin'OfInv hMM' hM'M)
theorem det_comm [DecidableEq n] (M N : Matrix n n A) : det (M * N) = det (N * M) := by
rw [det_mul, det_mul, mul_comm]
/-- If there exists a two-sided inverse `M'` for `M` (indexed differently),
then `det (N * M) = det (M * N)`. -/
theorem det_comm' [DecidableEq m] [DecidableEq n] {M : Matrix n m A} {N : Matrix m n A}
{M' : Matrix m n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N) = det (N * M) := by
nontriviality A
-- Although `m` and `n` are different a priori, we will show they have the same cardinality.
-- This turns the problem into one for square matrices, which is easy.
let e := indexEquivOfInv hMM' hM'M
rw [← det_submatrix_equiv_self e, ← submatrix_mul_equiv _ _ _ (Equiv.refl n) _, det_comm,
submatrix_mul_equiv, Equiv.coe_refl, submatrix_id_id]
/-- If `M'` is a two-sided inverse for `M` (indexed differently), `det (M * N * M') = det N`.
See `Matrix.det_conj` and `Matrix.det_conj'` for the case when `M' = M⁻¹` or vice versa. -/
theorem det_conj_of_mul_eq_one [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} {N : Matrix n n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) :
det (M * N * M') = det N := by
rw [← det_comm' hM'M hMM', ← Matrix.mul_assoc, hM'M, Matrix.one_mul]
end Matrix
end Conjugate
namespace LinearMap
/-! ### Determinant of a linear map -/
variable {A : Type*} [CommRing A] [Module A M]
variable {κ : Type*} [Fintype κ]
/-- The determinant of `LinearMap.toMatrix` does not depend on the choice of basis. -/
theorem det_toMatrix_eq_det_toMatrix [DecidableEq κ] (b : Basis ι A M) (c : Basis κ A M)
(f : M →ₗ[A] M) : det (LinearMap.toMatrix b b f) = det (LinearMap.toMatrix c c f) := by
rw [← linearMap_toMatrix_mul_basis_toMatrix c b c, ← basis_toMatrix_mul_linearMap_toMatrix b c b,
Matrix.det_conj_of_mul_eq_one] <;>
rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self]
/-- The determinant of an endomorphism given a basis.
See `LinearMap.det` for a version that populates the basis non-computably.
Although the `Trunc (Basis ι A M)` parameter makes it slightly more convenient to switch bases,
there is no good way to generalize over universe parameters, so we can't fully state in `detAux`'s
type that it does not depend on the choice of basis. Instead you can use the `detAux_def''` lemma,
or avoid mentioning a basis at all using `LinearMap.det`.
-/
irreducible_def detAux : Trunc (Basis ι A M) → (M →ₗ[A] M) →* A :=
Trunc.lift
(fun b : Basis ι A M => detMonoidHom.comp (toMatrixAlgEquiv b : (M →ₗ[A] M) →* Matrix ι ι A))
fun b c => MonoidHom.ext <| det_toMatrix_eq_det_toMatrix b c
/-- Unfold lemma for `detAux`.
See also `detAux_def''` which allows you to vary the basis.
-/
theorem detAux_def' (b : Basis ι A M) (f : M →ₗ[A] M) :
LinearMap.detAux (Trunc.mk b) f = Matrix.det (LinearMap.toMatrix b b f) := by
rw [detAux]
rfl
theorem detAux_def'' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (tb : Trunc <| Basis ι A M)
(b' : Basis ι' A M) (f : M →ₗ[A] M) :
LinearMap.detAux tb f = Matrix.det (LinearMap.toMatrix b' b' f) := by
induction tb using Trunc.induction_on with
| h b => rw [detAux_def', det_toMatrix_eq_det_toMatrix b b']
@[simp]
theorem detAux_id (b : Trunc <| Basis ι A M) : LinearMap.detAux b LinearMap.id = 1 :=
(LinearMap.detAux b).map_one
@[simp]
theorem detAux_comp (b : Trunc <| Basis ι A M) (f g : M →ₗ[A] M) :
LinearMap.detAux b (f.comp g) = LinearMap.detAux b f * LinearMap.detAux b g :=
(LinearMap.detAux b).map_mul f g
section
open scoped Classical in
-- Discourage the elaborator from unfolding `det` and producing a huge term by marking it
-- as irreducible.
/-- The determinant of an endomorphism independent of basis.
If there is no finite basis on `M`, the result is `1` instead.
-/
protected irreducible_def det : (M →ₗ[A] M) →* A :=
if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some)
else 1
open scoped Classical in
theorem coe_det [DecidableEq M] :
⇑(LinearMap.det : (M →ₗ[A] M) →* A) =
if H : ∃ s : Finset M, Nonempty (Basis s A M) then
LinearMap.detAux (Trunc.mk H.choose_spec.some)
else 1 := by
ext
rw [LinearMap.det_def]
split_ifs
· congr -- use the correct `DecidableEq` instance
rfl
end
-- Auxiliary lemma, the `simp` normal form goes in the other direction
-- (using `LinearMap.det_toMatrix`)
theorem det_eq_det_toMatrix_of_finset [DecidableEq M] {s : Finset M} (b : Basis s A M)
(f : M →ₗ[A] M) : LinearMap.det f = Matrix.det (LinearMap.toMatrix b b f) := by
have : ∃ s : Finset M, Nonempty (Basis s A M) := ⟨s, ⟨b⟩⟩
rw [LinearMap.coe_det, dif_pos, detAux_def'' _ b] <;> assumption
@[simp]
theorem det_toMatrix (b : Basis ι A M) (f : M →ₗ[A] M) :
Matrix.det (toMatrix b b f) = LinearMap.det f := by
haveI := Classical.decEq M
rw [det_eq_det_toMatrix_of_finset b.reindexFinsetRange]
-- Porting note: moved out of `rw` due to error
-- typeclass instance problem is stuck, it is often due to metavariables `DecidableEq ?m.628881`
apply det_toMatrix_eq_det_toMatrix b
@[simp]
theorem det_toMatrix' {ι : Type*} [Fintype ι] [DecidableEq ι] (f : (ι → A) →ₗ[A] ι → A) :
Matrix.det (LinearMap.toMatrix' f) = LinearMap.det f := by simp [← toMatrix_eq_toMatrix']
@[simp]
theorem det_toLin (b : Basis ι R M) (f : Matrix ι ι R) :
LinearMap.det (Matrix.toLin b b f) = f.det := by
rw [← LinearMap.det_toMatrix b, LinearMap.toMatrix_toLin]
@[simp]
theorem det_toLin' (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin' f) = Matrix.det f := by
simp only [← toLin_eq_toLin', det_toLin]
/-- To show `P (LinearMap.det f)` it suffices to consider `P (Matrix.det (toMatrix _ _ f))` and
`P 1`. -/
-- @[elab_as_elim] -- Porting note: This attr can't be applied.
theorem det_cases [DecidableEq M] {P : A → Prop} (f : M →ₗ[A] M)
(hb : ∀ (s : Finset M) (b : Basis s A M), P (Matrix.det (toMatrix b b f))) (h1 : P 1) :
P (LinearMap.det f) := by
rw [LinearMap.det_def]
split_ifs with h
· convert hb _ h.choose_spec.some
-- Porting note: was `apply det_aux_def'`
convert detAux_def'' (Trunc.mk h.choose_spec.some) h.choose_spec.some f
· exact h1
@[simp]
theorem det_comp (f g : M →ₗ[A] M) :
LinearMap.det (f.comp g) = LinearMap.det f * LinearMap.det g :=
LinearMap.det.map_mul f g
@[simp]
theorem det_id : LinearMap.det (LinearMap.id : M →ₗ[A] M) = 1 :=
LinearMap.det.map_one
/-- Multiplying a map by a scalar `c` multiplies its determinant by `c ^ dim M`. -/
@[simp]
theorem det_smul {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M] (c : 𝕜)
(f : M →ₗ[𝕜] M) :
LinearMap.det (c • f) = c ^ FiniteDimensional.finrank 𝕜 M * LinearMap.det f := by
by_cases H : ∃ s : Finset M, Nonempty (Basis s 𝕜 M)
· have : FiniteDimensional 𝕜 M := by
rcases H with ⟨s, ⟨hs⟩⟩
exact FiniteDimensional.of_fintype_basis hs
simp only [← det_toMatrix (FiniteDimensional.finBasis 𝕜 M), LinearEquiv.map_smul,
Fintype.card_fin, Matrix.det_smul]
· classical
have : FiniteDimensional.finrank 𝕜 M = 0 := finrank_eq_zero_of_not_exists_basis H
simp [coe_det, H, this]
theorem det_zero' {ι : Type*} [Finite ι] [Nonempty ι] (b : Basis ι A M) :
LinearMap.det (0 : M →ₗ[A] M) = 0 := by
haveI := Classical.decEq ι
cases nonempty_fintype ι
rwa [← det_toMatrix b, LinearEquiv.map_zero, det_zero]
/-- In a finite-dimensional vector space, the zero map has determinant `1` in dimension `0`,
and `0` otherwise. We give a formula that also works in infinite dimension, where we define
the determinant to be `1`. -/
@[simp]
theorem det_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M] :
LinearMap.det (0 : M →ₗ[𝕜] M) = (0 : 𝕜) ^ FiniteDimensional.finrank 𝕜 M := by
simp only [← zero_smul 𝕜 (1 : M →ₗ[𝕜] M), det_smul, mul_one, MonoidHom.map_one]
theorem det_eq_one_of_subsingleton [Subsingleton M] (f : M →ₗ[R] M) :
LinearMap.det (f : M →ₗ[R] M) = 1 := by
have b : Basis (Fin 0) R M := Basis.empty M
rw [← f.det_toMatrix b]
exact Matrix.det_isEmpty
theorem det_eq_one_of_finrank_eq_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M]
[Module 𝕜 M] (h : FiniteDimensional.finrank 𝕜 M = 0) (f : M →ₗ[𝕜] M) :
LinearMap.det (f : M →ₗ[𝕜] M) = 1 := by
classical
refine @LinearMap.det_cases M _ 𝕜 _ _ _ (fun t => t = 1) f ?_ rfl
intro s b
have : IsEmpty s := by
rw [← Fintype.card_eq_zero_iff]
exact (FiniteDimensional.finrank_eq_card_basis b).symm.trans h
exact Matrix.det_isEmpty
/-- Conjugating a linear map by a linear equiv does not change its determinant. -/
@[simp]
theorem det_conj {N : Type*} [AddCommGroup N] [Module A N] (f : M →ₗ[A] M) (e : M ≃ₗ[A] N) :
LinearMap.det ((e : M →ₗ[A] N) ∘ₗ f ∘ₗ (e.symm : N →ₗ[A] M)) = LinearMap.det f := by
classical
by_cases H : ∃ s : Finset M, Nonempty (Basis s A M)
· rcases H with ⟨s, ⟨b⟩⟩
rw [← det_toMatrix b f, ← det_toMatrix (b.map e), toMatrix_comp (b.map e) b (b.map e),
toMatrix_comp (b.map e) b b, ← Matrix.mul_assoc, Matrix.det_conj_of_mul_eq_one]
· rw [← toMatrix_comp, LinearEquiv.comp_coe, e.symm_trans_self, LinearEquiv.refl_toLinearMap,
toMatrix_id]
· rw [← toMatrix_comp, LinearEquiv.comp_coe, e.self_trans_symm, LinearEquiv.refl_toLinearMap,
toMatrix_id]
· have H' : ¬∃ t : Finset N, Nonempty (Basis t A N) := by
contrapose! H
rcases H with ⟨s, ⟨b⟩⟩
exact ⟨_, ⟨(b.map e.symm).reindexFinsetRange⟩⟩
simp only [coe_det, H, H', MonoidHom.one_apply, dif_neg, not_false_eq_true]
/-- If a linear map is invertible, so is its determinant. -/
theorem isUnit_det {A : Type*} [CommRing A] [Module A M] (f : M →ₗ[A] M) (hf : IsUnit f) :
IsUnit (LinearMap.det f) := by
obtain ⟨g, hg⟩ : ∃ g, f.comp g = 1 := hf.exists_right_inv
have : LinearMap.det f * LinearMap.det g = 1 := by
simp only [← LinearMap.det_comp, hg, MonoidHom.map_one]
exact isUnit_of_mul_eq_one _ _ this
/-- If a linear map has determinant different from `1`, then the space is finite-dimensional. -/
theorem finiteDimensional_of_det_ne_one {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M →ₗ[𝕜] M)
(hf : LinearMap.det f ≠ 1) : FiniteDimensional 𝕜 M := by
by_cases H : ∃ s : Finset M, Nonempty (Basis s 𝕜 M)
· rcases H with ⟨s, ⟨hs⟩⟩
exact FiniteDimensional.of_fintype_basis hs
· classical simp [LinearMap.coe_det, H] at hf
/-- If the determinant of a map vanishes, then the map is not onto. -/
theorem range_lt_top_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M}
(hf : LinearMap.det f = 0) : LinearMap.range f < ⊤ := by
have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf]
contrapose hf
simp only [lt_top_iff_ne_top, Classical.not_not, ← isUnit_iff_range_eq_top] at hf
exact isUnit_iff_ne_zero.1 (f.isUnit_det hf)
/-- If the determinant of a map vanishes, then the map is not injective. -/
theorem bot_lt_ker_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M}
(hf : LinearMap.det f = 0) : ⊥ < LinearMap.ker f := by
have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf]
contrapose hf
simp only [bot_lt_iff_ne_bot, Classical.not_not, ← isUnit_iff_ker_eq_bot] at hf
exact isUnit_iff_ne_zero.1 (f.isUnit_det hf)
end LinearMap
namespace LinearEquiv
/-- On a `LinearEquiv`, the domain of `LinearMap.det` can be promoted to `Rˣ`. -/
protected def det : (M ≃ₗ[R] M) →* Rˣ :=
(Units.map (LinearMap.det : (M →ₗ[R] M) →* R)).comp
(LinearMap.GeneralLinearGroup.generalLinearEquiv R M).symm.toMonoidHom
@[simp]
theorem coe_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f) = LinearMap.det (f : M →ₗ[R] M) :=
rfl
@[simp]
theorem coe_inv_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f)⁻¹ = LinearMap.det (f.symm : M →ₗ[R] M) :=
rfl
@[simp]
theorem det_refl : LinearEquiv.det (LinearEquiv.refl R M) = 1 :=
Units.ext <| LinearMap.det_id
@[simp]
theorem det_trans (f g : M ≃ₗ[R] M) :
LinearEquiv.det (f.trans g) = LinearEquiv.det g * LinearEquiv.det f :=
map_mul _ g f
@[simp]
theorem det_symm (f : M ≃ₗ[R] M) : LinearEquiv.det f.symm = LinearEquiv.det f⁻¹ :=
map_inv _ f
/-- Conjugating a linear equiv by a linear equiv does not change its determinant. -/
@[simp]
theorem det_conj (f : M ≃ₗ[R] M) (e : M ≃ₗ[R] M') :
LinearEquiv.det ((e.symm.trans f).trans e) = LinearEquiv.det f := by
rw [← Units.eq_iff, coe_det, coe_det, ← comp_coe, ← comp_coe, LinearMap.det_conj]
attribute [irreducible] LinearEquiv.det
end LinearEquiv
/-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/
@[simp]
theorem LinearEquiv.det_mul_det_symm {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
LinearMap.det (f : M →ₗ[A] M) * LinearMap.det (f.symm : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
/-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/
@[simp]
theorem LinearEquiv.det_symm_mul_det {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
LinearMap.det (f.symm : M →ₗ[A] M) * LinearMap.det (f : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
-- Cannot be stated using `LinearMap.det` because `f` is not an endomorphism.
theorem LinearEquiv.isUnit_det (f : M ≃ₗ[R] M') (v : Basis ι R M) (v' : Basis ι R M') :
IsUnit (LinearMap.toMatrix v v' f).det := by
apply isUnit_det_of_left_inverse
simpa using (LinearMap.toMatrix_comp v v' v f.symm f).symm
/-- Specialization of `LinearEquiv.isUnit_det` -/
theorem LinearEquiv.isUnit_det' {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
IsUnit (LinearMap.det (f : M →ₗ[A] M)) :=
isUnit_of_mul_eq_one _ _ f.det_mul_det_symm
/-- The determinant of `f.symm` is the inverse of that of `f` when `f` is a linear equiv. -/
theorem LinearEquiv.det_coe_symm {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M ≃ₗ[𝕜] M) :
LinearMap.det (f.symm : M →ₗ[𝕜] M) = (LinearMap.det (f : M →ₗ[𝕜] M))⁻¹ := by
field_simp [IsUnit.ne_zero f.isUnit_det']
/-- Builds a linear equivalence from a linear map whose determinant in some bases is a unit. -/
@[simps]
def LinearEquiv.ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'}
(h : IsUnit (LinearMap.toMatrix v v' f).det) : M ≃ₗ[R] M' where
toFun := f
map_add' := f.map_add
map_smul' := f.map_smul
invFun := toLin v' v (toMatrix v v' f)⁻¹
left_inv x :=
calc toLin v' v (toMatrix v v' f)⁻¹ (f x)
_ = toLin v v ((toMatrix v v' f)⁻¹ * toMatrix v v' f) x := by
rw [toLin_mul v v' v, toLin_toMatrix, LinearMap.comp_apply]
_ = x := by simp [h]
right_inv x :=
calc f (toLin v' v (toMatrix v v' f)⁻¹ x)
_ = toLin v' v' (toMatrix v v' f * (toMatrix v v' f)⁻¹) x := by
rw [toLin_mul v' v v', LinearMap.comp_apply, toLin_toMatrix v v']
_ = x := by simp [h]
@[simp]
theorem LinearEquiv.coe_ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'}
(h : IsUnit (LinearMap.toMatrix v v' f).det) :
(LinearEquiv.ofIsUnitDet h : M →ₗ[R] M') = f := by
ext x
rfl
/-- Builds a linear equivalence from a linear map on a finite-dimensional vector space whose
determinant is nonzero. -/
abbrev LinearMap.equivOfDetNeZero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M]
[FiniteDimensional 𝕜 M] (f : M →ₗ[𝕜] M) (hf : LinearMap.det f ≠ 0) : M ≃ₗ[𝕜] M :=
have : IsUnit (LinearMap.toMatrix (FiniteDimensional.finBasis 𝕜 M)
(FiniteDimensional.finBasis 𝕜 M) f).det := by
rw [LinearMap.det_toMatrix]
exact isUnit_iff_ne_zero.2 hf
LinearEquiv.ofIsUnitDet this
theorem LinearMap.associated_det_of_eq_comp (e : M ≃ₗ[R] M) (f f' : M →ₗ[R] M)
(h : ∀ x, f x = f' (e x)) : Associated (LinearMap.det f) (LinearMap.det f') := by
suffices Associated (LinearMap.det (f' ∘ₗ ↑e)) (LinearMap.det f') by
convert this using 2
ext x
exact h x
rw [← mul_one (LinearMap.det f'), LinearMap.det_comp]
exact Associated.mul_left _ (associated_one_iff_isUnit.mpr e.isUnit_det')
theorem LinearMap.associated_det_comp_equiv {N : Type*} [AddCommGroup N] [Module R N]
(f : N →ₗ[R] M) (e e' : M ≃ₗ[R] N) :
Associated (LinearMap.det (f ∘ₗ ↑e)) (LinearMap.det (f ∘ₗ ↑e')) := by
refine LinearMap.associated_det_of_eq_comp (e.trans e'.symm) _ _ ?_
intro x
simp only [LinearMap.comp_apply, LinearEquiv.coe_coe, LinearEquiv.trans_apply,
LinearEquiv.apply_symm_apply]
/-- The determinant of a family of vectors with respect to some basis, as an alternating
multilinear map. -/
nonrec def Basis.det : M [⋀^ι]→ₗ[R] R where
toFun v := det (e.toMatrix v)
map_add' := by
intro inst v i x y
cases Subsingleton.elim inst ‹_›
simp only [e.toMatrix_update, LinearEquiv.map_add, Finsupp.coe_add]
-- Porting note: was `exact det_update_column_add _ _ _ _`
convert det_updateColumn_add (e.toMatrix v) i (e.repr x) (e.repr y)
map_smul' := by
intro inst u i c x
cases Subsingleton.elim inst ‹_›
simp only [e.toMatrix_update, Algebra.id.smul_eq_mul, LinearEquiv.map_smul]
-- Porting note: was `apply det_update_column_smul`
convert det_updateColumn_smul (e.toMatrix u) i c (e.repr x)
map_eq_zero_of_eq' := by
intro v i j h hij
-- Porting note: added
simp only
rw [← Function.update_eq_self i v, h, ← det_transpose, e.toMatrix_update, ← updateRow_transpose,
← e.toMatrix_transpose_apply]
apply det_zero_of_row_eq hij
rw [updateRow_ne hij.symm, updateRow_self]
theorem Basis.det_apply (v : ι → M) : e.det v = Matrix.det (e.toMatrix v) :=
rfl
theorem Basis.det_self : e.det e = 1 := by simp [e.det_apply]
@[simp]
theorem Basis.det_isEmpty [IsEmpty ι] : e.det = AlternatingMap.constOfIsEmpty R M ι 1 := by
ext v
exact Matrix.det_isEmpty
/-- `Basis.det` is not the zero map. -/
theorem Basis.det_ne_zero [Nontrivial R] : e.det ≠ 0 := fun h => by simpa [h] using e.det_self
theorem Basis.smul_det {G} [Group G] [DistribMulAction G M] [SMulCommClass G R M]
(g : G) (v : ι → M) :
(g • e).det v = e.det (g⁻¹ • v) := by
simp_rw [det_apply, toMatrix_smul_left]
theorem is_basis_iff_det {v : ι → M} :
LinearIndependent R v ∧ span R (Set.range v) = ⊤ ↔ IsUnit (e.det v) := by
constructor
· rintro ⟨hli, hspan⟩
set v' := Basis.mk hli hspan.ge
rw [e.det_apply]
convert LinearEquiv.isUnit_det (LinearEquiv.refl R M) v' e using 2
ext i j
simp [v']
· intro h
rw [Basis.det_apply, Basis.toMatrix_eq_toMatrix_constr] at h
set v' := Basis.map e (LinearEquiv.ofIsUnitDet h) with v'_def
have : ⇑v' = v := by
ext i
rw [v'_def, Basis.map_apply, LinearEquiv.ofIsUnitDet_apply, e.constr_basis]
rw [← this]
exact ⟨v'.linearIndependent, v'.span_eq⟩
theorem Basis.isUnit_det (e' : Basis ι R M) : IsUnit (e.det e') :=
(is_basis_iff_det e).mp ⟨e'.linearIndependent, e'.span_eq⟩
/-- Any alternating map to `R` where `ι` has the cardinality of a basis equals the determinant
map with respect to that basis, multiplied by the value of that alternating map on that basis. -/
theorem AlternatingMap.eq_smul_basis_det (f : M [⋀^ι]→ₗ[R] R) : f = f e • e.det := by
refine Basis.ext_alternating e fun i h => ?_
let σ : Equiv.Perm ι := Equiv.ofBijective i (Finite.injective_iff_bijective.1 h)
change f (e ∘ σ) = (f e • e.det) (e ∘ σ)
simp [AlternatingMap.map_perm, Basis.det_self]
@[simp]
theorem AlternatingMap.map_basis_eq_zero_iff {ι : Type*} [Finite ι] (e : Basis ι R M)
(f : M [⋀^ι]→ₗ[R] R) : f e = 0 ↔ f = 0 :=
⟨fun h => by
cases nonempty_fintype ι
letI := Classical.decEq ι
simpa [h] using f.eq_smul_basis_det e,
fun h => h.symm ▸ AlternatingMap.zero_apply _⟩
theorem AlternatingMap.map_basis_ne_zero_iff {ι : Type*} [Finite ι] (e : Basis ι R M)
(f : M [⋀^ι]→ₗ[R] R) : f e ≠ 0 ↔ f ≠ 0 :=
not_congr <| f.map_basis_eq_zero_iff e
variable {A : Type*} [CommRing A] [Module A M]
@[simp]
theorem Basis.det_comp (e : Basis ι A M) (f : M →ₗ[A] M) (v : ι → M) :
e.det (f ∘ v) = (LinearMap.det f) * e.det v := by
rw [Basis.det_apply, Basis.det_apply, ← f.det_toMatrix e, ← Matrix.det_mul,
e.toMatrix_eq_toMatrix_constr (f ∘ v), e.toMatrix_eq_toMatrix_constr v, ← toMatrix_comp,
e.constr_comp]
@[simp]
theorem Basis.det_comp_basis [Module A M'] (b : Basis ι A M) (b' : Basis ι A M') (f : M →ₗ[A] M') :
b'.det (f ∘ b) = LinearMap.det (f ∘ₗ (b'.equiv b (Equiv.refl ι) : M' →ₗ[A] M)) := by
rw [Basis.det_apply, ← LinearMap.det_toMatrix b', LinearMap.toMatrix_comp _ b, Matrix.det_mul,
LinearMap.toMatrix_basis_equiv, Matrix.det_one, mul_one]
congr 1; ext i j
rw [Basis.toMatrix_apply, LinearMap.toMatrix_apply, Function.comp_apply]
theorem Basis.det_reindex {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M) (v : ι' → M)
(e : ι ≃ ι') : (b.reindex e).det v = b.det (v ∘ e) := by
rw [Basis.det_apply, Basis.toMatrix_reindex', det_reindexAlgEquiv, Basis.det_apply]
theorem Basis.det_reindex' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M)
(e : ι ≃ ι') : (b.reindex e).det = b.det.domDomCongr e :=
AlternatingMap.ext fun _ => Basis.det_reindex _ _ _
theorem Basis.det_reindex_symm {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M)
(v : ι → M) (e : ι' ≃ ι) : (b.reindex e.symm).det (v ∘ e) = b.det v := by
rw [Basis.det_reindex, Function.comp.assoc, e.self_comp_symm, Function.comp_id]
@[simp]
theorem Basis.det_map (b : Basis ι R M) (f : M ≃ₗ[R] M') (v : ι → M') :
(b.map f).det v = b.det (f.symm ∘ v) := by
rw [Basis.det_apply, Basis.toMatrix_map, Basis.det_apply]
theorem Basis.det_map' (b : Basis ι R M) (f : M ≃ₗ[R] M') :
(b.map f).det = b.det.compLinearMap f.symm :=
AlternatingMap.ext <| b.det_map f
@[simp]
theorem Pi.basisFun_det : (Pi.basisFun R ι).det = Matrix.detRowAlternating := by
ext M
rw [Basis.det_apply, Basis.coePiBasisFun.toMatrix_eq_transpose, det_transpose]
/-- If we fix a background basis `e`, then for any other basis `v`, we can characterise the
coordinates provided by `v` in terms of determinants relative to `e`. -/
theorem Basis.det_smul_mk_coord_eq_det_update {v : ι → M} (hli : LinearIndependent R v)
(hsp : ⊤ ≤ span R (range v)) (i : ι) :
e.det v • (Basis.mk hli hsp).coord i = e.det.toMultilinearMap.toLinearMap v i := by
apply (Basis.mk hli hsp).ext
intro k
rcases eq_or_ne k i with (rfl | hik) <;>
simp only [Algebra.id.smul_eq_mul, Basis.coe_mk, LinearMap.smul_apply, LinearMap.coe_mk,
MultilinearMap.toLinearMap_apply]
· rw [Basis.mk_coord_apply_eq, mul_one, update_eq_self]
congr
· rw [Basis.mk_coord_apply_ne hik, mul_zero, eq_comm]
exact e.det.map_eq_zero_of_eq _ (by simp [hik, Function.update_apply]) hik
/-- If a basis is multiplied columnwise by scalars `w : ι → Rˣ`, then the determinant with respect
to this basis is multiplied by the product of the inverse of these scalars. -/
theorem Basis.det_unitsSMul (e : Basis ι R M) (w : ι → Rˣ) :
(e.unitsSMul w).det = (↑(∏ i, w i)⁻¹ : R) • e.det := by
ext f
change
(Matrix.det fun i j => (e.unitsSMul w).repr (f j) i) =
(↑(∏ i, w i)⁻¹ : R) • Matrix.det fun i j => e.repr (f j) i
simp only [e.repr_unitsSMul]
convert Matrix.det_mul_column (fun i => (↑(w i)⁻¹ : R)) fun i j => e.repr (f j) i
-- porting note (#10745): was `simp [← Finset.prod_inv_distrib]`
simp only [← Finset.prod_inv_distrib]
norm_cast
/-- The determinant of a basis constructed by `unitsSMul` is the product of the given units. -/
@[simp]
theorem Basis.det_unitsSMul_self (w : ι → Rˣ) : e.det (e.unitsSMul w) = ∏ i, (w i : R) := by
simp [Basis.det_apply]
/-- The determinant of a basis constructed by `isUnitSMul` is the product of the given units. -/
@[simp]
theorem Basis.det_isUnitSMul {w : ι → R} (hw : ∀ i, IsUnit (w i)) :
e.det (e.isUnitSMul hw) = ∏ i, w i :=
e.det_unitsSMul_self _
|
LinearAlgebra\DFinsupp.lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau
-/
import Mathlib.Data.Finsupp.ToDFinsupp
import Mathlib.LinearAlgebra.Finsupp
import Mathlib.LinearAlgebra.LinearIndependent
/-!
# Properties of the module `Π₀ i, M i`
Given an indexed collection of `R`-modules `M i`, the `R`-module structure on `Π₀ i, M i`
is defined in `Data.DFinsupp`.
In this file we define `LinearMap` versions of various maps:
* `DFinsupp.lsingle a : M →ₗ[R] Π₀ i, M i`: `DFinsupp.single a` as a linear map;
* `DFinsupp.lmk s : (Π i : (↑s : Set ι), M i) →ₗ[R] Π₀ i, M i`: `DFinsupp.single a` as a linear map;
* `DFinsupp.lapply i : (Π₀ i, M i) →ₗ[R] M`: the map `fun f ↦ f i` as a linear map;
* `DFinsupp.lsum`: `DFinsupp.sum` or `DFinsupp.liftAddHom` as a `LinearMap`;
## Implementation notes
This file should try to mirror `LinearAlgebra.Finsupp` where possible. The API of `Finsupp` is
much more developed, but many lemmas in that file should be eligible to copy over.
## Tags
function with finite support, module, linear algebra
-/
variable {ι : Type*} {R : Type*} {S : Type*} {M : ι → Type*} {N : Type*}
namespace DFinsupp
variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
variable [AddCommMonoid N] [Module R N]
section DecidableEq
variable [DecidableEq ι]
/-- `DFinsupp.mk` as a `LinearMap`. -/
def lmk (s : Finset ι) : (∀ i : (↑s : Set ι), M i) →ₗ[R] Π₀ i, M i where
toFun := mk s
map_add' _ _ := mk_add
map_smul' c x := mk_smul c x
/-- `DFinsupp.single` as a `LinearMap` -/
def lsingle (i) : M i →ₗ[R] Π₀ i, M i :=
{ DFinsupp.singleAddHom _ _ with
toFun := single i
map_smul' := single_smul }
/-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere. -/
theorem lhom_ext ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄ (h : ∀ i x, φ (single i x) = ψ (single i x)) : φ = ψ :=
LinearMap.toAddMonoidHom_injective <| addHom_ext h
/-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere.
See note [partially-applied ext lemmas].
After apply this lemma, if `M = R` then it suffices to verify `φ (single a 1) = ψ (single a 1)`. -/
@[ext 1100]
theorem lhom_ext' ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄ (h : ∀ i, φ.comp (lsingle i) = ψ.comp (lsingle i)) :
φ = ψ :=
lhom_ext fun i => LinearMap.congr_fun (h i)
-- This lemma has always been bad, but the linter only noticed after lean4#2644.
@[simp, nolint simpNF]
theorem lmk_apply (s : Finset ι) (x) : (lmk s : _ →ₗ[R] Π₀ i, M i) x = mk s x :=
rfl
@[simp]
theorem lsingle_apply (i : ι) (x : M i) : (lsingle i : (M i) →ₗ[R] _) x = single i x :=
rfl
end DecidableEq
/-- Interpret `fun (f : Π₀ i, M i) ↦ f i` as a linear map. -/
def lapply (i : ι) : (Π₀ i, M i) →ₗ[R] M i where
toFun f := f i
map_add' f g := add_apply f g i
map_smul' c f := smul_apply c f i
@[simp]
theorem lapply_apply (i : ι) (f : Π₀ i, M i) : (lapply i : (Π₀ i, M i) →ₗ[R] _) f = f i :=
rfl
section Lsum
-- Porting note: Unclear how true these docstrings are in lean 4
/-- Typeclass inference can't find `DFinsupp.addCommMonoid` without help for this case.
This instance allows it to be found where it is needed on the LHS of the colon in
`DFinsupp.moduleOfLinearMap`. -/
instance addCommMonoidOfLinearMap : AddCommMonoid (Π₀ i : ι, M i →ₗ[R] N) :=
inferInstance
/-- Typeclass inference can't find `DFinsupp.module` without help for this case.
This is needed to define `DFinsupp.lsum` below.
The cause seems to be an inability to unify the `∀ i, AddCommMonoid (M i →ₗ[R] N)` instance that
we have with the `∀ i, Zero (M i →ₗ[R] N)` instance which appears as a parameter to the
`DFinsupp` type. -/
instance moduleOfLinearMap [Semiring S] [Module S N] [SMulCommClass R S N] :
Module S (Π₀ i : ι, M i →ₗ[R] N) :=
DFinsupp.module
variable (S)
variable [DecidableEq ι]
instance {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S)
{σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : Type*) (M₂ : Type*)
[AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] :
EquivLike (LinearEquiv σ M M₂) M M₂ :=
inferInstance
/- Porting note: In every application of lsum that follows, the argument M needs to be explicitly
supplied, lean does not manage to gather that information itself -/
/-- The `DFinsupp` version of `Finsupp.lsum`.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/
@[simps]
def lsum [Semiring S] [Module S N] [SMulCommClass R S N] :
(∀ i, M i →ₗ[R] N) ≃ₗ[S] (Π₀ i, M i) →ₗ[R] N where
toFun F :=
{ toFun := sumAddHom fun i => (F i).toAddMonoidHom
map_add' := (DFinsupp.liftAddHom fun (i : ι) => (F i).toAddMonoidHom).map_add
map_smul' := fun c f => by
dsimp
apply DFinsupp.induction f
· rw [smul_zero, AddMonoidHom.map_zero, smul_zero]
· intro a b f _ _ hf
rw [smul_add, AddMonoidHom.map_add, AddMonoidHom.map_add, smul_add, hf, ← single_smul,
sumAddHom_single, sumAddHom_single, LinearMap.toAddMonoidHom_coe,
LinearMap.map_smul] }
invFun F i := F.comp (lsingle i)
left_inv F := by
ext
simp
right_inv F := by
refine DFinsupp.lhom_ext' (fun i ↦ ?_)
ext
simp
map_add' F G := by
refine DFinsupp.lhom_ext' (fun i ↦ ?_)
ext
simp
map_smul' c F := by
refine DFinsupp.lhom_ext' (fun i ↦ ?_)
ext
simp
/-- While `simp` can prove this, it is often convenient to avoid unfolding `lsum` into `sumAddHom`
with `DFinsupp.lsum_apply_apply`. -/
theorem lsum_single [Semiring S] [Module S N] [SMulCommClass R S N] (F : ∀ i, M i →ₗ[R] N) (i)
(x : M i) : lsum S (M := M) F (single i x) = F i x := by
simp
end Lsum
/-! ### Bundled versions of `DFinsupp.mapRange`
The names should match the equivalent bundled `Finsupp.mapRange` definitions.
-/
section mapRange
variable {β β₁ β₂ : ι → Type*}
variable [∀ i, AddCommMonoid (β i)] [∀ i, AddCommMonoid (β₁ i)] [∀ i, AddCommMonoid (β₂ i)]
variable [∀ i, Module R (β i)] [∀ i, Module R (β₁ i)] [∀ i, Module R (β₂ i)]
theorem mapRange_smul (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (r : R)
(hf' : ∀ i x, f i (r • x) = r • f i x) (g : Π₀ i, β₁ i) :
mapRange f hf (r • g) = r • mapRange f hf g := by
ext
simp only [mapRange_apply f, coe_smul, Pi.smul_apply, hf']
/-- `DFinsupp.mapRange` as a `LinearMap`. -/
@[simps! apply]
def mapRange.linearMap (f : ∀ i, β₁ i →ₗ[R] β₂ i) : (Π₀ i, β₁ i) →ₗ[R] Π₀ i, β₂ i :=
{ mapRange.addMonoidHom fun i => (f i).toAddMonoidHom with
toFun := mapRange (fun i x => f i x) fun i => (f i).map_zero
map_smul' := fun r => mapRange_smul _ (fun i => (f i).map_zero) _ fun i => (f i).map_smul r }
@[simp]
theorem mapRange.linearMap_id :
(mapRange.linearMap fun i => (LinearMap.id : β₂ i →ₗ[R] _)) = LinearMap.id := by
ext
simp [linearMap]
theorem mapRange.linearMap_comp (f : ∀ i, β₁ i →ₗ[R] β₂ i) (f₂ : ∀ i, β i →ₗ[R] β₁ i) :
(mapRange.linearMap fun i => (f i).comp (f₂ i)) =
(mapRange.linearMap f).comp (mapRange.linearMap f₂) :=
LinearMap.ext <| mapRange_comp (fun i x => f i x) (fun i x => f₂ i x)
(fun i => (f i).map_zero) (fun i => (f₂ i).map_zero) (by simp)
theorem sum_mapRange_index.linearMap [DecidableEq ι] {f : ∀ i, β₁ i →ₗ[R] β₂ i}
{h : ∀ i, β₂ i →ₗ[R] N} {l : Π₀ i, β₁ i} :
DFinsupp.lsum ℕ h (mapRange.linearMap f l) = DFinsupp.lsum ℕ (fun i => (h i).comp (f i)) l := by
classical simpa [DFinsupp.sumAddHom_apply] using sum_mapRange_index fun i => by simp
/-- `DFinsupp.mapRange.linearMap` as a `LinearEquiv`. -/
@[simps apply]
def mapRange.linearEquiv (e : ∀ i, β₁ i ≃ₗ[R] β₂ i) : (Π₀ i, β₁ i) ≃ₗ[R] Π₀ i, β₂ i :=
{ mapRange.addEquiv fun i => (e i).toAddEquiv,
mapRange.linearMap fun i => (e i).toLinearMap with
toFun := mapRange (fun i x => e i x) fun i => (e i).map_zero
invFun := mapRange (fun i x => (e i).symm x) fun i => (e i).symm.map_zero }
@[simp]
theorem mapRange.linearEquiv_refl :
(mapRange.linearEquiv fun i => LinearEquiv.refl R (β₁ i)) = LinearEquiv.refl _ _ :=
LinearEquiv.ext mapRange_id
theorem mapRange.linearEquiv_trans (f : ∀ i, β i ≃ₗ[R] β₁ i) (f₂ : ∀ i, β₁ i ≃ₗ[R] β₂ i) :
(mapRange.linearEquiv fun i => (f i).trans (f₂ i)) =
(mapRange.linearEquiv f).trans (mapRange.linearEquiv f₂) :=
LinearEquiv.ext <| mapRange_comp (fun i x => f₂ i x) (fun i x => f i x)
(fun i => (f₂ i).map_zero) (fun i => (f i).map_zero) (by simp)
@[simp]
theorem mapRange.linearEquiv_symm (e : ∀ i, β₁ i ≃ₗ[R] β₂ i) :
(mapRange.linearEquiv e).symm = mapRange.linearEquiv fun i => (e i).symm :=
rfl
end mapRange
section CoprodMap
variable [DecidableEq ι]
/-- Given a family of linear maps `f i : M i →ₗ[R] N`, we can form a linear map
`(Π₀ i, M i) →ₗ[R] N` which sends `x : Π₀ i, M i` to the sum over `i` of `f i` applied to `x i`.
This is the map coming from the universal property of `Π₀ i, M i` as the coproduct of the `M i`.
See also `LinearMap.coprod` for the binary product version. -/
def coprodMap (f : ∀ i : ι, M i →ₗ[R] N) : (Π₀ i, M i) →ₗ[R] N :=
(DFinsupp.lsum ℕ fun _ : ι => LinearMap.id) ∘ₗ DFinsupp.mapRange.linearMap f
theorem coprodMap_apply [∀ x : N, Decidable (x ≠ 0)] (f : ∀ i : ι, M i →ₗ[R] N) (x : Π₀ i, M i) :
coprodMap f x =
DFinsupp.sum (mapRange (fun i => f i) (fun _ => LinearMap.map_zero _) x) fun _ =>
id :=
DFinsupp.sumAddHom_apply _ _
theorem coprodMap_apply_single (f : ∀ i : ι, M i →ₗ[R] N) (i : ι) (x : M i) :
coprodMap f (single i x) = f i x := by
simp [coprodMap]
end CoprodMap
end DFinsupp
namespace Submodule
variable [Semiring R] [AddCommMonoid N] [Module R N]
open DFinsupp
section DecidableEq
variable [DecidableEq ι]
theorem dfinsupp_sum_mem {β : ι → Type*} [∀ i, Zero (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)]
(S : Submodule R N) (f : Π₀ i, β i) (g : ∀ i, β i → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) :
f.sum g ∈ S :=
_root_.dfinsupp_sum_mem S f g h
theorem dfinsupp_sumAddHom_mem {β : ι → Type*} [∀ i, AddZeroClass (β i)] (S : Submodule R N)
(f : Π₀ i, β i) (g : ∀ i, β i →+ N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) :
DFinsupp.sumAddHom g f ∈ S :=
_root_.dfinsupp_sumAddHom_mem S f g h
/-- The supremum of a family of submodules is equal to the range of `DFinsupp.lsum`; that is
every element in the `iSup` can be produced from taking a finite number of non-zero elements
of `p i`, coercing them to `N`, and summing them. -/
theorem iSup_eq_range_dfinsupp_lsum (p : ι → Submodule R N) :
iSup p = LinearMap.range (DFinsupp.lsum ℕ (M := fun i ↦ ↥(p i)) fun i => (p i).subtype) := by
apply le_antisymm
· apply iSup_le _
intro i y hy
simp only [LinearMap.mem_range, lsum_apply_apply]
exact ⟨DFinsupp.single i ⟨y, hy⟩, DFinsupp.sumAddHom_single _ _ _⟩
· rintro x ⟨v, rfl⟩
exact dfinsupp_sumAddHom_mem _ v _ fun i _ => (le_iSup p i : p i ≤ _) (v i).2
/-- The bounded supremum of a family of commutative additive submonoids is equal to the range of
`DFinsupp.sumAddHom` composed with `DFinsupp.filter_add_monoid_hom`; that is, every element in the
bounded `iSup` can be produced from taking a finite number of non-zero elements from the `S i` that
satisfy `p i`, coercing them to `γ`, and summing them. -/
theorem biSup_eq_range_dfinsupp_lsum (p : ι → Prop) [DecidablePred p] (S : ι → Submodule R N) :
⨆ (i) (_ : p i), S i =
LinearMap.range
(LinearMap.comp
(DFinsupp.lsum ℕ (M := fun i ↦ ↥(S i)) (fun i => (S i).subtype))
(DFinsupp.filterLinearMap R _ p)) := by
apply le_antisymm
· refine iSup₂_le fun i hi y hy => ⟨DFinsupp.single i ⟨y, hy⟩, ?_⟩
rw [LinearMap.comp_apply, filterLinearMap_apply, filter_single_pos _ _ hi]
simp only [lsum_apply_apply, sumAddHom_single, LinearMap.toAddMonoidHom_coe, coeSubtype]
· rintro x ⟨v, rfl⟩
refine dfinsupp_sumAddHom_mem _ _ _ fun i _ => ?_
refine mem_iSup_of_mem i ?_
by_cases hp : p i
· simp [hp]
· simp [hp]
/-- A characterisation of the span of a family of submodules.
See also `Submodule.mem_iSup_iff_exists_finsupp`. -/
theorem mem_iSup_iff_exists_dfinsupp (p : ι → Submodule R N) (x : N) :
x ∈ iSup p ↔
∃ f : Π₀ i, p i, DFinsupp.lsum ℕ (M := fun i ↦ ↥(p i)) (fun i => (p i).subtype) f = x :=
SetLike.ext_iff.mp (iSup_eq_range_dfinsupp_lsum p) x
/-- A variant of `Submodule.mem_iSup_iff_exists_dfinsupp` with the RHS fully unfolded.
See also `Submodule.mem_iSup_iff_exists_finsupp`. -/
theorem mem_iSup_iff_exists_dfinsupp' (p : ι → Submodule R N) [∀ (i) (x : p i), Decidable (x ≠ 0)]
(x : N) : x ∈ iSup p ↔ ∃ f : Π₀ i, p i, (f.sum fun i xi => ↑xi) = x := by
rw [mem_iSup_iff_exists_dfinsupp]
simp_rw [DFinsupp.lsum_apply_apply, DFinsupp.sumAddHom_apply,
LinearMap.toAddMonoidHom_coe, coeSubtype]
theorem mem_biSup_iff_exists_dfinsupp (p : ι → Prop) [DecidablePred p] (S : ι → Submodule R N)
(x : N) :
(x ∈ ⨆ (i) (_ : p i), S i) ↔
∃ f : Π₀ i, S i,
DFinsupp.lsum ℕ (M := fun i ↦ ↥(S i)) (fun i => (S i).subtype) (f.filter p) = x :=
SetLike.ext_iff.mp (biSup_eq_range_dfinsupp_lsum p S) x
end DecidableEq
lemma mem_iSup_iff_exists_finsupp (p : ι → Submodule R N) (x : N) :
x ∈ iSup p ↔ ∃ (f : ι →₀ N), (∀ i, f i ∈ p i) ∧ (f.sum fun _i xi ↦ xi) = x := by
classical
rw [mem_iSup_iff_exists_dfinsupp']
refine ⟨fun ⟨f, hf⟩ ↦ ⟨⟨f.support, fun i ↦ (f i : N), by simp⟩, by simp, hf⟩, ?_⟩
rintro ⟨f, hf, rfl⟩
refine ⟨DFinsupp.mk f.support fun i ↦ ⟨f i, hf i⟩, Finset.sum_congr ?_ fun i hi ↦ ?_⟩
· ext; simp
· simp [Finsupp.mem_support_iff.mp hi]
theorem mem_iSup_finset_iff_exists_sum {s : Finset ι} (p : ι → Submodule R N) (a : N) :
(a ∈ ⨆ i ∈ s, p i) ↔ ∃ μ : ∀ i, p i, (∑ i ∈ s, (μ i : N)) = a := by
classical
rw [Submodule.mem_iSup_iff_exists_dfinsupp']
constructor <;> rintro ⟨μ, hμ⟩
· use fun i => ⟨μ i, (iSup_const_le : _ ≤ p i) (coe_mem <| μ i)⟩
rw [← hμ]
symm
apply Finset.sum_subset
· intro x
contrapose
intro hx
rw [mem_support_iff, not_ne_iff]
ext
rw [coe_zero, ← mem_bot R]
suffices ⊥ = ⨆ (_ : x ∈ s), p x from this.symm ▸ coe_mem (μ x)
exact (iSup_neg hx).symm
· intro x _ hx
rw [mem_support_iff, not_ne_iff] at hx
rw [hx]
rfl
· refine ⟨DFinsupp.mk s ?_, ?_⟩
· rintro ⟨i, hi⟩
refine ⟨μ i, ?_⟩
rw [iSup_pos]
· exact coe_mem _
· exact hi
simp only [DFinsupp.sum]
rw [Finset.sum_subset support_mk_subset, ← hμ]
· exact Finset.sum_congr rfl fun x hx => congr_arg Subtype.val <| mk_of_mem hx
· intro x _ hx
rw [mem_support_iff, not_ne_iff] at hx
rw [hx]
rfl
end Submodule
namespace CompleteLattice
open DFinsupp
section Semiring
variable [DecidableEq ι] [Semiring R] [AddCommMonoid N] [Module R N]
/-- Independence of a family of submodules can be expressed as a quantifier over `DFinsupp`s.
This is an intermediate result used to prove
`CompleteLattice.independent_of_dfinsupp_lsum_injective` and
`CompleteLattice.Independent.dfinsupp_lsum_injective`. -/
theorem independent_iff_forall_dfinsupp (p : ι → Submodule R N) :
Independent p ↔
∀ (i) (x : p i) (v : Π₀ i : ι, ↥(p i)),
lsum ℕ (M := fun i ↦ ↥(p i)) (fun i => (p i).subtype) (erase i v) = x → x = 0 := by
simp_rw [CompleteLattice.independent_def, Submodule.disjoint_def,
Submodule.mem_biSup_iff_exists_dfinsupp, exists_imp, filter_ne_eq_erase]
refine forall_congr' fun i => Subtype.forall'.trans ?_
simp_rw [Submodule.coe_eq_zero]
/- If `DFinsupp.lsum` applied with `Submodule.subtype` is injective then the submodules are
independent. -/
theorem independent_of_dfinsupp_lsum_injective (p : ι → Submodule R N)
(h : Function.Injective (lsum ℕ (M := fun i ↦ ↥(p i)) fun i => (p i).subtype)) :
Independent p := by
rw [independent_iff_forall_dfinsupp]
intro i x v hv
replace hv : lsum ℕ (M := fun i ↦ ↥(p i)) (fun i => (p i).subtype) (erase i v) =
lsum ℕ (M := fun i ↦ ↥(p i)) (fun i => (p i).subtype) (single i x) := by
simpa only [lsum_single] using hv
have := DFunLike.ext_iff.mp (h hv) i
simpa [eq_comm] using this
/- If `DFinsupp.sumAddHom` applied with `AddSubmonoid.subtype` is injective then the additive
submonoids are independent. -/
theorem independent_of_dfinsupp_sumAddHom_injective (p : ι → AddSubmonoid N)
(h : Function.Injective (sumAddHom fun i => (p i).subtype)) : Independent p := by
rw [← independent_map_orderIso_iff (AddSubmonoid.toNatSubmodule : AddSubmonoid N ≃o _)]
exact independent_of_dfinsupp_lsum_injective _ h
/-- Combining `DFinsupp.lsum` with `LinearMap.toSpanSingleton` is the same as `Finsupp.total` -/
theorem lsum_comp_mapRange_toSpanSingleton [∀ m : R, Decidable (m ≠ 0)] (p : ι → Submodule R N)
{v : ι → N} (hv : ∀ i : ι, v i ∈ p i) :
(lsum ℕ (M := fun i ↦ ↥(p i)) fun i => (p i).subtype : _ →ₗ[R] _).comp
((mapRange.linearMap fun i => LinearMap.toSpanSingleton R (↥(p i)) ⟨v i, hv i⟩ :
_ →ₗ[R] _).comp
(finsuppLequivDFinsupp R : (ι →₀ R) ≃ₗ[R] _).toLinearMap) =
Finsupp.total ι N R v := by
ext
simp
end Semiring
section Ring
variable [DecidableEq ι] [Ring R] [AddCommGroup N] [Module R N]
/- If `DFinsupp.sumAddHom` applied with `AddSubmonoid.subtype` is injective then the additive
subgroups are independent. -/
theorem independent_of_dfinsupp_sumAddHom_injective' (p : ι → AddSubgroup N)
(h : Function.Injective (sumAddHom fun i => (p i).subtype)) : Independent p := by
rw [← independent_map_orderIso_iff (AddSubgroup.toIntSubmodule : AddSubgroup N ≃o _)]
exact independent_of_dfinsupp_lsum_injective _ h
/-- The canonical map out of a direct sum of a family of submodules is injective when the submodules
are `CompleteLattice.Independent`.
Note that this is not generally true for `[Semiring R]`, for instance when `A` is the
`ℕ`-submodules of the positive and negative integers.
See `Counterexamples/DirectSumIsInternal.lean` for a proof of this fact. -/
theorem Independent.dfinsupp_lsum_injective {p : ι → Submodule R N} (h : Independent p) :
Function.Injective (lsum ℕ (M := fun i ↦ ↥(p i)) fun i => (p i).subtype) := by
-- simplify everything down to binders over equalities in `N`
rw [independent_iff_forall_dfinsupp] at h
suffices LinearMap.ker (lsum ℕ (M := fun i ↦ ↥(p i)) fun i => (p i).subtype) = ⊥ by
-- Lean can't find this without our help
letI thisI : AddCommGroup (Π₀ i, p i) := inferInstance
rw [LinearMap.ker_eq_bot] at this
exact this
rw [LinearMap.ker_eq_bot']
intro m hm
ext i : 1
-- split `m` into the piece at `i` and the pieces elsewhere, to match `h`
rw [DFinsupp.zero_apply, ← neg_eq_zero]
refine h i (-m i) m ?_
rwa [← erase_add_single i m, LinearMap.map_add, lsum_single, Submodule.subtype_apply,
add_eq_zero_iff_eq_neg, ← Submodule.coe_neg] at hm
/-- The canonical map out of a direct sum of a family of additive subgroups is injective when the
additive subgroups are `CompleteLattice.Independent`. -/
theorem Independent.dfinsupp_sumAddHom_injective {p : ι → AddSubgroup N} (h : Independent p) :
Function.Injective (sumAddHom fun i => (p i).subtype) := by
rw [← independent_map_orderIso_iff (AddSubgroup.toIntSubmodule : AddSubgroup N ≃o _)] at h
exact h.dfinsupp_lsum_injective
/-- A family of submodules over an additive group are independent if and only iff `DFinsupp.lsum`
applied with `Submodule.subtype` is injective.
Note that this is not generally true for `[Semiring R]`; see
`CompleteLattice.Independent.dfinsupp_lsum_injective` for details. -/
theorem independent_iff_dfinsupp_lsum_injective (p : ι → Submodule R N) :
Independent p ↔ Function.Injective (lsum ℕ (M := fun i ↦ ↥(p i)) fun i => (p i).subtype) :=
⟨Independent.dfinsupp_lsum_injective, independent_of_dfinsupp_lsum_injective p⟩
/-- A family of additive subgroups over an additive group are independent if and only if
`DFinsupp.sumAddHom` applied with `AddSubgroup.subtype` is injective. -/
theorem independent_iff_dfinsupp_sumAddHom_injective (p : ι → AddSubgroup N) :
Independent p ↔ Function.Injective (sumAddHom fun i => (p i).subtype) :=
⟨Independent.dfinsupp_sumAddHom_injective, independent_of_dfinsupp_sumAddHom_injective' p⟩
/-- If a family of submodules is `Independent`, then a choice of nonzero vector from each submodule
forms a linearly independent family.
See also `CompleteLattice.Independent.linearIndependent'`. -/
theorem Independent.linearIndependent [NoZeroSMulDivisors R N] {ι} (p : ι → Submodule R N)
(hp : Independent p) {v : ι → N} (hv : ∀ i, v i ∈ p i) (hv' : ∀ i, v i ≠ 0) :
LinearIndependent R v := by
let _ := Classical.decEq ι
let _ := Classical.decEq R
rw [linearIndependent_iff]
intro l hl
let a :=
DFinsupp.mapRange.linearMap (fun i => LinearMap.toSpanSingleton R (p i) ⟨v i, hv i⟩)
l.toDFinsupp
have ha : a = 0 := by
apply hp.dfinsupp_lsum_injective
rwa [← lsum_comp_mapRange_toSpanSingleton _ hv] at hl
ext i
apply smul_left_injective R (hv' i)
have : l i • v i = a i := rfl
simp only [coe_zero, Pi.zero_apply, ZeroMemClass.coe_zero, smul_eq_zero, ha] at this
simpa
theorem independent_iff_linearIndependent_of_ne_zero [NoZeroSMulDivisors R N] {ι} {v : ι → N}
(h_ne_zero : ∀ i, v i ≠ 0) : (Independent fun i => R ∙ v i) ↔ LinearIndependent R v :=
let _ := Classical.decEq ι
⟨fun hv => hv.linearIndependent _ (fun i => Submodule.mem_span_singleton_self <| v i) h_ne_zero,
fun hv => hv.independent_span_singleton⟩
end Ring
end CompleteLattice
namespace LinearMap
section AddCommMonoid
variable {R : Type*} {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} {R₄ : Type*}
variable {S : Type*}
variable {K : Type*} {K₂ : Type*}
variable {M : Type*} {M' : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*} {M₄ : Type*}
variable {N : Type*} {N₂ : Type*}
variable {ι : Type*}
variable {V : Type*} {V₂ : Type*}
variable [Semiring R] [Semiring R₂] [Semiring R₃]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃}
variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃]
variable [Module R M] [Module R₂ M₂] [Module R₃ M₃]
open Submodule
section DFinsupp
open DFinsupp
variable {γ : ι → Type*} [DecidableEq ι]
section Sum
variable [∀ i, Zero (γ i)] [∀ (i) (x : γ i), Decidable (x ≠ 0)]
theorem coe_dfinsupp_sum (t : Π₀ i, γ i) (g : ∀ i, γ i → M →ₛₗ[σ₁₂] M₂) :
⇑(t.sum g) = t.sum fun i d => g i d := rfl
@[simp]
theorem dfinsupp_sum_apply (t : Π₀ i, γ i) (g : ∀ i, γ i → M →ₛₗ[σ₁₂] M₂) (b : M) :
(t.sum g) b = t.sum fun i d => g i d b :=
sum_apply _ _ _
end Sum
section SumAddHom
variable [∀ i, AddZeroClass (γ i)]
@[simp]
theorem map_dfinsupp_sumAddHom (f : M →ₛₗ[σ₁₂] M₂) {t : Π₀ i, γ i} {g : ∀ i, γ i →+ M} :
f (sumAddHom g t) = sumAddHom (fun i => f.toAddMonoidHom.comp (g i)) t :=
f.toAddMonoidHom.map_dfinsupp_sumAddHom _ _
end SumAddHom
end DFinsupp
end AddCommMonoid
end LinearMap
namespace LinearEquiv
variable {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*} {ι : Type*}
section DFinsupp
open DFinsupp
variable [Semiring R] [Semiring R₂]
variable [AddCommMonoid M] [AddCommMonoid M₂]
variable [Module R M] [Module R₂ M₂]
variable {τ₁₂ : R →+* R₂} {τ₂₁ : R₂ →+* R}
variable [RingHomInvPair τ₁₂ τ₂₁] [RingHomInvPair τ₂₁ τ₁₂]
variable {γ : ι → Type*} [DecidableEq ι]
@[simp]
theorem map_dfinsupp_sumAddHom [∀ i, AddZeroClass (γ i)] (f : M ≃ₛₗ[τ₁₂] M₂) (t : Π₀ i, γ i)
(g : ∀ i, γ i →+ M) :
f (sumAddHom g t) = sumAddHom (fun i => f.toAddEquiv.toAddMonoidHom.comp (g i)) t :=
f.toAddEquiv.map_dfinsupp_sumAddHom _ _
end DFinsupp
end LinearEquiv
|
LinearAlgebra\Dual.lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Fabian Glöckle, Kyle Miller
-/
import Mathlib.LinearAlgebra.FiniteDimensional
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition
import Mathlib.LinearAlgebra.Projection
import Mathlib.LinearAlgebra.SesquilinearForm
import Mathlib.RingTheory.TensorProduct.Basic
import Mathlib.RingTheory.LocalRing.Basic
/-!
# 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.
* Bases:
* `Basis.toDual` produces the map `M →ₗ[R] Dual R M` associated to a basis for an `R`-module `M`.
* `Basis.toDual_equiv` 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.dual_bases e ε` is the proposition that the families `e` of vectors and `ε` of dual
vectors have the characteristic properties of a basis and a dual.
* 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.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`).
* `Submodule.dualPairing W` is the canonical pairing between `Dual R M ⧸ W.dualAnnihilator`
and `W`. It is nondegenerate for vector spaces (`Subspace.dualPairing_nondegenerate`).
* Vector spaces:
* `Subspace.dualLift W` is an arbitrary section (using choice) of `Submodule.dualRestrict W`.
## Main results
* Bases:
* `Module.dualBasis.basis` and `Module.dualBasis.coe_basis`: if `e` and `ε` form a dual pair,
then `e` is a basis.
* `Module.dualBasis.coe_dualBasis`: if `e` and `ε` form a dual pair,
then `ε` is a basis.
* Annihilators:
* `Module.dualAnnihilator_gc R M` is the antitone Galois correspondence between
`Submodule.dualAnnihilator` and `Submodule.dualConnihilator`.
* `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_dualConnihilator_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:
* `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)`.
* `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₁`.
-/
noncomputable section
namespace Module
-- Porting note: max u v universe issues so name and specific below
universe uR uA uM uM' uM''
variable (R : Type uR) (A : Type uA) (M : Type uM)
variable [CommSemiring R] [AddCommMonoid M] [Module R M]
/-- The dual space of an R-module M is the R-module of linear maps `M → R`. -/
abbrev Dual :=
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 : 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 uM'}
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
-- Porting note: with reducible def need to specify some parameters to transpose explicitly
theorem transpose_apply (u : M →ₗ[R] M') (l : Dual R M') : transpose (R := R) u l = l.comp u :=
rfl
variable {M'' : Type uM''} [AddCommMonoid M''] [Module R M'']
-- Porting note: with reducible def need to specify some parameters to transpose explicitly
theorem transpose_comp (u : M' →ₗ[R] M'') (v : M →ₗ[R] M') :
transpose (R := R) (u.comp v) = (transpose (R := R) v).comp (transpose (R := R) u) :=
rfl
end Dual
section Prod
variable (M' : Type uM') [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 DualMap
open Module
universe u v v'
variable {R : Type u} [CommSemiring R] {M₁ : Type v} {M₂ : Type v'}
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₁ :=
-- Porting note: with reducible def need to specify some parameters to transpose explicitly
Module.Dual.transpose (R := R) f
lemma LinearMap.dualMap_eq_lcomp (f : M₁ →ₗ[R] M₂) : f.dualMap = f.lcomp R := rfl
-- Porting note: with reducible def need to specify some parameters to transpose explicitly
theorem LinearMap.dualMap_def (f : M₁ →ₗ[R] M₂) : f.dualMap = Module.Dual.transpose (R := R) 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*} [AddCommGroup 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 `Linear_equiv` 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*} [AddCommGroup M₃] [Module R M₃] (f : M₁ ≃ₗ[R] M₂)
(g : M₂ ≃ₗ[R] M₃) : g.dualMap.trans f.dualMap = (f.trans g).dualMap :=
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 Basis
universe u v w
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] [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
erw [constr_basis b, constr_basis b]
simp only [eq_comm]
@[simp]
theorem toDual_total_left (f : ι →₀ R) (i : ι) :
b.toDual (Finsupp.total ι M R b f) (b i) = f i := by
rw [Finsupp.total_apply, Finsupp.sum, _root_.map_sum, LinearMap.sum_apply]
simp_rw [LinearMap.map_smul, LinearMap.smul_apply, toDual_apply, smul_eq_mul, mul_boole,
Finset.sum_ite_eq']
split_ifs with h
· rfl
· rw [Finsupp.not_mem_support_iff.mp h]
@[simp]
theorem toDual_total_right (f : ι →₀ R) (i : ι) :
b.toDual (b i) (Finsupp.total ι M R b f) = f i := by
rw [Finsupp.total_apply, Finsupp.sum, _root_.map_sum]
simp_rw [LinearMap.map_smul, toDual_apply, smul_eq_mul, mul_boole, Finset.sum_ite_eq]
split_ifs with h
· rfl
· rw [Finsupp.not_mem_support_iff.mp h]
theorem toDual_apply_left (m : M) (i : ι) : b.toDual m (b i) = b.repr m i := by
rw [← b.toDual_total_left, b.total_repr]
theorem toDual_apply_right (i : ι) (m : M) : b.toDual (b i) m = b.repr m i := by
rw [← b.toDual_total_right, b.total_repr]
theorem coe_toDual_self (i : ι) : b.toDual (b i) = b.coord i := by
ext
apply toDual_apply_right
/-- `h.toDual_flip 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 [_root_.map_zero])
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.ker
theorem toDual_ker : LinearMap.ker b.toDual = ⊥ :=
ker_eq_bot'.mpr b.toDual_inj
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range
theorem toDual_range [Finite ι] : LinearMap.range b.toDual = ⊤ := by
refine eq_top_iff'.2 fun f => ?_
let lin_comb : ι →₀ R := Finsupp.equivFunOnFinite.symm fun i => f (b i)
refine ⟨Finsupp.total ι M R b lin_comb, b.ext fun i => ?_⟩
rw [b.toDual_eq_repr _ i, repr_total b]
rfl
end CommSemiring
section
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [Fintype ι]
variable (b : Basis ι R M)
@[simp]
theorem sum_dual_apply_smul_coord (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, ← _root_.map_sum, Basis.coord_apply, Basis.sum_repr]
end
section CommRing
variable [CommRing R] [AddCommGroup M] [Module R M] [DecidableEq ι]
variable (b : Basis ι R M)
section Finite
variable [Finite ι]
/-- A vector space is linearly equivalent to its dual space. -/
def toDualEquiv : M ≃ₗ[R] Dual R M :=
LinearEquiv.ofBijective b.toDual ⟨ker_eq_bot.mp b.toDual_ker, 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
-- 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 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_alpeh0_iff]
by_contra!
apply (lift_rank_lt_rank_dual this).ne
have := e.lift_rank_eq
rwa [lift_umax.{uV,uK}, lift_id'.{uV,uK}] at this
/-- 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 total_dualBasis (f : ι →₀ R) (i : ι) :
Finsupp.total ι (Dual R M) R b.dualBasis f (b i) = f i := by
cases nonempty_fintype ι
rw [Finsupp.total_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]
theorem dualBasis_repr (l : Dual R M) (i : ι) : b.dualBasis.repr l i = l (b i) := by
rw [← total_dualBasis b, Basis.total_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_ker {ι : Type*} (b : Basis ι R M) :
LinearMap.ker (Dual.eval R M) = ⊥ := by
rw [ker_eq_bot']
intro m hm
simp_rw [LinearMap.ext_iff, Dual.eval_apply, zero_apply] at hm
exact (Basis.forall_coord_eq_zero_iff _).mp fun i => hm (b.coord i)
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range
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 _]
section
variable [Finite R M] [Free R M]
instance dual_free : Free R (Dual R M) :=
Free.of_basis (Free.chooseBasis R M).dualBasis
instance dual_finite : Finite R (Dual R M) :=
Finite.of_basis (Free.chooseBasis R M).dualBasis
end
end CommRing
/-- `simp` normal form version of `total_dualBasis` -/
@[simp]
theorem total_coord [CommRing R] [AddCommGroup M] [Module R M] [Finite ι] (b : Basis ι R M)
(f : ι →₀ R) (i : ι) : Finsupp.total ι (Dual R M) R b.coord f (b i) = f i := by
haveI := Classical.decEq ι
rw [← coe_dualBasis, total_dualBasis]
theorem dual_rank_eq [CommRing K] [AddCommGroup V] [Module K V] [Finite ι] (b : Basis ι K V) :
Cardinal.lift.{uK,uV} (Module.rank K V) = Module.rank K (Dual K V) := by
classical rw [← lift_umax.{uV,uK}, b.toDualEquiv.lift_rank_eq, lift_id'.{uV,uK}]
end Basis
namespace Module
universe uK uV
variable {K : Type uK} {V : Type uV}
variable [CommRing K] [AddCommGroup V] [Module K V] [Module.Free K V]
open Module Module.Dual Submodule LinearMap Cardinal Basis FiniteDimensional
section
variable (K) (V)
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.ker
theorem eval_ker : LinearMap.ker (eval K V) = ⊥ := by
classical exact (Module.Free.chooseBasis K V).eval_ker
theorem map_eval_injective : (Submodule.map (eval K V)).Injective := by
apply Submodule.map_injective_of_injective
rw [← LinearMap.ker_eq_bot]
exact eval_ker K V
theorem comap_eval_surjective : (Submodule.comap (eval K V)).Surjective := by
apply Submodule.comap_surjective_of_injective
rw [← LinearMap.ker_eq_bot]
exact eval_ker K V
end
section
variable (K)
theorem eval_apply_eq_zero_iff (v : V) : (eval K V) v = 0 ↔ v = 0 := by
simpa only using SetLike.ext_iff.mp (eval_ker K V) v
theorem eval_apply_injective : Function.Injective (eval K V) :=
(injective_iff_map_eq_zero' (eval K V)).mpr (eval_apply_eq_zero_iff K)
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]
rfl
@[simp]
theorem subsingleton_dual_iff :
Subsingleton (Dual K V) ↔ Subsingleton V := by
refine ⟨fun h ↦ ⟨fun v w ↦ ?_⟩, fun h ↦ ⟨fun f g ↦ ?_⟩⟩
· rw [← sub_eq_zero, ← forall_dual_apply_eq_zero_iff K (v - w)]
intros f
simp [Subsingleton.elim f 0]
· ext v
simp [Subsingleton.elim v 0]
instance instSubsingletonDual [Subsingleton V] : Subsingleton (Dual K V) :=
(subsingleton_dual_iff K).mp 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
theorem finite_dual_iff : Finite K (Dual K V) ↔ Finite K V := by
constructor <;> intro h
· obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := K) (M := V)
nontriviality K
obtain ⟨⟨s, span_s⟩⟩ := h
classical
haveI := (b.linearIndependent.map' _ b.toDual_ker).finite_of_le_span_finite _ s ?_
· exact Finite.of_basis b
· rw [span_s]; apply le_top
· infer_instance
end
theorem dual_rank_eq [Module.Finite K V] :
Cardinal.lift.{uK,uV} (Module.rank K V) = Module.rank K (Dual K V) :=
(Module.Free.chooseBasis K V).dual_rank_eq
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range
theorem erange_coe [Module.Finite K V] : LinearMap.range (eval K V) = ⊤ :=
(Module.Free.chooseBasis K V).eval_range
section IsReflexive
open Function
variable (R M N : Type*) [CommRing R] [AddCommGroup M] [AddCommGroup 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 free module (and thus any finite-dimensional vector space) is reflexive.
See `Module.IsReflexive.of_finite_of_free`. -/
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'
instance IsReflexive.of_finite_of_free [Finite R M] [Free R M] : IsReflexive R M where
bijective_dual_eval' := ⟨LinearMap.ker_eq_bot.mp (Free.chooseBasis R M).eval_ker,
LinearMap.range_eq_top.mp (Free.chooseBasis R M).eval_range⟩
variable [IsReflexive R M]
/-- 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
/-- 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⟩
/-- 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
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, LinearEquiv.trans_symm, LinearEquiv.symm_symm, LinearEquiv.dualMap_symm,
coe_comp, LinearEquiv.coe_coe, EquivLike.comp_bijective]
exact (bijective_dual_eval R M).prodMap (bijective_dual_eval R N)
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, LinearEquiv.trans_symm, LinearEquiv.symm_symm, LinearEquiv.dualMap_symm,
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 _
instance _root_.ULift.instModuleIsReflexive.{w} : IsReflexive R (ULift.{w} M) :=
equiv ULift.moduleEquiv.symm
end IsReflexive
end Module
namespace Submodule
open Module
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {p : Submodule R M}
theorem exists_dual_map_eq_bot_of_nmem {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
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_nmem hx hp'
exact ⟨f, by aesop, hf'⟩
end Submodule
section DualBases
open Module
variable {R M ι : Type*}
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [DecidableEq ι]
-- Porting note: replace use_finite_instance tactic
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 -/
-- @[nolint has_nonempty_instance] Porting note (#5171): removed
structure Module.DualBases (e : ι → M) (ε : ι → Dual R M) : Prop where
eval : ∀ i j : ι, ε i (e j) = if i = j then 1 else 0
protected total : ∀ {m : M}, (∀ i, ε i m = 0) → m = 0
protected finite : ∀ m : M, { i | ε i m ≠ 0 }.Finite := by
use_finite_instance
end DualBases
namespace Module.DualBases
open Module Module.Dual LinearMap Function
variable {R M ι : Type*}
variable [CommRing R] [AddCommGroup M] [Module R M]
variable {e : ι → M} {ε : ι → Dual R M}
/-- The coefficients of `v` on the basis `e` -/
def coeffs [DecidableEq ι] (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 [DecidableEq ι] (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.total _ M 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.total _ _ R e l :=
rfl
open Module
variable [DecidableEq ι] (h : DualBases e ε)
theorem dual_lc (l : ι →₀ R) (i : ι) : ε i (DualBases.lc e l) = l i := by
rw [lc, _root_.map_finsupp_sum, Finsupp.sum_eq_single i (g := fun a b ↦ (ε i) (b • e a))]
-- Porting note: cannot get at •
-- simp only [h.eval, map_smul, smul_eq_mul]
· simp [h.eval, smul_eq_mul]
· intro q _ q_ne
simp [q_ne.symm, h.eval, 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 := by
refine eq_of_sub_eq_zero <| h.total fun i ↦ ?_
simp [LinearMap.map_sub, h.dual_lc, sub_eq_zero]
/-- `(h : DualBases e ε).basis` shows the family of vectors `e` forms a basis. -/
@[simps]
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 }
-- Porting note: from simpNF the LHS simplifies; it yields lc_def.symm
-- probably not a useful simp lemma; nolint simpNF since it cannot see this removal
attribute [-simp, nolint simpNF] basis_repr_symm_apply
@[simp]
theorem coe_basis : ⇑h.basis = e := by
ext i
rw [Basis.apply_eq_iff]
ext j
rw [h.basis_repr_apply, coeffs_apply, h.eval, Finsupp.single_apply]
convert if_congr (eq_comm (a := j) (b := i)) rfl rfl
-- `convert` to get rid of a `DecidableEq` mismatch
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_total _).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 [_root_.Finite ι] : ⇑h.basis.dualBasis = ε :=
funext fun i =>
h.basis.ext fun j => by
rw [h.basis.dualBasis_apply_self, h.coe_basis, h.eval, if_congr eq_comm rfl rfl]
end Module.DualBases
namespace Submodule
universe u v w
variable {R : Type u} {M : Type v} [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 : Type u} {M : Type v} [CommSemiring R] [AddCommMonoid M] [Module R M]
(W : Submodule R M) : Submodule R <| Module.Dual R M :=
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.ker
LinearMap.ker W.dualRestrict
@[simp]
theorem mem_dualAnnihilator (φ : Module.Dual R M) : φ ∈ W.dualAnnihilator ↔ ∀ w ∈ W, φ w = 0 := by
refine LinearMap.mem_ker.trans ?_
simp_rw [LinearMap.ext_iff, dualRestrict_apply]
exact ⟨fun h w hw => h ⟨w, hw⟩, fun h w => h w.1 w.2⟩
/-- 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) :
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.ker
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]
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]
constructor <;>
· intro h x hx
simp only [mem_dualAnnihilator, mem_dualCoannihilator]
intro y hy
have := h hy
simp only [mem_dualAnnihilator, mem_dualCoannihilator] at this
exact this x hx
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
rw [eq_bot_iff]
intro v
simp_rw [mem_dualAnnihilator, mem_bot, mem_top, forall_true_left]
exact fun h => LinearMap.ext h
@[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)
end Submodule
namespace Subspace
open Submodule LinearMap
universe u v w
-- We work in vector spaces because `exists_is_compl` only hold for vector spaces
variable {K : Type u} {V : Type v} [Field K] [AddCommGroup V] [Module K V]
@[simp]
theorem dualCoannihilator_top (W : Subspace K V) :
(⊤ : Subspace K (Module.Dual K W)).dualCoannihilator = ⊥ := by
rw [dualCoannihilator, dualAnnihilator_top, comap_bot, Module.eval_ker]
@[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 =>
show W.dualRestrict.comp W.dualLift x = x by
rw [dualRestrict_comp_dualLift]
rfl
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`. -/
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.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
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. -/
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range
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
-- Porting note: this prevents the timeout; ML3 proof preserved below
-- refine' _ ≪≫ₗ W.quotDualEquivAnnihilator
-- refine' LinearEquiv.quot_equiv_of_equiv _ (Basis.ofVectorSpace K V).toDualEquiv
-- exact (Basis.ofVectorSpace K W).toDualEquiv.trans W.dual_equiv_dual
open FiniteDimensional
@[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]
-- Porting note: LinearEquiv.finrank_eq needs help
let equiv := W.quotEquivAnnihilator
have eq := LinearEquiv.finrank_eq (R := K) (M := (Module.Dual K V) ⧸ W)
(M₂ := { x // x ∈ dualAnnihilator W }) equiv
rw [eq.symm, add_comm, Submodule.finrank_quotient_add_finrank, Subspace.dual_finrank_eq]
end
end Subspace
open Module
namespace LinearMap
universe uR uM₁ uM₂
variable {R : Type uR} [CommSemiring R] {M₁ : Type uM₁} {M₂ : Type uM₂}
variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂]
variable (f : M₁ →ₗ[R] M₂)
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.ker
theorem ker_dualMap_eq_dualAnnihilator_range :
LinearMap.ker f.dualMap = f.range.dualAnnihilator := by
ext
simp_rw [mem_ker, LinearMap.ext_iff, Submodule.mem_dualAnnihilator,
← SetLike.mem_coe, range_coe, Set.forall_mem_range]
rfl
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range
theorem range_dualMap_le_dualAnnihilator_ker :
LinearMap.range f.dualMap ≤ f.ker.dualAnnihilator := by
rintro _ ⟨ψ, rfl⟩
simp_rw [Submodule.mem_dualAnnihilator, mem_ker]
rintro x hx
rw [dualMap_apply, hx, map_zero]
end LinearMap
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)
-- Porting note: helper instance
instance (W : Submodule R M) : FunLike (W.dualAnnihilator) M R :=
{ coe := fun φ => φ.val,
coe_injective' := fun φ ψ h => by
ext
simp only [Function.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
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range
/-- 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 φ =>
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.mem_range_self
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)] :
Finite R W.dualAnnihilator ↔ Finite R (M ⧸ W) :=
(Finite.equiv_iff W.dualQuotEquivDualAnnihilator.symm).trans (finite_dual_iff R)
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
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range
theorem range_dualMap_eq_dualAnnihilator_ker_of_surjective (f : M →ₗ[R] M')
(hf : Function.Surjective f) : LinearMap.range f.dualMap = f.ker.dualAnnihilator :=
((f.quotKerEquivOfSurjective hf).dualMap.range_comp _).trans f.ker.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 f.range.subtype.dualMap) :
LinearMap.range f.dualMap = f.ker.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
-- Porting note (#11036): broken dot notation lean4#1910
· 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
theorem ker_dualMap_eq_dualCoannihilator_range (f : M →ₗ[R] M') :
LinearMap.ker f.dualMap = (Dual.eval R M' ∘ₗ f).range.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 CommRing
section VectorSpace
-- Porting note: adding `uK` to avoid timeouts in `dualPairing_eq`
universe uK uV₁ uV₂
variable {K : Type uK} [Field K] {V₁ : Type uV₁} {V₂ : Type uV₂}
variable [AddCommGroup V₁] [Module K V₁] [AddCommGroup V₂] [Module K V₂]
namespace Module.Dual
variable [FiniteDimensional K V₁] {f : Module.Dual K V₁} (hf : f ≠ 0)
open FiniteDimensional
lemma range_eq_top_of_ne_zero :
LinearMap.range f = ⊤ := by
obtain ⟨v, hv⟩ : ∃ v, f v ≠ 0 := by contrapose! hf; ext v; simpa using hf v
rw [eq_top_iff]
exact fun x _ ↦ ⟨x • (f v)⁻¹ • v, by simp [inv_mul_cancel hv]⟩
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]
lemma eq_of_ker_eq_of_apply_eq {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)⟩
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range
theorem range_dualMap_eq_dualAnnihilator_ker (f : V₁ →ₗ[K] V₂) :
LinearMap.range f.dualMap = f.ker.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
-- Porting note: remove this at some point; this spends a lot of time
-- checking that AddCommGroup structures on V₁ ⧸ W.dualAnnihilator are defEq
-- was much worse with implicit universe variables
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')
-- Porting note (#11036): broken dot notation lean4#1910 LinearMap.ker
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 infi and supr 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 FiniteDimensional LinearMap
namespace LinearMap
@[simp]
theorem finrank_range_dualMap_eq_finrank_range (f : V₁ →ₗ[K] V₂) :
-- Porting note (#11036): broken dot notation lean4#1910
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 _ ↦ by
#adaptation_note
/--
After https://github.com/leanprover/lean4/pull/4119
the `Free K W` instance isn't found unless we use `set_option maxSynthPendingDepth 2`, or add
explicit instances:
```
have := Free.of_divisionRing K ↥W
have := Basis.dual_finite (R := K) (M := W)
```
-/
set_option maxSynthPendingDepth 2 in
exact 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 [FiniteDimensional.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
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 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 [CommRing R] [AddCommGroup M] [AddCommGroup 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 :=
-- Porting note: ∑ (i) (j) does not seem to work; applyₗ needs a little help to unify
∑ i, ∑ j,
(ringLmapEquivSelf R ℕ _).symm (b.dualBasis i ⊗ₜ c.dualBasis j) ∘ₗ
(applyₗ (R := R) (c j)) ∘ₗ (applyₗ (R := R) (b i)) ∘ₗ lcurry 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]
-- Porting note: introduced to help with timeout in dualDistribEquivOfBasis
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, ne_eq, _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 * }
-- Porting note: introduced to help with timeout in dualDistribEquivOfBasis
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,
ne_eq, 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
|
LinearAlgebra\FiniteDimensional.lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.LinearAlgebra.FiniteDimensional.Defs
import Mathlib.LinearAlgebra.Dimension.FreeAndStrongRankCondition
import Mathlib.LinearAlgebra.Dimension.DivisionRing
/-!
# Finite dimensional vector spaces
This file contains some further development of finite dimensional vector spaces, their dimensions,
and linear maps on such spaces.
Definitions and results that require fewer imports are in
`Mathlib.LinearAlgebra.FiniteDimensional.Defs`.
-/
universe u v v'
open Cardinal Submodule Module Function
variable {K : Type u} {V : Type v}
namespace Submodule
open IsNoetherian FiniteDimensional
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V]
/-- In a finite-dimensional vector space, the dimensions of a submodule and of the corresponding
quotient add up to the dimension of the space. -/
theorem finrank_quotient_add_finrank [FiniteDimensional K V] (s : Submodule K V) :
finrank K (V ⧸ s) + finrank K s = finrank K V := by
have := rank_quotient_add_rank s
rw [← finrank_eq_rank, ← finrank_eq_rank, ← finrank_eq_rank] at this
exact mod_cast this
/-- The dimension of a strict submodule is strictly bounded by the dimension of the ambient
space. -/
theorem finrank_lt [FiniteDimensional K V] {s : Submodule K V} (h : s < ⊤) :
finrank K s < finrank K V := by
rw [← s.finrank_quotient_add_finrank, add_comm]
exact Nat.lt_add_of_pos_right (finrank_pos_iff.mpr (Quotient.nontrivial_of_lt_top _ h))
/-- The sum of the dimensions of s + t and s ∩ t is the sum of the dimensions of s and t -/
theorem finrank_sup_add_finrank_inf_eq (s t : Submodule K V) [FiniteDimensional K s]
[FiniteDimensional K t] :
finrank K ↑(s ⊔ t) + finrank K ↑(s ⊓ t) = finrank K ↑s + finrank K ↑t := by
have key : Module.rank K ↑(s ⊔ t) + Module.rank K ↑(s ⊓ t) = Module.rank K s + Module.rank K t :=
rank_sup_add_rank_inf_eq s t
repeat rw [← finrank_eq_rank] at key
norm_cast at key
theorem finrank_add_le_finrank_add_finrank (s t : Submodule K V) [FiniteDimensional K s]
[FiniteDimensional K t] : finrank K (s ⊔ t : Submodule K V) ≤ finrank K s + finrank K t := by
rw [← finrank_sup_add_finrank_inf_eq]
exact self_le_add_right _ _
theorem eq_top_of_disjoint [FiniteDimensional K V] (s t : Submodule K V)
(hdim : finrank K s + finrank K t = finrank K V) (hdisjoint : Disjoint s t) : s ⊔ t = ⊤ := by
have h_finrank_inf : finrank K ↑(s ⊓ t) = 0 := by
rw [disjoint_iff_inf_le, le_bot_iff] at hdisjoint
rw [hdisjoint, finrank_bot]
apply eq_top_of_finrank_eq
rw [← hdim]
convert s.finrank_sup_add_finrank_inf_eq t
rw [h_finrank_inf]
rfl
theorem finrank_add_finrank_le_of_disjoint [FiniteDimensional K V]
{s t : Submodule K V} (hdisjoint : Disjoint s t) :
finrank K s + finrank K t ≤ finrank K V := by
rw [← Submodule.finrank_sup_add_finrank_inf_eq s t, hdisjoint.eq_bot, finrank_bot, add_zero]
exact Submodule.finrank_le _
end DivisionRing
end Submodule
namespace FiniteDimensional
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
variable [FiniteDimensional K V] [FiniteDimensional K V₂]
/-- Given isomorphic subspaces `p q` of vector spaces `V` and `V₁` respectively,
`p.quotient` is isomorphic to `q.quotient`. -/
noncomputable def LinearEquiv.quotEquivOfEquiv {p : Subspace K V} {q : Subspace K V₂}
(f₁ : p ≃ₗ[K] q) (f₂ : V ≃ₗ[K] V₂) : (V ⧸ p) ≃ₗ[K] V₂ ⧸ q :=
LinearEquiv.ofFinrankEq _ _
(by
rw [← @add_right_cancel_iff _ _ _ (finrank K p), Submodule.finrank_quotient_add_finrank,
LinearEquiv.finrank_eq f₁, Submodule.finrank_quotient_add_finrank,
LinearEquiv.finrank_eq f₂])
-- TODO: generalize to the case where one of `p` and `q` is finite-dimensional.
/-- Given the subspaces `p q`, if `p.quotient ≃ₗ[K] q`, then `q.quotient ≃ₗ[K] p` -/
noncomputable def LinearEquiv.quotEquivOfQuotEquiv {p q : Subspace K V} (f : (V ⧸ p) ≃ₗ[K] q) :
(V ⧸ q) ≃ₗ[K] p :=
LinearEquiv.ofFinrankEq _ _ <|
add_right_cancel <| by
rw [Submodule.finrank_quotient_add_finrank, ← LinearEquiv.finrank_eq f, add_comm,
Submodule.finrank_quotient_add_finrank]
end DivisionRing
end FiniteDimensional
namespace LinearMap
open FiniteDimensional
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
/-- rank-nullity theorem : the dimensions of the kernel and the range of a linear map add up to
the dimension of the source space. -/
theorem finrank_range_add_finrank_ker [FiniteDimensional K V] (f : V →ₗ[K] V₂) :
finrank K (LinearMap.range f) + finrank K (LinearMap.ker f) = finrank K V := by
rw [← f.quotKerEquivRange.finrank_eq]
exact Submodule.finrank_quotient_add_finrank _
lemma ker_ne_bot_of_finrank_lt [FiniteDimensional K V] [FiniteDimensional K V₂] {f : V →ₗ[K] V₂}
(h : finrank K V₂ < finrank K V) :
LinearMap.ker f ≠ ⊥ := by
have h₁ := f.finrank_range_add_finrank_ker
have h₂ : finrank K (LinearMap.range f) ≤ finrank K V₂ := (LinearMap.range f).finrank_le
suffices 0 < finrank K (LinearMap.ker f) from Submodule.one_le_finrank_iff.mp this
omega
end DivisionRing
end LinearMap
open FiniteDimensional
namespace LinearMap
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
theorem injective_iff_surjective_of_finrank_eq_finrank [FiniteDimensional K V]
[FiniteDimensional K V₂] (H : finrank K V = finrank K V₂) {f : V →ₗ[K] V₂} :
Function.Injective f ↔ Function.Surjective f := by
have := finrank_range_add_finrank_ker f
rw [← ker_eq_bot, ← range_eq_top]; refine ⟨fun h => ?_, fun h => ?_⟩
· rw [h, finrank_bot, add_zero, H] at this
exact eq_top_of_finrank_eq this
· rw [h, finrank_top, H] at this
exact Submodule.finrank_eq_zero.1 (add_right_injective _ this)
theorem ker_eq_bot_iff_range_eq_top_of_finrank_eq_finrank [FiniteDimensional K V]
[FiniteDimensional K V₂] (H : finrank K V = finrank K V₂) {f : V →ₗ[K] V₂} :
LinearMap.ker f = ⊥ ↔ LinearMap.range f = ⊤ := by
rw [range_eq_top, ker_eq_bot, injective_iff_surjective_of_finrank_eq_finrank H]
/-- Given a linear map `f` between two vector spaces with the same dimension, if
`ker f = ⊥` then `linearEquivOfInjective` is the induced isomorphism
between the two vector spaces. -/
noncomputable def linearEquivOfInjective [FiniteDimensional K V] [FiniteDimensional K V₂]
(f : V →ₗ[K] V₂) (hf : Injective f) (hdim : finrank K V = finrank K V₂) : V ≃ₗ[K] V₂ :=
LinearEquiv.ofBijective f
⟨hf, (LinearMap.injective_iff_surjective_of_finrank_eq_finrank hdim).mp hf⟩
@[simp]
theorem linearEquivOfInjective_apply [FiniteDimensional K V] [FiniteDimensional K V₂]
{f : V →ₗ[K] V₂} (hf : Injective f) (hdim : finrank K V = finrank K V₂) (x : V) :
f.linearEquivOfInjective hf hdim x = f x :=
rfl
end LinearMap
namespace Submodule
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
theorem finrank_lt_finrank_of_lt {s t : Submodule K V} [FiniteDimensional K t] (hst : s < t) :
finrank K s < finrank K t :=
(comapSubtypeEquivOfLe hst.le).finrank_eq.symm.trans_lt <|
finrank_lt (le_top.lt_of_ne <| hst.not_le ∘ comap_subtype_eq_top.1)
theorem finrank_strictMono [FiniteDimensional K V] :
StrictMono fun s : Submodule K V => finrank K s := fun _ _ => finrank_lt_finrank_of_lt
theorem finrank_add_eq_of_isCompl [FiniteDimensional K V] {U W : Submodule K V} (h : IsCompl U W) :
finrank K U + finrank K W = finrank K V := by
rw [← finrank_sup_add_finrank_inf_eq, h.codisjoint.eq_top, h.disjoint.eq_bot, finrank_bot,
add_zero]
exact finrank_top _ _
end DivisionRing
end Submodule
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V]
section Basis
theorem LinearIndependent.span_eq_top_of_card_eq_finrank' {ι : Type*}
[Fintype ι] [FiniteDimensional K V] {b : ι → V} (lin_ind : LinearIndependent K b)
(card_eq : Fintype.card ι = finrank K V) : span K (Set.range b) = ⊤ := by
by_contra ne_top
rw [← finrank_span_eq_card lin_ind] at card_eq
exact ne_of_lt (Submodule.finrank_lt <| lt_top_iff_ne_top.2 ne_top) card_eq
theorem LinearIndependent.span_eq_top_of_card_eq_finrank {ι : Type*} [Nonempty ι]
[Fintype ι] {b : ι → V} (lin_ind : LinearIndependent K b)
(card_eq : Fintype.card ι = finrank K V) : span K (Set.range b) = ⊤ :=
have : FiniteDimensional K V := .of_finrank_pos <| card_eq ▸ Fintype.card_pos
lin_ind.span_eq_top_of_card_eq_finrank' card_eq
@[deprecated (since := "2024-02-14")]
alias span_eq_top_of_linearIndependent_of_card_eq_finrank :=
LinearIndependent.span_eq_top_of_card_eq_finrank
/-- A linear independent family of `finrank K V` vectors forms a basis. -/
@[simps! repr_apply]
noncomputable def basisOfLinearIndependentOfCardEqFinrank {ι : Type*} [Nonempty ι] [Fintype ι]
{b : ι → V} (lin_ind : LinearIndependent K b) (card_eq : Fintype.card ι = finrank K V) :
Basis ι K V :=
Basis.mk lin_ind <| (lin_ind.span_eq_top_of_card_eq_finrank card_eq).ge
@[simp]
theorem coe_basisOfLinearIndependentOfCardEqFinrank {ι : Type*} [Nonempty ι] [Fintype ι]
{b : ι → V} (lin_ind : LinearIndependent K b) (card_eq : Fintype.card ι = finrank K V) :
⇑(basisOfLinearIndependentOfCardEqFinrank lin_ind card_eq) = b :=
Basis.coe_mk _ _
/-- A linear independent finset of `finrank K V` vectors forms a basis. -/
@[simps! repr_apply]
noncomputable def finsetBasisOfLinearIndependentOfCardEqFinrank {s : Finset V} (hs : s.Nonempty)
(lin_ind : LinearIndependent K ((↑) : s → V)) (card_eq : s.card = finrank K V) : Basis s K V :=
@basisOfLinearIndependentOfCardEqFinrank _ _ _ _ _ _
⟨(⟨hs.choose, hs.choose_spec⟩ : s)⟩ _ _ lin_ind (_root_.trans (Fintype.card_coe _) card_eq)
@[simp]
theorem coe_finsetBasisOfLinearIndependentOfCardEqFinrank {s : Finset V} (hs : s.Nonempty)
(lin_ind : LinearIndependent K ((↑) : s → V)) (card_eq : s.card = finrank K V) :
⇑(finsetBasisOfLinearIndependentOfCardEqFinrank hs lin_ind card_eq) = ((↑) : s → V) := by
-- Porting note: added to make the next line unify the `_`s
rw [finsetBasisOfLinearIndependentOfCardEqFinrank]
exact Basis.coe_mk _ _
/-- A linear independent set of `finrank K V` vectors forms a basis. -/
@[simps! repr_apply]
noncomputable def setBasisOfLinearIndependentOfCardEqFinrank {s : Set V} [Nonempty s] [Fintype s]
(lin_ind : LinearIndependent K ((↑) : s → V)) (card_eq : s.toFinset.card = finrank K V) :
Basis s K V :=
basisOfLinearIndependentOfCardEqFinrank lin_ind (_root_.trans s.toFinset_card.symm card_eq)
@[simp]
theorem coe_setBasisOfLinearIndependentOfCardEqFinrank {s : Set V} [Nonempty s] [Fintype s]
(lin_ind : LinearIndependent K ((↑) : s → V)) (card_eq : s.toFinset.card = finrank K V) :
⇑(setBasisOfLinearIndependentOfCardEqFinrank lin_ind card_eq) = ((↑) : s → V) := by
-- Porting note: added to make the next line unify the `_`s
rw [setBasisOfLinearIndependentOfCardEqFinrank]
exact Basis.coe_mk _ _
end Basis
/-!
We now give characterisations of `finrank K V = 1` and `finrank K V ≤ 1`.
-/
section finrank_eq_one
/-- Any `K`-algebra module that is 1-dimensional over `K` is simple. -/
theorem is_simple_module_of_finrank_eq_one {A} [Semiring A] [Module A V] [SMul K A]
[IsScalarTower K A V] (h : finrank K V = 1) : IsSimpleOrder (Submodule A V) := by
haveI := nontrivial_of_finrank_eq_succ h
refine ⟨fun S => or_iff_not_imp_left.2 fun hn => ?_⟩
rw [← restrictScalars_inj K] at hn ⊢
haveI : FiniteDimensional _ _ := .of_finrank_eq_succ h
refine eq_top_of_finrank_eq ((Submodule.finrank_le _).antisymm ?_)
simpa only [h, finrank_bot] using Submodule.finrank_strictMono (Ne.bot_lt hn)
end finrank_eq_one
end DivisionRing
section SubalgebraRank
open Module
variable {F E : Type*} [Field F] [Ring E] [Algebra F E]
theorem Subalgebra.isSimpleOrder_of_finrank (hr : finrank F E = 2) :
IsSimpleOrder (Subalgebra F E) :=
let i := nontrivial_of_finrank_pos (zero_lt_two.trans_eq hr.symm)
{ toNontrivial :=
⟨⟨⊥, ⊤, fun h => by cases hr.symm.trans (Subalgebra.bot_eq_top_iff_finrank_eq_one.1 h)⟩⟩
eq_bot_or_eq_top := by
intro S
haveI : FiniteDimensional F E := .of_finrank_eq_succ hr
haveI : FiniteDimensional F S :=
FiniteDimensional.finiteDimensional_submodule (Subalgebra.toSubmodule S)
have : finrank F S ≤ 2 := hr ▸ S.toSubmodule.finrank_le
have : 0 < finrank F S := finrank_pos_iff.mpr inferInstance
interval_cases h : finrank F { x // x ∈ S }
· left
exact Subalgebra.eq_bot_of_finrank_one h
· right
rw [← hr] at h
rw [← Algebra.toSubmodule_eq_top]
exact eq_top_of_finrank_eq h }
end SubalgebraRank
namespace Module
namespace End
variable [DivisionRing K] [AddCommGroup V] [Module K V]
theorem exists_ker_pow_eq_ker_pow_succ [FiniteDimensional K V] (f : End K V) :
∃ k : ℕ, k ≤ finrank K V ∧ LinearMap.ker (f ^ k) = LinearMap.ker (f ^ k.succ) := by
classical
by_contra h_contra
simp_rw [not_exists, not_and] at h_contra
have h_le_ker_pow : ∀ n : ℕ, n ≤ (finrank K V).succ →
n ≤ finrank K (LinearMap.ker (f ^ n)) := by
intro n hn
induction' n with n ih
· exact zero_le (finrank _ _)
· have h_ker_lt_ker : LinearMap.ker (f ^ n) < LinearMap.ker (f ^ n.succ) := by
refine lt_of_le_of_ne ?_ (h_contra n (Nat.le_of_succ_le_succ hn))
rw [pow_succ']
apply LinearMap.ker_le_ker_comp
have h_finrank_lt_finrank :
finrank K (LinearMap.ker (f ^ n)) < finrank K (LinearMap.ker (f ^ n.succ)) := by
apply Submodule.finrank_lt_finrank_of_lt h_ker_lt_ker
calc
n.succ ≤ (finrank K ↑(LinearMap.ker (f ^ n))).succ :=
Nat.succ_le_succ (ih (Nat.le_of_succ_le hn))
_ ≤ finrank K ↑(LinearMap.ker (f ^ n.succ)) := Nat.succ_le_of_lt h_finrank_lt_finrank
have h_any_n_lt : ∀ n, n ≤ (finrank K V).succ → n ≤ finrank K V := fun n hn =>
(h_le_ker_pow n hn).trans (Submodule.finrank_le _)
show False
exact Nat.not_succ_le_self _ (h_any_n_lt (finrank K V).succ (finrank K V).succ.le_refl)
theorem ker_pow_eq_ker_pow_finrank_of_le [FiniteDimensional K V] {f : End K V} {m : ℕ}
(hm : finrank K V ≤ m) : LinearMap.ker (f ^ m) = LinearMap.ker (f ^ finrank K V) := by
obtain ⟨k, h_k_le, hk⟩ :
∃ k, k ≤ finrank K V ∧ LinearMap.ker (f ^ k) = LinearMap.ker (f ^ k.succ) :=
exists_ker_pow_eq_ker_pow_succ f
calc
LinearMap.ker (f ^ m) = LinearMap.ker (f ^ (k + (m - k))) := by
rw [add_tsub_cancel_of_le (h_k_le.trans hm)]
_ = LinearMap.ker (f ^ k) := by rw [ker_pow_constant hk _]
_ = LinearMap.ker (f ^ (k + (finrank K V - k))) := ker_pow_constant hk (finrank K V - k)
_ = LinearMap.ker (f ^ finrank K V) := by rw [add_tsub_cancel_of_le h_k_le]
theorem ker_pow_le_ker_pow_finrank [FiniteDimensional K V] (f : End K V) (m : ℕ) :
LinearMap.ker (f ^ m) ≤ LinearMap.ker (f ^ finrank K V) := by
by_cases h_cases : m < finrank K V
· rw [← add_tsub_cancel_of_le (Nat.le_of_lt h_cases), add_comm, pow_add]
apply LinearMap.ker_le_ker_comp
· rw [ker_pow_eq_ker_pow_finrank_of_le (le_of_not_lt h_cases)]
end End
end Module
|
LinearAlgebra\FiniteSpan.lean | /-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash, Deepro Choudhury
-/
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.LinearAlgebra.Span
import Mathlib.Algebra.Module.Equiv.Basic
/-!
# Additional results about finite spanning sets in linear algebra
-/
open Set Function
open Submodule (span)
/-- A linear equivalence which preserves a finite spanning set must have finite order. -/
lemma LinearEquiv.isOfFinOrder_of_finite_of_span_eq_top_of_mapsTo
{R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M]
{Φ : Set M} (hΦ₁ : Φ.Finite) (hΦ₂ : span R Φ = ⊤) {e : M ≃ₗ[R] M} (he : MapsTo e Φ Φ) :
IsOfFinOrder e := by
replace he : BijOn e Φ Φ := (hΦ₁.injOn_iff_bijOn_of_mapsTo he).mp e.injective.injOn
let e' := he.equiv
have : Finite Φ := finite_coe_iff.mpr hΦ₁
obtain ⟨k, hk₀, hk⟩ := isOfFinOrder_of_finite e'
refine ⟨k, hk₀, ?_⟩
ext m
have hm : m ∈ span R Φ := hΦ₂ ▸ Submodule.mem_top
simp only [mul_left_iterate, mul_one, LinearEquiv.coe_one, id_eq]
refine Submodule.span_induction hm (fun x hx ↦ ?_) (by simp)
(fun x y hx hy ↦ by simp [map_add, hx, hy]) (fun t x hx ↦ by simp [map_smul, hx])
rw [LinearEquiv.pow_apply, ← he.1.coe_iterate_restrict ⟨x, hx⟩ k]
replace hk : (e') ^ k = 1 := by simpa [IsPeriodicPt, IsFixedPt] using hk
replace hk := Equiv.congr_fun hk ⟨x, hx⟩
rwa [Equiv.Perm.coe_one, id_eq, Subtype.ext_iff, Equiv.Perm.coe_pow] at hk
|
LinearAlgebra\Finsupp.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Finsupp.Encodable
import Mathlib.LinearAlgebra.Pi
import Mathlib.LinearAlgebra.Span
import Mathlib.Data.Set.Countable
/-!
# Properties of the module `α →₀ M`
Given an `R`-module `M`, the `R`-module structure on `α →₀ M` is defined in
`Data.Finsupp.Basic`.
In this file we define `Finsupp.supported s` to be the set `{f : α →₀ M | f.support ⊆ s}`
interpreted as a submodule of `α →₀ M`. We also define `LinearMap` versions of various maps:
* `Finsupp.lsingle a : M →ₗ[R] ι →₀ M`: `Finsupp.single a` as a linear map;
* `Finsupp.lapply a : (ι →₀ M) →ₗ[R] M`: the map `fun f ↦ f a` as a linear map;
* `Finsupp.lsubtypeDomain (s : Set α) : (α →₀ M) →ₗ[R] (s →₀ M)`: restriction to a subtype as a
linear map;
* `Finsupp.restrictDom`: `Finsupp.filter` as a linear map to `Finsupp.supported s`;
* `Finsupp.lsum`: `Finsupp.sum` or `Finsupp.liftAddHom` as a `LinearMap`;
* `Finsupp.total α M R (v : ι → M)`: sends `l : ι → R` to the linear combination of `v i` with
coefficients `l i`;
* `Finsupp.totalOn`: a restricted version of `Finsupp.total` with domain `Finsupp.supported R R s`
and codomain `Submodule.span R (v '' s)`;
* `Finsupp.supportedEquivFinsupp`: a linear equivalence between the functions `α →₀ M` supported
on `s` and the functions `s →₀ M`;
* `Finsupp.lmapDomain`: a linear map version of `Finsupp.mapDomain`;
* `Finsupp.domLCongr`: a `LinearEquiv` version of `Finsupp.domCongr`;
* `Finsupp.congr`: if the sets `s` and `t` are equivalent, then `supported M R s` is equivalent to
`supported M R t`;
* `Finsupp.lcongr`: a `LinearEquiv`alence between `α →₀ M` and `β →₀ N` constructed using
`e : α ≃ β` and `e' : M ≃ₗ[R] N`.
## Tags
function with finite support, module, linear algebra
-/
noncomputable section
open Set LinearMap Submodule
namespace Finsupp
section SMul
variable {α : Type*} {β : Type*} {R : Type*} {M : Type*} {M₂ : Type*}
theorem smul_sum [Zero β] [AddCommMonoid M] [DistribSMul R M] {v : α →₀ β} {c : R} {h : α → β → M} :
c • v.sum h = v.sum fun a b => c • h a b :=
Finset.smul_sum
@[simp]
theorem sum_smul_index_linearMap' [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M₂]
[Module R M₂] {v : α →₀ M} {c : R} {h : α → M →ₗ[R] M₂} :
((c • v).sum fun a => h a) = c • v.sum fun a => h a := by
rw [Finsupp.sum_smul_index', Finsupp.smul_sum]
· simp only [map_smul]
· intro i
exact (h i).map_zero
end SMul
section LinearEquivFunOnFinite
variable (R : Type*) {S : Type*} (M : Type*) (α : Type*)
variable [Finite α] [AddCommMonoid M] [Semiring R] [Module R M]
/-- Given `Finite α`, `linearEquivFunOnFinite R` is the natural `R`-linear equivalence between
`α →₀ β` and `α → β`. -/
@[simps apply]
noncomputable def linearEquivFunOnFinite : (α →₀ M) ≃ₗ[R] α → M :=
{ equivFunOnFinite with
toFun := (⇑)
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
@[simp]
theorem linearEquivFunOnFinite_single [DecidableEq α] (x : α) (m : M) :
(linearEquivFunOnFinite R M α) (single x m) = Pi.single x m :=
equivFunOnFinite_single x m
@[simp]
theorem linearEquivFunOnFinite_symm_single [DecidableEq α] (x : α) (m : M) :
(linearEquivFunOnFinite R M α).symm (Pi.single x m) = single x m :=
equivFunOnFinite_symm_single x m
@[simp]
theorem linearEquivFunOnFinite_symm_coe (f : α →₀ M) : (linearEquivFunOnFinite R M α).symm f = f :=
(linearEquivFunOnFinite R M α).symm_apply_apply f
end LinearEquivFunOnFinite
section LinearEquiv.finsuppUnique
variable (R : Type*) {S : Type*} (M : Type*)
variable [AddCommMonoid M] [Semiring R] [Module R M]
variable (α : Type*) [Unique α]
/-- If `α` has a unique term, then the type of finitely supported functions `α →₀ M` is
`R`-linearly equivalent to `M`. -/
noncomputable def LinearEquiv.finsuppUnique : (α →₀ M) ≃ₗ[R] M :=
{ Finsupp.equivFunOnFinite.trans (Equiv.funUnique α M) with
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
variable {R M}
@[simp]
theorem LinearEquiv.finsuppUnique_apply (f : α →₀ M) :
LinearEquiv.finsuppUnique R M α f = f default :=
rfl
variable {α}
@[simp]
theorem LinearEquiv.finsuppUnique_symm_apply (m : M) :
(LinearEquiv.finsuppUnique R M α).symm m = Finsupp.single default m := by
ext; simp [LinearEquiv.finsuppUnique, Equiv.funUnique, single, Pi.single,
equivFunOnFinite, Function.update]
end LinearEquiv.finsuppUnique
variable {α : Type*} {M : Type*} {N : Type*} {P : Type*} {R : Type*} {S : Type*}
variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M]
variable [AddCommMonoid N] [Module R N]
variable [AddCommMonoid P] [Module R P]
/-- Interpret `Finsupp.single a` as a linear map. -/
def lsingle (a : α) : M →ₗ[R] α →₀ M :=
{ Finsupp.singleAddHom a with map_smul' := fun _ _ => (smul_single _ _ _).symm }
/-- Two `R`-linear maps from `Finsupp X M` which agree on each `single x y` agree everywhere. -/
theorem lhom_ext ⦃φ ψ : (α →₀ M) →ₗ[R] N⦄ (h : ∀ a b, φ (single a b) = ψ (single a b)) : φ = ψ :=
LinearMap.toAddMonoidHom_injective <| addHom_ext h
/-- Two `R`-linear maps from `Finsupp X M` which agree on each `single x y` agree everywhere.
We formulate this fact using equality of linear maps `φ.comp (lsingle a)` and `ψ.comp (lsingle a)`
so that the `ext` tactic can apply a type-specific extensionality lemma to prove equality of these
maps. E.g., if `M = R`, then it suffices to verify `φ (single a 1) = ψ (single a 1)`. -/
-- Porting note: The priority should be higher than `LinearMap.ext`.
@[ext high]
theorem lhom_ext' ⦃φ ψ : (α →₀ M) →ₗ[R] N⦄ (h : ∀ a, φ.comp (lsingle a) = ψ.comp (lsingle a)) :
φ = ψ :=
lhom_ext fun a => LinearMap.congr_fun (h a)
/-- Interpret `fun f : α →₀ M ↦ f a` as a linear map. -/
def lapply (a : α) : (α →₀ M) →ₗ[R] M :=
{ Finsupp.applyAddHom a with map_smul' := fun _ _ => rfl }
section CompatibleSMul
variable (R S M N ι : Type*)
variable [Semiring S] [AddCommMonoid M] [AddCommMonoid N] [Module S M] [Module S N]
instance _root_.LinearMap.CompatibleSMul.finsupp_dom [SMulZeroClass R M] [DistribSMul R N]
[LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul (ι →₀ M) N R S where
map_smul f r m := by
conv_rhs => rw [← sum_single m, map_finsupp_sum, smul_sum]
erw [← sum_single (r • m), sum_mapRange_index single_zero, map_finsupp_sum]
congr; ext i m; exact (f.comp <| lsingle i).map_smul_of_tower r m
instance _root_.LinearMap.CompatibleSMul.finsupp_cod [SMul R M] [SMulZeroClass R N]
[LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul M (ι →₀ N) R S where
map_smul f r m := by ext i; apply ((lapply i).comp f).map_smul_of_tower
end CompatibleSMul
/-- Forget that a function is finitely supported.
This is the linear version of `Finsupp.toFun`. -/
@[simps]
def lcoeFun : (α →₀ M) →ₗ[R] α → M where
toFun := (⇑)
map_add' x y := by
ext
simp
map_smul' x y := by
ext
simp
section LSubtypeDomain
variable (s : Set α)
/-- Interpret `Finsupp.subtypeDomain s` as a linear map. -/
def lsubtypeDomain : (α →₀ M) →ₗ[R] s →₀ M where
toFun := subtypeDomain fun x => x ∈ s
map_add' _ _ := subtypeDomain_add
map_smul' _ _ := ext fun _ => rfl
theorem lsubtypeDomain_apply (f : α →₀ M) :
(lsubtypeDomain s : (α →₀ M) →ₗ[R] s →₀ M) f = subtypeDomain (fun x => x ∈ s) f :=
rfl
end LSubtypeDomain
@[simp]
theorem lsingle_apply (a : α) (b : M) : (lsingle a : M →ₗ[R] α →₀ M) b = single a b :=
rfl
@[simp]
theorem lapply_apply (a : α) (f : α →₀ M) : (lapply a : (α →₀ M) →ₗ[R] M) f = f a :=
rfl
@[simp]
theorem lapply_comp_lsingle_same (a : α) : lapply a ∘ₗ lsingle a = (.id : M →ₗ[R] M) := by ext; simp
@[simp]
theorem lapply_comp_lsingle_of_ne (a a' : α) (h : a ≠ a') :
lapply a ∘ₗ lsingle a' = (0 : M →ₗ[R] M) := by ext; simp [h.symm]
@[simp]
theorem ker_lsingle (a : α) : ker (lsingle a : M →ₗ[R] α →₀ M) = ⊥ :=
ker_eq_bot_of_injective (single_injective a)
theorem lsingle_range_le_ker_lapply (s t : Set α) (h : Disjoint s t) :
⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) ≤
⨅ a ∈ t, ker (lapply a : (α →₀ M) →ₗ[R] M) := by
refine iSup_le fun a₁ => iSup_le fun h₁ => range_le_iff_comap.2 ?_
simp only [(ker_comp _ _).symm, eq_top_iff, SetLike.le_def, mem_ker, comap_iInf, mem_iInf]
intro b _ a₂ h₂
have : a₁ ≠ a₂ := fun eq => h.le_bot ⟨h₁, eq.symm ▸ h₂⟩
exact single_eq_of_ne this
theorem iInf_ker_lapply_le_bot : ⨅ a, ker (lapply a : (α →₀ M) →ₗ[R] M) ≤ ⊥ := by
simp only [SetLike.le_def, mem_iInf, mem_ker, mem_bot, lapply_apply]
exact fun a h => Finsupp.ext h
theorem iSup_lsingle_range : ⨆ a, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) = ⊤ := by
refine eq_top_iff.2 <| SetLike.le_def.2 fun f _ => ?_
rw [← sum_single f]
exact sum_mem fun a _ => Submodule.mem_iSup_of_mem a ⟨_, rfl⟩
theorem disjoint_lsingle_lsingle (s t : Set α) (hs : Disjoint s t) :
Disjoint (⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M))
(⨆ a ∈ t, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) := by
-- Porting note: 2 placeholders are added to prevent timeout.
refine
(Disjoint.mono
(lsingle_range_le_ker_lapply s sᶜ ?_)
(lsingle_range_le_ker_lapply t tᶜ ?_))
?_
· apply disjoint_compl_right
· apply disjoint_compl_right
rw [disjoint_iff_inf_le]
refine le_trans (le_iInf fun i => ?_) iInf_ker_lapply_le_bot
classical
by_cases his : i ∈ s
· by_cases hit : i ∈ t
· exact (hs.le_bot ⟨his, hit⟩).elim
exact inf_le_of_right_le (iInf_le_of_le i <| iInf_le _ hit)
exact inf_le_of_left_le (iInf_le_of_le i <| iInf_le _ his)
theorem span_single_image (s : Set M) (a : α) :
Submodule.span R (single a '' s) = (Submodule.span R s).map (lsingle a : M →ₗ[R] α →₀ M) := by
rw [← span_image]; rfl
variable (M R)
/-- `Finsupp.supported M R s` is the `R`-submodule of all `p : α →₀ M` such that `p.support ⊆ s`. -/
def supported (s : Set α) : Submodule R (α →₀ M) where
carrier := { p | ↑p.support ⊆ s }
add_mem' {p q} hp hq := by
classical
refine Subset.trans (Subset.trans (Finset.coe_subset.2 support_add) ?_) (union_subset hp hq)
rw [Finset.coe_union]
zero_mem' := by
simp only [subset_def, Finset.mem_coe, Set.mem_setOf_eq, mem_support_iff, zero_apply]
intro h ha
exact (ha rfl).elim
smul_mem' a p hp := Subset.trans (Finset.coe_subset.2 support_smul) hp
variable {M}
theorem mem_supported {s : Set α} (p : α →₀ M) : p ∈ supported M R s ↔ ↑p.support ⊆ s :=
Iff.rfl
theorem mem_supported' {s : Set α} (p : α →₀ M) :
p ∈ supported M R s ↔ ∀ x ∉ s, p x = 0 := by
haveI := Classical.decPred fun x : α => x ∈ s; simp [mem_supported, Set.subset_def, not_imp_comm]
theorem mem_supported_support (p : α →₀ M) : p ∈ Finsupp.supported M R (p.support : Set α) := by
rw [Finsupp.mem_supported]
theorem single_mem_supported {s : Set α} {a : α} (b : M) (h : a ∈ s) :
single a b ∈ supported M R s :=
Set.Subset.trans support_single_subset (Finset.singleton_subset_set_iff.2 h)
theorem supported_eq_span_single (s : Set α) :
supported R R s = span R ((fun i => single i 1) '' s) := by
refine (span_eq_of_le _ ?_ (SetLike.le_def.2 fun l hl => ?_)).symm
· rintro _ ⟨_, hp, rfl⟩
exact single_mem_supported R 1 hp
· rw [← l.sum_single]
refine sum_mem fun i il => ?_
-- Porting note: Needed to help this convert quite a bit replacing underscores
convert smul_mem (M := α →₀ R) (x := single i 1) (span R ((fun i => single i 1) '' s)) (l i) ?_
· simp [span]
· apply subset_span
apply Set.mem_image_of_mem _ (hl il)
variable (M)
/-- Interpret `Finsupp.filter s` as a linear map from `α →₀ M` to `supported M R s`. -/
def restrictDom (s : Set α) [DecidablePred (· ∈ s)] : (α →₀ M) →ₗ[R] supported M R s :=
LinearMap.codRestrict _
{ toFun := filter (· ∈ s)
map_add' := fun _ _ => filter_add
map_smul' := fun _ _ => filter_smul } fun l =>
(mem_supported' _ _).2 fun _ => filter_apply_neg (· ∈ s) l
variable {M R}
section
@[simp]
theorem restrictDom_apply (s : Set α) (l : α →₀ M) [DecidablePred (· ∈ s)] :
(restrictDom M R s l : α →₀ M) = Finsupp.filter (· ∈ s) l := rfl
end
theorem restrictDom_comp_subtype (s : Set α) [DecidablePred (· ∈ s)] :
(restrictDom M R s).comp (Submodule.subtype _) = LinearMap.id := by
ext l a
by_cases h : a ∈ s
· simp [h]
simpa [h] using ((mem_supported' R l.1).1 l.2 a h).symm
theorem range_restrictDom (s : Set α) [DecidablePred (· ∈ s)] :
LinearMap.range (restrictDom M R s) = ⊤ :=
range_eq_top.2 <|
Function.RightInverse.surjective <| LinearMap.congr_fun (restrictDom_comp_subtype s)
theorem supported_mono {s t : Set α} (st : s ⊆ t) : supported M R s ≤ supported M R t := fun _ h =>
Set.Subset.trans h st
@[simp]
theorem supported_empty : supported M R (∅ : Set α) = ⊥ :=
eq_bot_iff.2 fun l h => (Submodule.mem_bot R).2 <| by ext; simp_all [mem_supported']
@[simp]
theorem supported_univ : supported M R (Set.univ : Set α) = ⊤ :=
eq_top_iff.2 fun _ _ => Set.subset_univ _
theorem supported_iUnion {δ : Type*} (s : δ → Set α) :
supported M R (⋃ i, s i) = ⨆ i, supported M R (s i) := by
refine le_antisymm ?_ (iSup_le fun i => supported_mono <| Set.subset_iUnion _ _)
haveI := Classical.decPred fun x => x ∈ ⋃ i, s i
suffices
LinearMap.range ((Submodule.subtype _).comp (restrictDom M R (⋃ i, s i))) ≤
⨆ i, supported M R (s i) by
rwa [LinearMap.range_comp, range_restrictDom, Submodule.map_top, range_subtype] at this
rw [range_le_iff_comap, eq_top_iff]
rintro l ⟨⟩
-- Porting note: Was ported as `induction l using Finsupp.induction`
refine Finsupp.induction l ?_ ?_
· exact zero_mem _
· refine fun x a l _ _ => add_mem ?_
by_cases h : ∃ i, x ∈ s i
· simp only [mem_comap, coe_comp, coeSubtype, Function.comp_apply, restrictDom_apply,
mem_iUnion, h, filter_single_of_pos]
cases' h with i hi
exact le_iSup (fun i => supported M R (s i)) i (single_mem_supported R _ hi)
· simp [h]
theorem supported_union (s t : Set α) :
supported M R (s ∪ t) = supported M R s ⊔ supported M R t := by
rw [Set.union_eq_iUnion, supported_iUnion, iSup_bool_eq, cond_true, cond_false]
theorem supported_iInter {ι : Type*} (s : ι → Set α) :
supported M R (⋂ i, s i) = ⨅ i, supported M R (s i) :=
Submodule.ext fun x => by simp [mem_supported, subset_iInter_iff]
theorem supported_inter (s t : Set α) :
supported M R (s ∩ t) = supported M R s ⊓ supported M R t := by
rw [Set.inter_eq_iInter, supported_iInter, iInf_bool_eq]; rfl
theorem disjoint_supported_supported {s t : Set α} (h : Disjoint s t) :
Disjoint (supported M R s) (supported M R t) :=
disjoint_iff.2 <| by rw [← supported_inter, disjoint_iff_inter_eq_empty.1 h, supported_empty]
theorem disjoint_supported_supported_iff [Nontrivial M] {s t : Set α} :
Disjoint (supported M R s) (supported M R t) ↔ Disjoint s t := by
refine ⟨fun h => Set.disjoint_left.mpr fun x hx1 hx2 => ?_, disjoint_supported_supported⟩
rcases exists_ne (0 : M) with ⟨y, hy⟩
have := h.le_bot ⟨single_mem_supported R y hx1, single_mem_supported R y hx2⟩
rw [mem_bot, single_eq_zero] at this
exact hy this
/-- Interpret `Finsupp.restrictSupportEquiv` as a linear equivalence between
`supported M R s` and `s →₀ M`. -/
def supportedEquivFinsupp (s : Set α) : supported M R s ≃ₗ[R] s →₀ M := by
let F : supported M R s ≃ (s →₀ M) := restrictSupportEquiv s M
refine F.toLinearEquiv ?_
have :
(F : supported M R s → ↥s →₀ M) =
(lsubtypeDomain s : (α →₀ M) →ₗ[R] s →₀ M).comp (Submodule.subtype (supported M R s)) :=
rfl
rw [this]
exact LinearMap.isLinear _
section LSum
variable (S)
variable [Module S N] [SMulCommClass R S N]
/-- Lift a family of linear maps `M →ₗ[R] N` indexed by `x : α` to a linear map from `α →₀ M` to
`N` using `Finsupp.sum`. This is an upgraded version of `Finsupp.liftAddHom`.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used.
-/
def lsum : (α → M →ₗ[R] N) ≃ₗ[S] (α →₀ M) →ₗ[R] N where
toFun F :=
{ toFun := fun d => d.sum fun i => F i
map_add' := (liftAddHom (α := α) (M := M) (N := N) fun x => (F x).toAddMonoidHom).map_add
map_smul' := fun c f => by simp [sum_smul_index', smul_sum] }
invFun F x := F.comp (lsingle x)
left_inv F := by
ext x y
simp
right_inv F := by
ext x y
simp
map_add' F G := by
ext x y
simp
map_smul' F G := by
ext x y
simp
@[simp]
theorem coe_lsum (f : α → M →ₗ[R] N) : (lsum S f : (α →₀ M) → N) = fun d => d.sum fun i => f i :=
rfl
theorem lsum_apply (f : α → M →ₗ[R] N) (l : α →₀ M) : Finsupp.lsum S f l = l.sum fun b => f b :=
rfl
theorem lsum_single (f : α → M →ₗ[R] N) (i : α) (m : M) :
Finsupp.lsum S f (Finsupp.single i m) = f i m :=
Finsupp.sum_single_index (f i).map_zero
@[simp] theorem lsum_comp_lsingle (f : α → M →ₗ[R] N) (i : α) :
Finsupp.lsum S f ∘ₗ lsingle i = f i := by ext; simp
theorem lsum_symm_apply (f : (α →₀ M) →ₗ[R] N) (x : α) : (lsum S).symm f x = f.comp (lsingle x) :=
rfl
end LSum
section
variable (M) (R) (X : Type*) (S)
variable [Module S M] [SMulCommClass R S M]
/-- A slight rearrangement from `lsum` gives us
the bijection underlying the free-forgetful adjunction for R-modules.
-/
noncomputable def lift : (X → M) ≃+ ((X →₀ R) →ₗ[R] M) :=
(AddEquiv.arrowCongr (Equiv.refl X) (ringLmapEquivSelf R ℕ M).toAddEquiv.symm).trans
(lsum _ : _ ≃ₗ[ℕ] _).toAddEquiv
@[simp]
theorem lift_symm_apply (f) (x) : ((lift M R X).symm f) x = f (single x 1) :=
rfl
@[simp]
theorem lift_apply (f) (g) : ((lift M R X) f) g = g.sum fun x r => r • f x :=
rfl
/-- Given compatible `S` and `R`-module structures on `M` and a type `X`, the set of functions
`X → M` is `S`-linearly equivalent to the `R`-linear maps from the free `R`-module
on `X` to `M`. -/
noncomputable def llift : (X → M) ≃ₗ[S] (X →₀ R) →ₗ[R] M :=
{ lift M R X with
map_smul' := by
intros
dsimp
ext
simp only [coe_comp, Function.comp_apply, lsingle_apply, lift_apply, Pi.smul_apply,
sum_single_index, zero_smul, one_smul, LinearMap.smul_apply] }
@[simp]
theorem llift_apply (f : X → M) (x : X →₀ R) : llift M R S X f x = lift M R X f x :=
rfl
@[simp]
theorem llift_symm_apply (f : (X →₀ R) →ₗ[R] M) (x : X) :
(llift M R S X).symm f x = f (single x 1) :=
rfl
end
section LMapDomain
variable {α' : Type*} {α'' : Type*} (M R)
/-- Interpret `Finsupp.mapDomain` as a linear map. -/
def lmapDomain (f : α → α') : (α →₀ M) →ₗ[R] α' →₀ M where
toFun := mapDomain f
map_add' _ _ := mapDomain_add
map_smul' := mapDomain_smul
@[simp]
theorem lmapDomain_apply (f : α → α') (l : α →₀ M) :
(lmapDomain M R f : (α →₀ M) →ₗ[R] α' →₀ M) l = mapDomain f l :=
rfl
@[simp]
theorem lmapDomain_id : (lmapDomain M R _root_.id : (α →₀ M) →ₗ[R] α →₀ M) = LinearMap.id :=
LinearMap.ext fun _ => mapDomain_id
theorem lmapDomain_comp (f : α → α') (g : α' → α'') :
lmapDomain M R (g ∘ f) = (lmapDomain M R g).comp (lmapDomain M R f) :=
LinearMap.ext fun _ => mapDomain_comp
theorem supported_comap_lmapDomain (f : α → α') (s : Set α') :
supported M R (f ⁻¹' s) ≤ (supported M R s).comap (lmapDomain M R f) := by
classical
intro l (hl : (l.support : Set α) ⊆ f ⁻¹' s)
show ↑(mapDomain f l).support ⊆ s
rw [← Set.image_subset_iff, ← Finset.coe_image] at hl
exact Set.Subset.trans mapDomain_support hl
theorem lmapDomain_supported (f : α → α') (s : Set α) :
(supported M R s).map (lmapDomain M R f) = supported M R (f '' s) := by
classical
cases isEmpty_or_nonempty α
· simp [s.eq_empty_of_isEmpty]
refine
le_antisymm
(map_le_iff_le_comap.2 <|
le_trans (supported_mono <| Set.subset_preimage_image _ _)
(supported_comap_lmapDomain M R _ _))
?_
intro l hl
refine ⟨(lmapDomain M R (Function.invFunOn f s) : (α' →₀ M) →ₗ[R] α →₀ M) l, fun x hx => ?_, ?_⟩
· rcases Finset.mem_image.1 (mapDomain_support hx) with ⟨c, hc, rfl⟩
exact Function.invFunOn_mem (by simpa using hl hc)
· rw [← LinearMap.comp_apply, ← lmapDomain_comp]
refine (mapDomain_congr fun c hc => ?_).trans mapDomain_id
exact Function.invFunOn_eq (by simpa using hl hc)
theorem lmapDomain_disjoint_ker (f : α → α') {s : Set α}
(H : ∀ a ∈ s, ∀ b ∈ s, f a = f b → a = b) :
Disjoint (supported M R s) (ker (lmapDomain M R f)) := by
rw [disjoint_iff_inf_le]
rintro l ⟨h₁, h₂⟩
rw [SetLike.mem_coe, mem_ker, lmapDomain_apply, mapDomain] at h₂
simp; ext x
haveI := Classical.decPred fun x => x ∈ s
by_cases xs : x ∈ s
· have : Finsupp.sum l (fun a => Finsupp.single (f a)) (f x) = 0 := by
rw [h₂]
rfl
rw [Finsupp.sum_apply, Finsupp.sum_eq_single x, single_eq_same] at this
· simpa
· intro y hy xy
simp only [SetLike.mem_coe, mem_supported, subset_def, Finset.mem_coe, mem_support_iff] at h₁
simp [mt (H _ (h₁ _ hy) _ xs) xy]
· simp (config := { contextual := true })
· by_contra h
exact xs (h₁ <| Finsupp.mem_support_iff.2 h)
end LMapDomain
section LComapDomain
variable {β : Type*}
/-- Given `f : α → β` and a proof `hf` that `f` is injective, `lcomapDomain f hf` is the linear map
sending `l : β →₀ M` to the finitely supported function from `α` to `M` given by composing
`l` with `f`.
This is the linear version of `Finsupp.comapDomain`. -/
def lcomapDomain (f : α → β) (hf : Function.Injective f) : (β →₀ M) →ₗ[R] α →₀ M where
toFun l := Finsupp.comapDomain f l hf.injOn
map_add' x y := by ext; simp
map_smul' c x := by ext; simp
end LComapDomain
section Total
variable (α) (M) (R)
variable {α' : Type*} {M' : Type*} [AddCommMonoid M'] [Module R M'] (v : α → M) {v' : α' → M'}
/-- Interprets (l : α →₀ R) as linear combination of the elements in the family (v : α → M) and
evaluates this linear combination. -/
protected def total : (α →₀ R) →ₗ[R] M :=
Finsupp.lsum ℕ fun i => LinearMap.id.smulRight (v i)
variable {α M v}
theorem total_apply (l : α →₀ R) : Finsupp.total α M R v l = l.sum fun i a => a • v i :=
rfl
theorem total_apply_of_mem_supported {l : α →₀ R} {s : Finset α}
(hs : l ∈ supported R R (↑s : Set α)) : Finsupp.total α M R v l = s.sum fun i => l i • v i :=
Finset.sum_subset hs fun x _ hxg =>
show l x • v x = 0 by rw [not_mem_support_iff.1 hxg, zero_smul]
@[simp]
theorem total_single (c : R) (a : α) : Finsupp.total α M R v (single a c) = c • v a := by
simp [total_apply, sum_single_index]
theorem total_zero_apply (x : α →₀ R) : (Finsupp.total α M R 0) x = 0 := by
simp [Finsupp.total_apply]
variable (α M)
@[simp]
theorem total_zero : Finsupp.total α M R 0 = 0 :=
LinearMap.ext (total_zero_apply R)
variable {α M}
theorem apply_total (f : M →ₗ[R] M') (v) (l : α →₀ R) :
f (Finsupp.total α M R v l) = Finsupp.total α M' R (f ∘ v) l := by
apply Finsupp.induction_linear l <;> simp (config := { contextual := true })
theorem apply_total_id (f : M →ₗ[R] M') (l : M →₀ R) :
f (Finsupp.total M M R _root_.id l) = Finsupp.total M M' R f l :=
apply_total ..
theorem total_unique [Unique α] (l : α →₀ R) (v) :
Finsupp.total α M R v l = l default • v default := by rw [← total_single, ← unique_single l]
theorem total_surjective (h : Function.Surjective v) :
Function.Surjective (Finsupp.total α M R v) := by
intro x
obtain ⟨y, hy⟩ := h x
exact ⟨Finsupp.single y 1, by simp [hy]⟩
theorem total_range (h : Function.Surjective v) : LinearMap.range (Finsupp.total α M R v) = ⊤ :=
range_eq_top.2 <| total_surjective R h
/-- Any module is a quotient of a free module. This is stated as surjectivity of
`Finsupp.total M M R id : (M →₀ R) →ₗ[R] M`. -/
theorem total_id_surjective (M) [AddCommMonoid M] [Module R M] :
Function.Surjective (Finsupp.total M M R _root_.id) :=
total_surjective R Function.surjective_id
theorem range_total : LinearMap.range (Finsupp.total α M R v) = span R (range v) := by
ext x
constructor
· intro hx
rw [LinearMap.mem_range] at hx
rcases hx with ⟨l, hl⟩
rw [← hl]
rw [Finsupp.total_apply]
exact sum_mem fun i _ => Submodule.smul_mem _ _ (subset_span (mem_range_self i))
· apply span_le.2
intro x hx
rcases hx with ⟨i, hi⟩
rw [SetLike.mem_coe, LinearMap.mem_range]
use Finsupp.single i 1
simp [hi]
theorem lmapDomain_total (f : α → α') (g : M →ₗ[R] M') (h : ∀ i, g (v i) = v' (f i)) :
(Finsupp.total α' M' R v').comp (lmapDomain R R f) = g.comp (Finsupp.total α M R v) := by
ext l
simp [total_apply, Finsupp.sum_mapDomain_index, add_smul, h]
theorem total_comp_lmapDomain (f : α → α') :
(Finsupp.total α' M' R v').comp (Finsupp.lmapDomain R R f) = Finsupp.total α M' R (v' ∘ f) := by
ext
simp
@[simp]
theorem total_embDomain (f : α ↪ α') (l : α →₀ R) :
(Finsupp.total α' M' R v') (embDomain f l) = (Finsupp.total α M' R (v' ∘ f)) l := by
simp [total_apply, Finsupp.sum, support_embDomain, embDomain_apply]
@[simp]
theorem total_mapDomain (f : α → α') (l : α →₀ R) :
(Finsupp.total α' M' R v') (mapDomain f l) = (Finsupp.total α M' R (v' ∘ f)) l :=
LinearMap.congr_fun (total_comp_lmapDomain _ _) l
@[simp]
theorem total_equivMapDomain (f : α ≃ α') (l : α →₀ R) :
(Finsupp.total α' M' R v') (equivMapDomain f l) = (Finsupp.total α M' R (v' ∘ f)) l := by
rw [equivMapDomain_eq_mapDomain, total_mapDomain]
/-- A version of `Finsupp.range_total` which is useful for going in the other direction -/
theorem span_eq_range_total (s : Set M) : span R s = LinearMap.range (Finsupp.total s M R (↑)) := by
rw [range_total, Subtype.range_coe_subtype, Set.setOf_mem_eq]
theorem mem_span_iff_total (s : Set M) (x : M) :
x ∈ span R s ↔ ∃ l : s →₀ R, Finsupp.total s M R (↑) l = x :=
(SetLike.ext_iff.1 <| span_eq_range_total _ _) x
variable {R}
theorem mem_span_range_iff_exists_finsupp {v : α → M} {x : M} :
x ∈ span R (range v) ↔ ∃ c : α →₀ R, (c.sum fun i a => a • v i) = x := by
simp only [← Finsupp.range_total, LinearMap.mem_range, Finsupp.total_apply]
variable (R)
theorem span_image_eq_map_total (s : Set α) :
span R (v '' s) = Submodule.map (Finsupp.total α M R v) (supported R R s) := by
apply span_eq_of_le
· intro x hx
rw [Set.mem_image] at hx
apply Exists.elim hx
intro i hi
exact ⟨_, Finsupp.single_mem_supported R 1 hi.1, by simp [hi.2]⟩
· refine map_le_iff_le_comap.2 fun z hz => ?_
have : ∀ i, z i • v i ∈ span R (v '' s) := by
intro c
haveI := Classical.decPred fun x => x ∈ s
by_cases h : c ∈ s
· exact smul_mem _ _ (subset_span (Set.mem_image_of_mem _ h))
· simp [(Finsupp.mem_supported' R _).1 hz _ h]
-- Porting note: `rw` is required to infer metavariables in `sum_mem`.
rw [mem_comap, total_apply]
refine sum_mem ?_
simp [this]
theorem mem_span_image_iff_total {s : Set α} {x : M} :
x ∈ span R (v '' s) ↔ ∃ l ∈ supported R R s, Finsupp.total α M R v l = x := by
rw [span_image_eq_map_total]
simp
theorem total_option (v : Option α → M) (f : Option α →₀ R) :
Finsupp.total (Option α) M R v f =
f none • v none + Finsupp.total α M R (v ∘ Option.some) f.some := by
rw [total_apply, sum_option_index_smul, total_apply]; simp
theorem total_total {α β : Type*} (A : α → M) (B : β → α →₀ R) (f : β →₀ R) :
Finsupp.total α M R A (Finsupp.total β (α →₀ R) R B f) =
Finsupp.total β M R (fun b => Finsupp.total α M R A (B b)) f := by
classical
simp only [total_apply]
apply induction_linear f
· simp only [sum_zero_index]
· intro f₁ f₂ h₁ h₂
simp [sum_add_index, h₁, h₂, add_smul]
· simp [sum_single_index, sum_smul_index, smul_sum, mul_smul]
@[simp]
theorem total_fin_zero (f : Fin 0 → M) : Finsupp.total (Fin 0) M R f = 0 := by
ext i
apply finZeroElim i
variable (α) (M) (v)
/-- `Finsupp.totalOn M v s` interprets `p : α →₀ R` as a linear combination of a
subset of the vectors in `v`, mapping it to the span of those vectors.
The subset is indicated by a set `s : Set α` of indices.
-/
protected def totalOn (s : Set α) : supported R R s →ₗ[R] span R (v '' s) :=
LinearMap.codRestrict _ ((Finsupp.total _ _ _ v).comp (Submodule.subtype (supported R R s)))
fun ⟨l, hl⟩ => (mem_span_image_iff_total _).2 ⟨l, hl, rfl⟩
variable {α} {M} {v}
theorem totalOn_range (s : Set α) : LinearMap.range (Finsupp.totalOn α M R v s) = ⊤ := by
rw [Finsupp.totalOn, LinearMap.range_eq_map, LinearMap.map_codRestrict,
← LinearMap.range_le_iff_comap, range_subtype, Submodule.map_top, LinearMap.range_comp,
range_subtype]
exact (span_image_eq_map_total _ _).le
theorem total_comp (f : α' → α) :
Finsupp.total α' M R (v ∘ f) = (Finsupp.total α M R v).comp (lmapDomain R R f) := by
ext
simp [total_apply]
theorem total_comapDomain (f : α → α') (l : α' →₀ R) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) :
Finsupp.total α M R v (Finsupp.comapDomain f l hf) =
(l.support.preimage f hf).sum fun i => l (f i) • v i := by
rw [Finsupp.total_apply]; rfl
theorem total_onFinset {s : Finset α} {f : α → R} (g : α → M) (hf : ∀ a, f a ≠ 0 → a ∈ s) :
Finsupp.total α M R g (Finsupp.onFinset s f hf) = Finset.sum s fun x : α => f x • g x := by
classical
simp only [Finsupp.total_apply, Finsupp.sum, Finsupp.onFinset_apply, Finsupp.support_onFinset]
rw [Finset.sum_filter_of_ne]
intro x _ h
contrapose! h
simp [h]
end Total
/-- An equivalence of domains induces a linear equivalence of finitely supported functions.
This is `Finsupp.domCongr` as a `LinearEquiv`.
See also `LinearMap.funCongrLeft` for the case of arbitrary functions. -/
protected def domLCongr {α₁ α₂ : Type*} (e : α₁ ≃ α₂) : (α₁ →₀ M) ≃ₗ[R] α₂ →₀ M :=
(Finsupp.domCongr e : (α₁ →₀ M) ≃+ (α₂ →₀ M)).toLinearEquiv <| by
simpa only [equivMapDomain_eq_mapDomain, domCongr_apply] using (lmapDomain M R e).map_smul
@[simp]
theorem domLCongr_apply {α₁ : Type*} {α₂ : Type*} (e : α₁ ≃ α₂) (v : α₁ →₀ M) :
(Finsupp.domLCongr e : _ ≃ₗ[R] _) v = Finsupp.domCongr e v :=
rfl
@[simp]
theorem domLCongr_refl : Finsupp.domLCongr (Equiv.refl α) = LinearEquiv.refl R (α →₀ M) :=
LinearEquiv.ext fun _ => equivMapDomain_refl _
theorem domLCongr_trans {α₁ α₂ α₃ : Type*} (f : α₁ ≃ α₂) (f₂ : α₂ ≃ α₃) :
(Finsupp.domLCongr f).trans (Finsupp.domLCongr f₂) =
(Finsupp.domLCongr (f.trans f₂) : (_ →₀ M) ≃ₗ[R] _) :=
LinearEquiv.ext fun _ => (equivMapDomain_trans _ _ _).symm
@[simp]
theorem domLCongr_symm {α₁ α₂ : Type*} (f : α₁ ≃ α₂) :
((Finsupp.domLCongr f).symm : (_ →₀ M) ≃ₗ[R] _) = Finsupp.domLCongr f.symm :=
LinearEquiv.ext fun _ => rfl
-- @[simp] -- Porting note (#10618): simp can prove this
theorem domLCongr_single {α₁ : Type*} {α₂ : Type*} (e : α₁ ≃ α₂) (i : α₁) (m : M) :
(Finsupp.domLCongr e : _ ≃ₗ[R] _) (Finsupp.single i m) = Finsupp.single (e i) m := by
simp
/-- An equivalence of sets induces a linear equivalence of `Finsupp`s supported on those sets. -/
noncomputable def congr {α' : Type*} (s : Set α) (t : Set α') (e : s ≃ t) :
supported M R s ≃ₗ[R] supported M R t := by
haveI := Classical.decPred fun x => x ∈ s
haveI := Classical.decPred fun x => x ∈ t
exact Finsupp.supportedEquivFinsupp s ≪≫ₗ
(Finsupp.domLCongr e ≪≫ₗ (Finsupp.supportedEquivFinsupp t).symm)
/-- `Finsupp.mapRange` as a `LinearMap`. -/
def mapRange.linearMap (f : M →ₗ[R] N) : (α →₀ M) →ₗ[R] α →₀ N :=
{ mapRange.addMonoidHom f.toAddMonoidHom with
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
-- Porting note: `hf` should be specified.
map_smul' := fun c v => mapRange_smul (hf := f.map_zero) c v (f.map_smul c) }
-- Porting note: This was generated by `simps!`.
@[simp]
theorem mapRange.linearMap_apply (f : M →ₗ[R] N) (g : α →₀ M) :
mapRange.linearMap f g = mapRange f f.map_zero g := rfl
@[simp]
theorem mapRange.linearMap_id :
mapRange.linearMap LinearMap.id = (LinearMap.id : (α →₀ M) →ₗ[R] _) :=
LinearMap.ext mapRange_id
theorem mapRange.linearMap_comp (f : N →ₗ[R] P) (f₂ : M →ₗ[R] N) :
(mapRange.linearMap (f.comp f₂) : (α →₀ _) →ₗ[R] _) =
(mapRange.linearMap f).comp (mapRange.linearMap f₂) :=
-- Porting note: Placeholders should be filled.
LinearMap.ext <| mapRange_comp f f.map_zero f₂ f₂.map_zero (comp f f₂).map_zero
@[simp]
theorem mapRange.linearMap_toAddMonoidHom (f : M →ₗ[R] N) :
(mapRange.linearMap f).toAddMonoidHom =
(mapRange.addMonoidHom f.toAddMonoidHom : (α →₀ M) →+ _) :=
AddMonoidHom.ext fun _ => rfl
/-- `Finsupp.mapRange` as a `LinearEquiv`. -/
def mapRange.linearEquiv (e : M ≃ₗ[R] N) : (α →₀ M) ≃ₗ[R] α →₀ N :=
{ mapRange.linearMap e.toLinearMap,
mapRange.addEquiv e.toAddEquiv with
toFun := mapRange e e.map_zero
invFun := mapRange e.symm e.symm.map_zero }
-- Porting note: This was generated by `simps`.
@[simp]
theorem mapRange.linearEquiv_apply (e : M ≃ₗ[R] N) (g : α →₀ M) :
mapRange.linearEquiv e g = mapRange.linearMap e.toLinearMap g := rfl
@[simp]
theorem mapRange.linearEquiv_refl :
mapRange.linearEquiv (LinearEquiv.refl R M) = LinearEquiv.refl R (α →₀ M) :=
LinearEquiv.ext mapRange_id
theorem mapRange.linearEquiv_trans (f : M ≃ₗ[R] N) (f₂ : N ≃ₗ[R] P) :
(mapRange.linearEquiv (f.trans f₂) : (α →₀ _) ≃ₗ[R] _) =
(mapRange.linearEquiv f).trans (mapRange.linearEquiv f₂) :=
-- Porting note: Placeholders should be filled.
LinearEquiv.ext <| mapRange_comp f₂ f₂.map_zero f f.map_zero (f.trans f₂).map_zero
@[simp]
theorem mapRange.linearEquiv_symm (f : M ≃ₗ[R] N) :
((mapRange.linearEquiv f).symm : (α →₀ _) ≃ₗ[R] _) = mapRange.linearEquiv f.symm :=
LinearEquiv.ext fun _x => rfl
-- Porting note: This priority should be higher than `LinearEquiv.coe_toAddEquiv`.
@[simp 1500]
theorem mapRange.linearEquiv_toAddEquiv (f : M ≃ₗ[R] N) :
(mapRange.linearEquiv f).toAddEquiv = (mapRange.addEquiv f.toAddEquiv : (α →₀ M) ≃+ _) :=
AddEquiv.ext fun _ => rfl
@[simp]
theorem mapRange.linearEquiv_toLinearMap (f : M ≃ₗ[R] N) :
(mapRange.linearEquiv f).toLinearMap = (mapRange.linearMap f.toLinearMap : (α →₀ M) →ₗ[R] _) :=
LinearMap.ext fun _ => rfl
/-- An equivalence of domain and a linear equivalence of codomain induce a linear equivalence of the
corresponding finitely supported functions. -/
def lcongr {ι κ : Sort _} (e₁ : ι ≃ κ) (e₂ : M ≃ₗ[R] N) : (ι →₀ M) ≃ₗ[R] κ →₀ N :=
(Finsupp.domLCongr e₁).trans (mapRange.linearEquiv e₂)
@[simp]
theorem lcongr_single {ι κ : Sort _} (e₁ : ι ≃ κ) (e₂ : M ≃ₗ[R] N) (i : ι) (m : M) :
lcongr e₁ e₂ (Finsupp.single i m) = Finsupp.single (e₁ i) (e₂ m) := by simp [lcongr]
@[simp]
theorem lcongr_apply_apply {ι κ : Sort _} (e₁ : ι ≃ κ) (e₂ : M ≃ₗ[R] N) (f : ι →₀ M) (k : κ) :
lcongr e₁ e₂ f k = e₂ (f (e₁.symm k)) :=
rfl
theorem lcongr_symm_single {ι κ : Sort _} (e₁ : ι ≃ κ) (e₂ : M ≃ₗ[R] N) (k : κ) (n : N) :
(lcongr e₁ e₂).symm (Finsupp.single k n) = Finsupp.single (e₁.symm k) (e₂.symm n) := by
apply_fun (lcongr e₁ e₂ : (ι →₀ M) → (κ →₀ N)) using (lcongr e₁ e₂).injective
simp
@[simp]
theorem lcongr_symm {ι κ : Sort _} (e₁ : ι ≃ κ) (e₂ : M ≃ₗ[R] N) :
(lcongr e₁ e₂).symm = lcongr e₁.symm e₂.symm := by
ext
rfl
section Sum
variable (R)
/-- The linear equivalence between `(α ⊕ β) →₀ M` and `(α →₀ M) × (β →₀ M)`.
This is the `LinearEquiv` version of `Finsupp.sumFinsuppEquivProdFinsupp`. -/
@[simps apply symm_apply]
def sumFinsuppLEquivProdFinsupp {α β : Type*} : (α ⊕ β →₀ M) ≃ₗ[R] (α →₀ M) × (β →₀ M) :=
{ sumFinsuppAddEquivProdFinsupp with
map_smul' := by
intros
ext <;>
-- Porting note: `add_equiv.to_fun_eq_coe` →
-- `Equiv.toFun_as_coe` & `AddEquiv.toEquiv_eq_coe` & `AddEquiv.coe_toEquiv`
simp only [Equiv.toFun_as_coe, AddEquiv.toEquiv_eq_coe, AddEquiv.coe_toEquiv, Prod.smul_fst,
Prod.smul_snd, smul_apply,
snd_sumFinsuppAddEquivProdFinsupp, fst_sumFinsuppAddEquivProdFinsupp,
RingHom.id_apply] }
theorem fst_sumFinsuppLEquivProdFinsupp {α β : Type*} (f : α ⊕ β →₀ M) (x : α) :
(sumFinsuppLEquivProdFinsupp R f).1 x = f (Sum.inl x) :=
rfl
theorem snd_sumFinsuppLEquivProdFinsupp {α β : Type*} (f : α ⊕ β →₀ M) (y : β) :
(sumFinsuppLEquivProdFinsupp R f).2 y = f (Sum.inr y) :=
rfl
theorem sumFinsuppLEquivProdFinsupp_symm_inl {α β : Type*} (fg : (α →₀ M) × (β →₀ M)) (x : α) :
((sumFinsuppLEquivProdFinsupp R).symm fg) (Sum.inl x) = fg.1 x :=
rfl
theorem sumFinsuppLEquivProdFinsupp_symm_inr {α β : Type*} (fg : (α →₀ M) × (β →₀ M)) (y : β) :
((sumFinsuppLEquivProdFinsupp R).symm fg) (Sum.inr y) = fg.2 y :=
rfl
end Sum
section Sigma
variable {η : Type*} [Fintype η] {ιs : η → Type*} [Zero α]
variable (R)
/-- On a `Fintype η`, `Finsupp.split` is a linear equivalence between
`(Σ (j : η), ιs j) →₀ M` and `(j : η) → (ιs j →₀ M)`.
This is the `LinearEquiv` version of `Finsupp.sigmaFinsuppAddEquivPiFinsupp`. -/
noncomputable def sigmaFinsuppLEquivPiFinsupp {M : Type*} {ιs : η → Type*} [AddCommMonoid M]
[Module R M] : ((Σ j, ιs j) →₀ M) ≃ₗ[R] (j : _) → (ιs j →₀ M) :=
-- Porting note: `ιs` should be specified.
{ sigmaFinsuppAddEquivPiFinsupp (ιs := ιs) with
map_smul' := fun c f => by
ext
simp }
@[simp]
theorem sigmaFinsuppLEquivPiFinsupp_apply {M : Type*} {ιs : η → Type*} [AddCommMonoid M]
[Module R M] (f : (Σj, ιs j) →₀ M) (j i) : sigmaFinsuppLEquivPiFinsupp R f j i = f ⟨j, i⟩ :=
rfl
@[simp]
theorem sigmaFinsuppLEquivPiFinsupp_symm_apply {M : Type*} {ιs : η → Type*} [AddCommMonoid M]
[Module R M] (f : (j : _) → (ιs j →₀ M)) (ji) :
(Finsupp.sigmaFinsuppLEquivPiFinsupp R).symm f ji = f ji.1 ji.2 :=
rfl
end Sigma
section Prod
/-- The linear equivalence between `α × β →₀ M` and `α →₀ β →₀ M`.
This is the `LinearEquiv` version of `Finsupp.finsuppProdEquiv`. -/
noncomputable def finsuppProdLEquiv {α β : Type*} (R : Type*) {M : Type*} [Semiring R]
[AddCommMonoid M] [Module R M] : (α × β →₀ M) ≃ₗ[R] α →₀ β →₀ M :=
{ finsuppProdEquiv with
map_add' := fun f g => by
ext
simp [finsuppProdEquiv, curry_apply]
map_smul' := fun c f => by
ext
simp [finsuppProdEquiv, curry_apply] }
@[simp]
theorem finsuppProdLEquiv_apply {α β R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
(f : α × β →₀ M) (x y) : finsuppProdLEquiv R f x y = f (x, y) := by
rw [finsuppProdLEquiv, LinearEquiv.coe_mk, finsuppProdEquiv, Finsupp.curry_apply]
@[simp]
theorem finsuppProdLEquiv_symm_apply {α β R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
(f : α →₀ β →₀ M) (xy) : (finsuppProdLEquiv R).symm f xy = f xy.1 xy.2 := by
conv_rhs =>
rw [← (finsuppProdLEquiv R).apply_symm_apply f, finsuppProdLEquiv_apply]
end Prod
/-- If `R` is countable, then any `R`-submodule spanned by a countable family of vectors is
countable. -/
instance {ι : Type*} [Countable R] [Countable ι] (v : ι → M) :
Countable (Submodule.span R (Set.range v)) := by
refine Set.countable_coe_iff.mpr (Set.Countable.mono ?_ (Set.countable_range
(fun c : (ι →₀ R) => c.sum fun i _ => (c i) • v i)))
exact fun _ h => Finsupp.mem_span_range_iff_exists_finsupp.mp (SetLike.mem_coe.mp h)
end Finsupp
section Fintype
variable {α M : Type*} (R : Type*) [Fintype α] [Semiring R] [AddCommMonoid M] [Module R M]
variable (S : Type*) [Semiring S] [Module S M] [SMulCommClass R S M]
variable (v : α → M)
/-- `Fintype.total R S v f` is the linear combination of vectors in `v` with weights in `f`.
This variant of `Finsupp.total` is defined on fintype indexed vectors.
This map is linear in `v` if `R` is commutative, and always linear in `f`.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used.
-/
protected def Fintype.total : (α → M) →ₗ[S] (α → R) →ₗ[R] M where
toFun v :=
{ toFun := fun f => ∑ i, f i • v i
map_add' := fun f g => by simp_rw [← Finset.sum_add_distrib, ← add_smul]; rfl
map_smul' := fun r f => by simp_rw [Finset.smul_sum, smul_smul]; rfl }
map_add' u v := by ext; simp [Finset.sum_add_distrib, Pi.add_apply, smul_add]
map_smul' r v := by ext; simp [Finset.smul_sum, smul_comm]
variable {S}
theorem Fintype.total_apply (f) : Fintype.total R S v f = ∑ i, f i • v i :=
rfl
@[simp]
theorem Fintype.total_apply_single [DecidableEq α] (i : α) (r : R) :
Fintype.total R S v (Pi.single i r) = r • v i := by
simp_rw [Fintype.total_apply, Pi.single_apply, ite_smul, zero_smul]
rw [Finset.sum_ite_eq', if_pos (Finset.mem_univ _)]
variable (S)
theorem Finsupp.total_eq_fintype_total_apply (x : α → R) : Finsupp.total α M R v
((Finsupp.linearEquivFunOnFinite R R α).symm x) = Fintype.total R S v x := by
apply Finset.sum_subset
· exact Finset.subset_univ _
· intro x _ hx
rw [Finsupp.not_mem_support_iff.mp hx]
exact zero_smul _ _
theorem Finsupp.total_eq_fintype_total :
(Finsupp.total α M R v).comp (Finsupp.linearEquivFunOnFinite R R α).symm.toLinearMap =
Fintype.total R S v :=
LinearMap.ext <| Finsupp.total_eq_fintype_total_apply R S v
variable {S}
@[simp]
theorem Fintype.range_total :
LinearMap.range (Fintype.total R S v) = Submodule.span R (Set.range v) := by
rw [← Finsupp.total_eq_fintype_total, LinearMap.range_comp, LinearEquiv.range,
Submodule.map_top, Finsupp.range_total]
section SpanRange
variable {v} {x : M}
/-- An element `x` lies in the span of `v` iff it can be written as sum `∑ cᵢ • vᵢ = x`.
-/
theorem mem_span_range_iff_exists_fun :
x ∈ span R (range v) ↔ ∃ c : α → R, ∑ i, c i • v i = x := by
-- Porting note: `Finsupp.equivFunOnFinite.surjective.exists` should be come before `simp`.
rw [Finsupp.equivFunOnFinite.surjective.exists]
simp only [Finsupp.mem_span_range_iff_exists_finsupp, Finsupp.equivFunOnFinite_apply]
exact exists_congr fun c => Eq.congr_left <| Finsupp.sum_fintype _ _ fun i => zero_smul _ _
/-- A family `v : α → V` is generating `V` iff every element `(x : V)`
can be written as sum `∑ cᵢ • vᵢ = x`.
-/
theorem top_le_span_range_iff_forall_exists_fun :
⊤ ≤ span R (range v) ↔ ∀ x, ∃ c : α → R, ∑ i, c i • v i = x := by
simp_rw [← mem_span_range_iff_exists_fun]
exact ⟨fun h x => h trivial, fun h x _ => h x⟩
end SpanRange
end Fintype
variable {R : Type*} {M : Type*} {N : Type*}
variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
section
variable (R)
/-- Pick some representation of `x : span R w` as a linear combination in `w`,
using the axiom of choice.
-/
irreducible_def Span.repr (w : Set M) (x : span R w) : w →₀ R :=
((Finsupp.mem_span_iff_total _ _ _).mp x.2).choose
@[simp]
theorem Span.finsupp_total_repr {w : Set M} (x : span R w) :
Finsupp.total w M R (↑) (Span.repr R w x) = x := by
rw [Span.repr_def]
exact ((Finsupp.mem_span_iff_total _ _ _).mp x.2).choose_spec
end
protected theorem Submodule.finsupp_sum_mem {ι β : Type*} [Zero β] (S : Submodule R M) (f : ι →₀ β)
(g : ι → β → M) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) : f.sum g ∈ S :=
AddSubmonoidClass.finsupp_sum_mem S f g h
theorem LinearMap.map_finsupp_total (f : M →ₗ[R] N) {ι : Type*} {g : ι → M} (l : ι →₀ R) :
f (Finsupp.total ι M R g l) = Finsupp.total ι N R (f ∘ g) l := by
-- Porting note: `(· ∘ ·)` is required.
simp only [Finsupp.total_apply, Finsupp.total_apply, Finsupp.sum, map_sum, map_smul, (· ∘ ·)]
theorem Submodule.exists_finset_of_mem_iSup {ι : Sort _} (p : ι → Submodule R M) {m : M}
(hm : m ∈ ⨆ i, p i) : ∃ s : Finset ι, m ∈ ⨆ i ∈ s, p i := by
have :=
CompleteLattice.IsCompactElement.exists_finset_of_le_iSup (Submodule R M)
(Submodule.singleton_span_isCompactElement m) p
simp only [Submodule.span_singleton_le_iff_mem] at this
exact this hm
/-- `Submodule.exists_finset_of_mem_iSup` as an `iff` -/
theorem Submodule.mem_iSup_iff_exists_finset {ι : Sort _} {p : ι → Submodule R M} {m : M} :
(m ∈ ⨆ i, p i) ↔ ∃ s : Finset ι, m ∈ ⨆ i ∈ s, p i :=
⟨Submodule.exists_finset_of_mem_iSup p, fun ⟨_, hs⟩ =>
iSup_mono (fun i => (iSup_const_le : _ ≤ p i)) hs⟩
theorem Submodule.mem_sSup_iff_exists_finset {S : Set (Submodule R M)} {m : M} :
m ∈ sSup S ↔ ∃ s : Finset (Submodule R M), ↑s ⊆ S ∧ m ∈ ⨆ i ∈ s, i := by
rw [sSup_eq_iSup, iSup_subtype', Submodule.mem_iSup_iff_exists_finset]
refine ⟨fun ⟨s, hs⟩ ↦ ⟨s.map (Function.Embedding.subtype S), ?_, ?_⟩,
fun ⟨s, hsS, hs⟩ ↦ ⟨s.preimage (↑) Subtype.coe_injective.injOn, ?_⟩⟩
· simpa using fun x _ ↦ x.property
· suffices m ∈ ⨆ (i) (hi : i ∈ S) (_ : ⟨i, hi⟩ ∈ s), i by simpa
rwa [iSup_subtype']
· have : ⨆ (i) (_ : i ∈ S ∧ i ∈ s), i = ⨆ (i) (_ : i ∈ s), i := by convert rfl; aesop
simpa only [Finset.mem_preimage, iSup_subtype, iSup_and', this]
theorem mem_span_finset {s : Finset M} {x : M} :
x ∈ span R (↑s : Set M) ↔ ∃ f : M → R, ∑ i ∈ s, f i • i = x :=
⟨fun hx =>
let ⟨v, hvs, hvx⟩ :=
(Finsupp.mem_span_image_iff_total _).1
(show x ∈ span R (_root_.id '' (↑s : Set M)) by rwa [Set.image_id])
⟨v, hvx ▸ (Finsupp.total_apply_of_mem_supported _ hvs).symm⟩,
fun ⟨f, hf⟩ => hf ▸ sum_mem fun i hi => smul_mem _ _ <| subset_span hi⟩
/-- An element `m ∈ M` is contained in the `R`-submodule spanned by a set `s ⊆ M`, if and only if
`m` can be written as a finite `R`-linear combination of elements of `s`.
The implementation uses `Finsupp.sum`. -/
theorem mem_span_set {m : M} {s : Set M} :
m ∈ Submodule.span R s ↔
∃ c : M →₀ R, (c.support : Set M) ⊆ s ∧ (c.sum fun mi r => r • mi) = m := by
conv_lhs => rw [← Set.image_id s]
exact Finsupp.mem_span_image_iff_total R (v := _root_.id (α := M))
/-- An element `m ∈ M` is contained in the `R`-submodule spanned by a set `s ⊆ M`, if and only if
`m` can be written as a finite `R`-linear combination of elements of `s`.
The implementation uses a sum indexed by `Fin n` for some `n`. -/
lemma mem_span_set' {m : M} {s : Set M} :
m ∈ Submodule.span R s ↔ ∃ (n : ℕ) (f : Fin n → R) (g : Fin n → s),
∑ i, f i • (g i : M) = m := by
refine ⟨fun h ↦ ?_, ?_⟩
· rcases mem_span_set.1 h with ⟨c, cs, rfl⟩
have A : c.support ≃ Fin c.support.card := Finset.equivFin _
refine ⟨_, fun i ↦ c (A.symm i), fun i ↦ ⟨A.symm i, cs (A.symm i).2⟩, ?_⟩
rw [Finsupp.sum, ← Finset.sum_coe_sort c.support]
exact Fintype.sum_equiv A.symm _ (fun j ↦ c j • (j : M)) (fun i ↦ rfl)
· rintro ⟨n, f, g, rfl⟩
exact Submodule.sum_mem _ (fun i _ ↦ Submodule.smul_mem _ _ (Submodule.subset_span (g i).2))
/-- The span of a subset `s` is the union over all `n` of the set of linear combinations of at most
`n` terms belonging to `s`. -/
lemma span_eq_iUnion_nat (s : Set M) :
(Submodule.span R s : Set M) = ⋃ (n : ℕ),
(fun (f : Fin n → (R × M)) ↦ ∑ i, (f i).1 • (f i).2) '' ({f | ∀ i, (f i).2 ∈ s}) := by
ext m
simp only [SetLike.mem_coe, mem_iUnion, mem_image, mem_setOf_eq, mem_span_set']
refine exists_congr (fun n ↦ ⟨?_, ?_⟩)
· rintro ⟨f, g, rfl⟩
exact ⟨fun i ↦ (f i, g i), fun i ↦ (g i).2, rfl⟩
· rintro ⟨f, hf, rfl⟩
exact ⟨fun i ↦ (f i).1, fun i ↦ ⟨(f i).2, (hf i)⟩, rfl⟩
/-- If `Subsingleton R`, then `M ≃ₗ[R] ι →₀ R` for any type `ι`. -/
@[simps]
def Module.subsingletonEquiv (R M ι : Type*) [Semiring R] [Subsingleton R] [AddCommMonoid M]
[Module R M] : M ≃ₗ[R] ι →₀ R where
toFun _ := 0
invFun _ := 0
left_inv m := by
letI := Module.subsingleton R M
simp only [eq_iff_true_of_subsingleton]
right_inv f := by simp only [eq_iff_true_of_subsingleton]
map_add' _ _ := (add_zero 0).symm
map_smul' r _ := (smul_zero r).symm
namespace LinearMap
variable {α : Type*}
open Finsupp Function
-- See also `LinearMap.splittingOfFunOnFintypeSurjective`
/-- A surjective linear map to finitely supported functions has a splitting. -/
def splittingOfFinsuppSurjective (f : M →ₗ[R] α →₀ R) (s : Surjective f) : (α →₀ R) →ₗ[R] M :=
Finsupp.lift _ _ _ fun x : α => (s (Finsupp.single x 1)).choose
theorem splittingOfFinsuppSurjective_splits (f : M →ₗ[R] α →₀ R) (s : Surjective f) :
f.comp (splittingOfFinsuppSurjective f s) = LinearMap.id := by
-- Porting note: `ext` can't find appropriate theorems.
refine lhom_ext' fun x => ext_ring <| Finsupp.ext fun y => ?_
dsimp [splittingOfFinsuppSurjective]
congr
rw [sum_single_index, one_smul]
· exact (s (Finsupp.single x 1)).choose_spec
· rw [zero_smul]
theorem leftInverse_splittingOfFinsuppSurjective (f : M →ₗ[R] α →₀ R) (s : Surjective f) :
LeftInverse f (splittingOfFinsuppSurjective f s) := fun g =>
LinearMap.congr_fun (splittingOfFinsuppSurjective_splits f s) g
theorem splittingOfFinsuppSurjective_injective (f : M →ₗ[R] α →₀ R) (s : Surjective f) :
Injective (splittingOfFinsuppSurjective f s) :=
(leftInverse_splittingOfFinsuppSurjective f s).injective
-- See also `LinearMap.splittingOfFinsuppSurjective`
/-- A surjective linear map to functions on a finite type has a splitting. -/
def splittingOfFunOnFintypeSurjective [Finite α] (f : M →ₗ[R] α → R) (s : Surjective f) :
(α → R) →ₗ[R] M :=
(Finsupp.lift _ _ _ fun x : α => (s (Finsupp.single x 1)).choose).comp
(linearEquivFunOnFinite R R α).symm.toLinearMap
theorem splittingOfFunOnFintypeSurjective_splits [Finite α] (f : M →ₗ[R] α → R)
(s : Surjective f) : f.comp (splittingOfFunOnFintypeSurjective f s) = LinearMap.id := by
classical
-- Porting note: `ext` can't find appropriate theorems.
refine pi_ext' fun x => ext_ring <| funext fun y => ?_
dsimp [splittingOfFunOnFintypeSurjective]
rw [linearEquivFunOnFinite_symm_single, Finsupp.sum_single_index, one_smul,
(s (Finsupp.single x 1)).choose_spec, Finsupp.single_eq_pi_single]
rw [zero_smul]
theorem leftInverse_splittingOfFunOnFintypeSurjective [Finite α] (f : M →ₗ[R] α → R)
(s : Surjective f) : LeftInverse f (splittingOfFunOnFintypeSurjective f s) := fun g =>
LinearMap.congr_fun (splittingOfFunOnFintypeSurjective_splits f s) g
theorem splittingOfFunOnFintypeSurjective_injective [Finite α] (f : M →ₗ[R] α → R)
(s : Surjective f) : Injective (splittingOfFunOnFintypeSurjective f s) :=
(leftInverse_splittingOfFunOnFintypeSurjective f s).injective
end LinearMap
namespace LinearMap
section AddCommMonoid
variable {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*} {ι : Type*}
variable [Semiring R] [Semiring R₂] [AddCommMonoid M] [AddCommMonoid M₂] {σ₁₂ : R →+* R₂}
variable [Module R M] [Module R₂ M₂]
variable {γ : Type*} [Zero γ]
section Finsupp
theorem coe_finsupp_sum (t : ι →₀ γ) (g : ι → γ → M →ₛₗ[σ₁₂] M₂) :
⇑(t.sum g) = t.sum fun i d => g i d := rfl
@[simp]
theorem finsupp_sum_apply (t : ι →₀ γ) (g : ι → γ → M →ₛₗ[σ₁₂] M₂) (b : M) :
(t.sum g) b = t.sum fun i d => g i d b :=
sum_apply _ _ _
end Finsupp
end AddCommMonoid
end LinearMap
namespace Submodule
variable {S : Type*} [Semiring S] [Module R S] [SMulCommClass R R S]
section
variable [SMulCommClass R S S]
/-- If `M` and `N` are submodules of an `R`-algebra `S`, `m : ι → M` is a family of elements, then
there is an `R`-linear map from `ι →₀ N` to `S` which maps `{ n_i }` to the sum of `m_i * n_i`.
This is used in the definition of linearly disjointness. -/
def mulLeftMap {M : Submodule R S} (N : Submodule R S) {ι : Type*} (m : ι → M) :
(ι →₀ N) →ₗ[R] S := Finsupp.lsum R fun i ↦ (m i).1 • N.subtype
theorem mulLeftMap_apply {M N : Submodule R S} {ι : Type*} (m : ι → M) (n : ι →₀ N) :
mulLeftMap N m n = Finsupp.sum n fun (i : ι) (n : N) ↦ (m i).1 * n.1 := rfl
@[simp]
theorem mulLeftMap_apply_single {M N : Submodule R S} {ι : Type*} (m : ι → M) (i : ι) (n : N) :
mulLeftMap N m (Finsupp.single i n) = (m i).1 * n.1 := by
simp [mulLeftMap]
end
variable [IsScalarTower R S S]
/-- If `M` and `N` are submodules of an `R`-algebra `S`, `n : ι → N` is a family of elements, then
there is an `R`-linear map from `ι →₀ M` to `S` which maps `{ m_i }` to the sum of `m_i * n_i`.
This is used in the definition of linearly disjointness. -/
def mulRightMap (M : Submodule R S) {N : Submodule R S} {ι : Type*} (n : ι → N) :
(ι →₀ M) →ₗ[R] S := Finsupp.lsum R fun i ↦ MulOpposite.op (n i).1 • M.subtype
theorem mulRightMap_apply {M N : Submodule R S} {ι : Type*} (n : ι → N) (m : ι →₀ M) :
mulRightMap M n m = Finsupp.sum m fun (i : ι) (m : M) ↦ m.1 * (n i).1 := rfl
@[simp]
theorem mulRightMap_apply_single {M N : Submodule R S} {ι : Type*} (n : ι → N) (i : ι) (m : M) :
mulRightMap M n (Finsupp.single i m) = m.1 * (n i).1 := by
simp [mulRightMap]
theorem mulLeftMap_eq_mulRightMap_of_commute [SMulCommClass R S S]
{M : Submodule R S} (N : Submodule R S) {ι : Type*} (m : ι → M)
(hc : ∀ (i : ι) (n : N), Commute (m i).1 n.1) : mulLeftMap N m = mulRightMap N m := by
ext i n; simp [(hc i n).eq]
theorem mulLeftMap_eq_mulRightMap {S : Type*} [CommSemiring S] [Module R S] [SMulCommClass R R S]
[SMulCommClass R S S] [IsScalarTower R S S] {M : Submodule R S} (N : Submodule R S)
{ι : Type*} (m : ι → M) : mulLeftMap N m = mulRightMap N m :=
mulLeftMap_eq_mulRightMap_of_commute N m fun _ _ ↦ mul_comm _ _
end Submodule
|
LinearAlgebra\FinsuppVectorSpace.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.LinearAlgebra.DFinsupp
import Mathlib.LinearAlgebra.StdBasis
/-!
# Linear structures on function with finite support `ι →₀ M`
This file contains results on the `R`-module structure on functions of finite support from a type
`ι` to an `R`-module `M`, in particular in the case that `R` is a field.
-/
noncomputable section
open Set LinearMap Submodule
open scoped Cardinal
universe u v w
namespace Finsupp
section Ring
variable {R : Type*} {M : Type*} {ι : Type*}
variable [Ring R] [AddCommGroup M] [Module R M]
theorem linearIndependent_single {φ : ι → Type*} {f : ∀ ι, φ ι → M}
(hf : ∀ i, LinearIndependent R (f i)) :
LinearIndependent R fun ix : Σi, φ i => single ix.1 (f ix.1 ix.2) := by
apply @linearIndependent_iUnion_finite R _ _ _ _ ι φ fun i x => single i (f i x)
· intro i
have h_disjoint : Disjoint (span R (range (f i))) (ker (lsingle i)) := by
rw [ker_lsingle]
exact disjoint_bot_right
apply (hf i).map h_disjoint
· intro i t _ hit
refine (disjoint_lsingle_lsingle {i} t (disjoint_singleton_left.2 hit)).mono ?_ ?_
· rw [span_le]
simp only [iSup_singleton]
rw [range_coe]
apply range_comp_subset_range _ (lsingle i)
· refine iSup₂_mono fun i hi => ?_
rw [span_le, range_coe]
apply range_comp_subset_range _ (lsingle i)
end Ring
section Semiring
variable {R : Type*} {M : Type*} {ι : Type*}
variable [Semiring R] [AddCommMonoid M] [Module R M]
open LinearMap Submodule
open scoped Classical in
/-- The basis on `ι →₀ M` with basis vectors `fun ⟨i, x⟩ ↦ single i (b i x)`. -/
protected def basis {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) : Basis (Σi, φ i) R (ι →₀ M) :=
Basis.ofRepr
{ toFun := fun g =>
{ toFun := fun ix => (b ix.1).repr (g ix.1) ix.2
support := g.support.sigma fun i => ((b i).repr (g i)).support
mem_support_toFun := fun ix => by
simp only [Finset.mem_sigma, mem_support_iff, and_iff_right_iff_imp, Ne]
intro b hg
simp [hg] at b }
invFun := fun g =>
{ toFun := fun i => (b i).repr.symm (g.comapDomain _ sigma_mk_injective.injOn)
support := g.support.image Sigma.fst
mem_support_toFun := fun i => by
rw [Ne, ← (b i).repr.injective.eq_iff, (b i).repr.apply_symm_apply,
DFunLike.ext_iff]
simp only [exists_prop, LinearEquiv.map_zero, comapDomain_apply, zero_apply,
exists_and_right, mem_support_iff, exists_eq_right, Sigma.exists, Finset.mem_image,
not_forall] }
left_inv := fun g => by
ext i
rw [← (b i).repr.injective.eq_iff]
ext x
simp only [coe_mk, LinearEquiv.apply_symm_apply, comapDomain_apply]
right_inv := fun g => by
ext ⟨i, x⟩
simp only [coe_mk, LinearEquiv.apply_symm_apply, comapDomain_apply]
map_add' := fun g h => by
ext ⟨i, x⟩
simp only [coe_mk, add_apply, LinearEquiv.map_add]
map_smul' := fun c h => by
ext ⟨i, x⟩
simp only [coe_mk, smul_apply, LinearEquiv.map_smul, RingHom.id_apply] }
@[simp]
theorem basis_repr {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) (g : ι →₀ M) (ix) :
(Finsupp.basis b).repr g ix = (b ix.1).repr (g ix.1) ix.2 :=
rfl
@[simp]
theorem coe_basis {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) :
⇑(Finsupp.basis b) = fun ix : Σi, φ i => single ix.1 (b ix.1 ix.2) :=
funext fun ⟨i, x⟩ =>
Basis.apply_eq_iff.mpr <| by
classical
ext ⟨j, y⟩
by_cases h : i = j
· cases h
simp only [basis_repr, single_eq_same, Basis.repr_self,
Finsupp.single_apply_left sigma_mk_injective]
· have : Sigma.mk i x ≠ Sigma.mk j y := fun h' => h <| congrArg (fun s => s.fst) h'
-- Porting note: previously `this` not needed
simp only [basis_repr, single_apply, h, this, false_and_iff, if_false, LinearEquiv.map_zero,
zero_apply]
/-- The basis on `ι →₀ M` with basis vectors `fun i ↦ single i 1`. -/
@[simps]
protected def basisSingleOne : Basis ι R (ι →₀ R) :=
Basis.ofRepr (LinearEquiv.refl _ _)
@[simp]
theorem coe_basisSingleOne : (Finsupp.basisSingleOne : ι → ι →₀ R) = fun i => Finsupp.single i 1 :=
funext fun _ => Basis.apply_eq_iff.mpr rfl
end Semiring
end Finsupp
namespace DFinsupp
variable {ι : Type*} {R : Type*} {M : ι → Type*}
variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
/-- The direct sum of free modules is free.
Note that while this is stated for `DFinsupp` not `DirectSum`, the types are defeq. -/
noncomputable def basis {η : ι → Type*} (b : ∀ i, Basis (η i) R (M i)) :
Basis (Σi, η i) R (Π₀ i, M i) :=
.ofRepr
((mapRange.linearEquiv fun i => (b i).repr).trans (sigmaFinsuppLequivDFinsupp R).symm)
end DFinsupp
/-! TODO: move this section to an earlier file. -/
namespace Basis
variable {R M n : Type*}
variable [DecidableEq n]
variable [Semiring R] [AddCommMonoid M] [Module R M]
theorem _root_.Finset.sum_single_ite [Fintype n] (a : R) (i : n) :
(∑ x : n, Finsupp.single x (if i = x then a else 0)) = Finsupp.single i a := by
simp only [apply_ite (Finsupp.single _), Finsupp.single_zero, Finset.sum_ite_eq,
if_pos (Finset.mem_univ _)]
theorem equivFun_symm_stdBasis [Finite n] (b : Basis n R M) (i : n) :
b.equivFun.symm (LinearMap.stdBasis R (fun _ => R) i 1) = b i := by
cases nonempty_fintype n
simp
end Basis
|
LinearAlgebra\FreeAlgebra.lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.Basis
import Mathlib.Algebra.FreeAlgebra
import Mathlib.LinearAlgebra.FinsuppVectorSpace
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition
import Mathlib.LinearAlgebra.Dimension.StrongRankCondition
/-!
# Linear algebra properties of `FreeAlgebra R X`
This file provides a `FreeMonoid X` basis on the `FreeAlgebra R X`, and uses it to show the
dimension of the algebra is the cardinality of `List X`
-/
universe u v
namespace FreeAlgebra
variable (R : Type u) (X : Type v)
section
variable [CommSemiring R]
/-- The `FreeMonoid X` basis on the `FreeAlgebra R X`,
mapping `[x₁, x₂, ..., xₙ]` to the "monomial" `1 • x₁ * x₂ * ⋯ * xₙ` -/
-- @[simps]
noncomputable def basisFreeMonoid : Basis (FreeMonoid X) R (FreeAlgebra R X) :=
Finsupp.basisSingleOne.map (equivMonoidAlgebraFreeMonoid (R := R) (X := X)).symm.toLinearEquiv
instance : Module.Free R (FreeAlgebra R X) :=
have : Module.Free R (MonoidAlgebra R (FreeMonoid X)) := Module.Free.finsupp _ _ _
Module.Free.of_equiv (equivMonoidAlgebraFreeMonoid (R := R) (X := X)).symm.toLinearEquiv
end
theorem rank_eq [CommRing R] [Nontrivial R] :
Module.rank R (FreeAlgebra R X) = Cardinal.lift.{u} (Cardinal.mk (List X)) := by
rw [← (Basis.mk_eq_rank'.{_,_,_,u} (basisFreeMonoid R X)).trans (Cardinal.lift_id _),
Cardinal.lift_umax'.{v,u}, FreeMonoid]
end FreeAlgebra
|
LinearAlgebra\GeneralLinearGroup.lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Module.Equiv.Basic
/-!
# The general linear group of linear maps
The general linear group is defined to be the group of invertible linear maps from `M` to itself.
See also `Matrix.GeneralLinearGroup`
## Main definitions
* `LinearMap.GeneralLinearGroup`
-/
variable (R M : Type*)
namespace LinearMap
variable [Semiring R] [AddCommMonoid M] [Module R M]
/-- The group of invertible linear maps from `M` to itself -/
abbrev GeneralLinearGroup :=
(M →ₗ[R] M)ˣ
namespace GeneralLinearGroup
variable {R M}
/-- An invertible linear map `f` determines an equivalence from `M` to itself. -/
def toLinearEquiv (f : GeneralLinearGroup R M) : M ≃ₗ[R] M :=
{ f.val with
invFun := f.inv.toFun
left_inv := fun m ↦ show (f.inv * f.val) m = m by erw [f.inv_val]; simp
right_inv := fun m ↦ show (f.val * f.inv) m = m by erw [f.val_inv]; simp }
/-- An equivalence from `M` to itself determines an invertible linear map. -/
def ofLinearEquiv (f : M ≃ₗ[R] M) : GeneralLinearGroup R M where
val := f
inv := (f.symm : M →ₗ[R] M)
val_inv := LinearMap.ext fun _ ↦ f.apply_symm_apply _
inv_val := LinearMap.ext fun _ ↦ f.symm_apply_apply _
variable (R M)
/-- The general linear group on `R` and `M` is multiplicatively equivalent to the type of linear
equivalences between `M` and itself. -/
def generalLinearEquiv : GeneralLinearGroup R M ≃* M ≃ₗ[R] M where
toFun := toLinearEquiv
invFun := ofLinearEquiv
left_inv f := by ext; rfl
right_inv f := by ext; rfl
map_mul' x y := by ext; rfl
@[simp]
theorem generalLinearEquiv_to_linearMap (f : GeneralLinearGroup R M) :
(generalLinearEquiv R M f : M →ₗ[R] M) = f := by ext; rfl
@[simp]
theorem coeFn_generalLinearEquiv (f : GeneralLinearGroup R M) :
(generalLinearEquiv R M f) = (f : M → M) := rfl
end GeneralLinearGroup
end LinearMap
|
LinearAlgebra\InvariantBasisNumber.lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, Scott Morrison
-/
import Mathlib.RingTheory.OrzechProperty
import Mathlib.RingTheory.Ideal.Quotient
import Mathlib.RingTheory.PrincipalIdealDomain
/-!
# Invariant basis number property
## Main definitions
Let `R` be a (not necessary commutative) ring.
- `InvariantBasisNumber R` is a type class stating that `(Fin n → R) ≃ₗ[R] (Fin m → R)`
implies `n = m`, a property known as the *invariant basis number property.*
This assumption implies that there is a well-defined notion of the rank
of a finitely generated free (left) `R`-module.
It is also useful to consider the following stronger conditions:
- the *rank condition*, witnessed by the type class `RankCondition R`, states that
the existence of a surjective linear map `(Fin n → R) →ₗ[R] (Fin m → R)` implies `m ≤ n`
- the *strong rank condition*, witnessed by the type class `StrongRankCondition R`, states
that the existence of an injective linear map `(Fin n → R) →ₗ[R] (Fin m → R)`
implies `n ≤ m`.
- `OrzechProperty R`, defined in `Mathlib/RingTheory/OrzechProperty.lean`,
states that for any finitely generated `R`-module `M`, any surjective homomorphism `f : N → M`
from a submodule `N` of `M` to `M` is injective.
## Instances
- `IsNoetherianRing.orzechProperty` (defined in `Mathlib/RingTheory/Noetherian.lean`) :
any left-noetherian ring satisfies the Orzech property.
This applies in particular to division rings.
- `strongRankCondition_of_orzechProperty` : the Orzech property implies the strong rank condition
(for non trivial rings).
- `IsNoetherianRing.strongRankCondition` : every nontrivial left-noetherian ring satisfies the
strong rank condition (and so in particular every division ring or field).
- `rankCondition_of_strongRankCondition` : the strong rank condition implies the rank condition.
- `invariantBasisNumber_of_rankCondition` : the rank condition implies the
invariant basis number property.
- `invariantBasisNumber_of_nontrivial_of_commRing`: a nontrivial commutative ring satisfies
the invariant basis number property.
More generally, every commutative ring satisfies the Orzech property,
hence the strong rank condition, which is proved in `Mathlib/RingTheory/FiniteType.lean`.
We keep `invariantBasisNumber_of_nontrivial_of_commRing` here since it imports fewer files.
## Counterexamples to converse results
The following examples can be found in the book of Lam [lam_1999]
(see also <https://math.stackexchange.com/questions/4711904>):
- Let `k` be a field, then the free (non-commutative) algebra `k⟨x, y⟩` satisfies
the rank condition but not the strong rank condition.
- The free (non-commutative) algebra `ℚ⟨a, b, c, d⟩` quotient by the
two-sided ideal `(ac − 1, bd − 1, ab, cd)` satisfies the invariant basis number property
but not the rank condition.
## Future work
So far, there is no API at all for the `InvariantBasisNumber` class. There are several natural
ways to formulate that a module `M` is finitely generated and free, for example
`M ≃ₗ[R] (Fin n → R)`, `M ≃ₗ[R] (ι → R)`, where `ι` is a fintype, or providing a basis indexed by
a finite type. There should be lemmas applying the invariant basis number property to each
situation.
The finite version of the invariant basis number property implies the infinite analogue, i.e., that
`(ι →₀ R) ≃ₗ[R] (ι' →₀ R)` implies that `Cardinal.mk ι = Cardinal.mk ι'`. This fact (and its
variants) should be formalized.
## References
* https://en.wikipedia.org/wiki/Invariant_basis_number
* https://mathoverflow.net/a/2574/
* [Lam, T. Y. *Lectures on Modules and Rings*][lam_1999]
* [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]
## Tags
free module, rank, Orzech property, (strong) rank condition, invariant basis number, IBN
-/
noncomputable section
open Function
universe u v w
section
variable (R : Type u) [Semiring R]
/-- We say that `R` satisfies the strong rank condition if `(Fin n → R) →ₗ[R] (Fin m → R)` injective
implies `n ≤ m`. -/
@[mk_iff]
class StrongRankCondition : Prop where
/-- Any injective linear map from `Rⁿ` to `Rᵐ` guarantees `n ≤ m`. -/
le_of_fin_injective : ∀ {n m : ℕ} (f : (Fin n → R) →ₗ[R] Fin m → R), Injective f → n ≤ m
theorem le_of_fin_injective [StrongRankCondition R] {n m : ℕ} (f : (Fin n → R) →ₗ[R] Fin m → R) :
Injective f → n ≤ m :=
StrongRankCondition.le_of_fin_injective f
/-- A ring satisfies the strong rank condition if and only if, for all `n : ℕ`, any linear map
`(Fin (n + 1) → R) →ₗ[R] (Fin n → R)` is not injective. -/
theorem strongRankCondition_iff_succ :
StrongRankCondition R ↔
∀ (n : ℕ) (f : (Fin (n + 1) → R) →ₗ[R] Fin n → R), ¬Function.Injective f := by
refine ⟨fun h n => fun f hf => ?_, fun h => ⟨@fun n m f hf => ?_⟩⟩
· letI : StrongRankCondition R := h
exact Nat.not_succ_le_self n (le_of_fin_injective R f hf)
· by_contra H
exact
h m (f.comp (Function.ExtendByZero.linearMap R (Fin.castLE (not_le.1 H))))
(hf.comp (Function.extend_injective (Fin.strictMono_castLE _).injective _))
/-- Any nontrivial ring satisfying Orzech property also satisfies strong rank condition. -/
instance (priority := 100) strongRankCondition_of_orzechProperty
[Nontrivial R] [OrzechProperty R] : StrongRankCondition R := by
refine (strongRankCondition_iff_succ R).2 fun n i hi ↦ ?_
let f : (Fin (n + 1) → R) →ₗ[R] Fin n → R := {
toFun := fun x ↦ x ∘ Fin.castSucc
map_add' := fun _ _ ↦ rfl
map_smul' := fun _ _ ↦ rfl
}
have h : (0 : Fin (n + 1) → R) = update (0 : Fin (n + 1) → R) (Fin.last n) 1 := by
apply OrzechProperty.injective_of_surjective_of_injective i f hi
(Fin.castSucc_injective _).surjective_comp_right
ext m
simp [f, update_apply, (Fin.castSucc_lt_last m).ne]
simpa using congr_fun h (Fin.last n)
theorem card_le_of_injective [StrongRankCondition R] {α β : Type*} [Fintype α] [Fintype β]
(f : (α → R) →ₗ[R] β → R) (i : Injective f) : Fintype.card α ≤ Fintype.card β := by
let P := LinearEquiv.funCongrLeft R R (Fintype.equivFin α)
let Q := LinearEquiv.funCongrLeft R R (Fintype.equivFin β)
exact
le_of_fin_injective R ((Q.symm.toLinearMap.comp f).comp P.toLinearMap)
(((LinearEquiv.symm Q).injective.comp i).comp (LinearEquiv.injective P))
theorem card_le_of_injective' [StrongRankCondition R] {α β : Type*} [Fintype α] [Fintype β]
(f : (α →₀ R) →ₗ[R] β →₀ R) (i : Injective f) : Fintype.card α ≤ Fintype.card β := by
let P := Finsupp.linearEquivFunOnFinite R R β
let Q := (Finsupp.linearEquivFunOnFinite R R α).symm
exact
card_le_of_injective R ((P.toLinearMap.comp f).comp Q.toLinearMap)
((P.injective.comp i).comp Q.injective)
/-- We say that `R` satisfies the rank condition if `(Fin n → R) →ₗ[R] (Fin m → R)` surjective
implies `m ≤ n`. -/
class RankCondition : Prop where
/-- Any surjective linear map from `Rⁿ` to `Rᵐ` guarantees `m ≤ n`. -/
le_of_fin_surjective : ∀ {n m : ℕ} (f : (Fin n → R) →ₗ[R] Fin m → R), Surjective f → m ≤ n
theorem le_of_fin_surjective [RankCondition R] {n m : ℕ} (f : (Fin n → R) →ₗ[R] Fin m → R) :
Surjective f → m ≤ n :=
RankCondition.le_of_fin_surjective f
theorem card_le_of_surjective [RankCondition R] {α β : Type*} [Fintype α] [Fintype β]
(f : (α → R) →ₗ[R] β → R) (i : Surjective f) : Fintype.card β ≤ Fintype.card α := by
let P := LinearEquiv.funCongrLeft R R (Fintype.equivFin α)
let Q := LinearEquiv.funCongrLeft R R (Fintype.equivFin β)
exact
le_of_fin_surjective R ((Q.symm.toLinearMap.comp f).comp P.toLinearMap)
(((LinearEquiv.symm Q).surjective.comp i).comp (LinearEquiv.surjective P))
theorem card_le_of_surjective' [RankCondition R] {α β : Type*} [Fintype α] [Fintype β]
(f : (α →₀ R) →ₗ[R] β →₀ R) (i : Surjective f) : Fintype.card β ≤ Fintype.card α := by
let P := Finsupp.linearEquivFunOnFinite R R β
let Q := (Finsupp.linearEquivFunOnFinite R R α).symm
exact
card_le_of_surjective R ((P.toLinearMap.comp f).comp Q.toLinearMap)
((P.surjective.comp i).comp Q.surjective)
/-- By the universal property for free modules, any surjective map `(Fin n → R) →ₗ[R] (Fin m → R)`
has an injective splitting `(Fin m → R) →ₗ[R] (Fin n → R)`
from which the strong rank condition gives the necessary inequality for the rank condition.
-/
instance (priority := 100) rankCondition_of_strongRankCondition [StrongRankCondition R] :
RankCondition R where
le_of_fin_surjective f s :=
le_of_fin_injective R _ (f.splittingOfFunOnFintypeSurjective_injective s)
/-- We say that `R` has the invariant basis number property if `(Fin n → R) ≃ₗ[R] (Fin m → R)`
implies `n = m`. This gives rise to a well-defined notion of rank of a finitely generated free
module. -/
class InvariantBasisNumber : Prop where
/-- Any linear equiv between `Rⁿ` and `Rᵐ` guarantees `m = n`. -/
eq_of_fin_equiv : ∀ {n m : ℕ}, ((Fin n → R) ≃ₗ[R] Fin m → R) → n = m
instance (priority := 100) invariantBasisNumber_of_rankCondition [RankCondition R] :
InvariantBasisNumber R where
eq_of_fin_equiv e := le_antisymm (le_of_fin_surjective R e.symm.toLinearMap e.symm.surjective)
(le_of_fin_surjective R e.toLinearMap e.surjective)
end
section
variable (R : Type u) [Semiring R] [InvariantBasisNumber R]
theorem eq_of_fin_equiv {n m : ℕ} : ((Fin n → R) ≃ₗ[R] Fin m → R) → n = m :=
InvariantBasisNumber.eq_of_fin_equiv
theorem card_eq_of_linearEquiv {α β : Type*} [Fintype α] [Fintype β] (f : (α → R) ≃ₗ[R] β → R) :
Fintype.card α = Fintype.card β :=
eq_of_fin_equiv R
((LinearEquiv.funCongrLeft R R (Fintype.equivFin α)).trans f ≪≫ₗ
(LinearEquiv.funCongrLeft R R (Fintype.equivFin β)).symm)
-- Porting note: this was not well-named because `lequiv` could mean other things
-- (e.g., `localEquiv`)
theorem nontrivial_of_invariantBasisNumber : Nontrivial R := by
by_contra h
refine zero_ne_one (eq_of_fin_equiv R ?_)
haveI := not_nontrivial_iff_subsingleton.1 h
haveI : Subsingleton (Fin 1 → R) :=
Subsingleton.intro fun a b => funext fun x => Subsingleton.elim _ _
exact
{ toFun := 0
invFun := 0
map_add' := by aesop
map_smul' := by aesop
left_inv := fun _ => by simp [eq_iff_true_of_subsingleton]
right_inv := fun _ => by simp [eq_iff_true_of_subsingleton] }
end
section
variable (R : Type u) [Ring R] [Nontrivial R] [IsNoetherianRing R]
/-- Any nontrivial noetherian ring satisfies the strong rank condition,
since it satisfies Orzech property. -/
instance (priority := 100) IsNoetherianRing.strongRankCondition : StrongRankCondition R :=
inferInstance
end
/-!
We want to show that nontrivial commutative rings have invariant basis number. The idea is to
take a maximal ideal `I` of `R` and use an isomorphism `R^n ≃ R^m` of `R` modules to produce an
isomorphism `(R/I)^n ≃ (R/I)^m` of `R/I`-modules, which will imply `n = m` since `R/I` is a field
and we know that fields have invariant basis number.
We construct the isomorphism in two steps:
1. We construct the ring `R^n/I^n`, show that it is an `R/I`-module and show that there is an
isomorphism of `R/I`-modules `R^n/I^n ≃ (R/I)^n`. This isomorphism is called
`Ideal.piQuotEquiv` and is located in the file `RingTheory/Ideals.lean`.
2. We construct an isomorphism of `R/I`-modules `R^n/I^n ≃ R^m/I^m` using the isomorphism
`R^n ≃ R^m`.
-/
section
variable {R : Type u} [CommRing R] (I : Ideal R) {ι : Type v} [Fintype ι] {ι' : Type w}
/-- An `R`-linear map `R^n → R^m` induces a function `R^n/I^n → R^m/I^m`. -/
private def induced_map (I : Ideal R) (e : (ι → R) →ₗ[R] ι' → R) :
(ι → R) ⧸ I.pi ι → (ι' → R) ⧸ I.pi ι' := fun x =>
Quotient.liftOn' x (fun y => Ideal.Quotient.mk (I.pi ι') (e y))
(by
refine fun a b hab => Ideal.Quotient.eq.2 fun h => ?_
rw [Submodule.quotientRel_r_def] at hab
rw [← LinearMap.map_sub]
exact Ideal.map_pi _ _ hab e h)
/-- An isomorphism of `R`-modules `R^n ≃ R^m` induces an isomorphism of `R/I`-modules
`R^n/I^n ≃ R^m/I^m`. -/
private def induced_equiv [Fintype ι'] (I : Ideal R) (e : (ι → R) ≃ₗ[R] ι' → R) :
((ι → R) ⧸ I.pi ι) ≃ₗ[R ⧸ I] (ι' → R) ⧸ I.pi ι' where
-- Porting note: Lean couldn't correctly infer `(I.pi ι)` and `(I.pi ι')` on their own
toFun := induced_map I e
invFun := induced_map I e.symm
map_add' := by
rintro ⟨a⟩ ⟨b⟩
convert_to Ideal.Quotient.mk (I.pi ι') _ = Ideal.Quotient.mk (I.pi ι') _
congr
simp only [map_add]
map_smul' := by
rintro ⟨a⟩ ⟨b⟩
convert_to Ideal.Quotient.mk (I.pi ι') _ = Ideal.Quotient.mk (I.pi ι') _
congr
simp only [LinearEquiv.coe_coe, LinearEquiv.map_smulₛₗ, RingHom.id_apply]
left_inv := by
rintro ⟨a⟩
convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _
congr
simp only [LinearEquiv.coe_coe, LinearEquiv.symm_apply_apply]
right_inv := by
rintro ⟨a⟩
convert_to Ideal.Quotient.mk (I.pi ι') _ = Ideal.Quotient.mk (I.pi ι') _
congr
simp only [LinearEquiv.coe_coe, LinearEquiv.apply_symm_apply]
end
section
attribute [local instance] Ideal.Quotient.field
/-- Nontrivial commutative rings have the invariant basis number property.
In fact, any nontrivial commutative ring satisfies the strong rank condition, see
`commRing_strongRankCondition`. We prove this instance separately to avoid dependency on
`LinearAlgebra.Charpoly.Basic`. -/
instance (priority := 100) invariantBasisNumber_of_nontrivial_of_commRing {R : Type u} [CommRing R]
[Nontrivial R] : InvariantBasisNumber R :=
⟨fun e =>
let ⟨I, _hI⟩ := Ideal.exists_maximal R
eq_of_fin_equiv (R ⧸ I)
((Ideal.piQuotEquiv _ _).symm ≪≫ₗ (induced_equiv _ e ≪≫ₗ Ideal.piQuotEquiv _ _))⟩
end
|
LinearAlgebra\Isomorphisms.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov
-/
import Mathlib.LinearAlgebra.Quotient
/-!
# Isomorphism theorems for modules.
* The Noether's first, second, and third isomorphism theorems for modules are proved as
`LinearMap.quotKerEquivRange`, `LinearMap.quotientInfEquivSupQuotient` and
`Submodule.quotientQuotientEquivQuotient`.
-/
universe u v
variable {R M M₂ M₃ : Type*}
variable [Ring R] [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃]
variable [Module R M] [Module R M₂] [Module R M₃]
variable (f : M →ₗ[R] M₂)
/-! The first and second isomorphism theorems for modules. -/
namespace LinearMap
open Submodule
section IsomorphismLaws
/-- The **first isomorphism law for modules**. The quotient of `M` by the kernel of `f` is linearly
equivalent to the range of `f`. -/
noncomputable def quotKerEquivRange : (M ⧸ LinearMap.ker f) ≃ₗ[R] LinearMap.range f :=
(LinearEquiv.ofInjective (f.ker.liftQ f <| le_rfl) <|
ker_eq_bot.mp <| Submodule.ker_liftQ_eq_bot _ _ _ (le_refl (LinearMap.ker f))).trans
(LinearEquiv.ofEq _ _ <| Submodule.range_liftQ _ _ _)
/-- The **first isomorphism theorem for surjective linear maps**. -/
noncomputable def quotKerEquivOfSurjective (f : M →ₗ[R] M₂) (hf : Function.Surjective f) :
(M ⧸ LinearMap.ker f) ≃ₗ[R] M₂ :=
f.quotKerEquivRange.trans (LinearEquiv.ofTop (LinearMap.range f) (LinearMap.range_eq_top.2 hf))
@[simp]
theorem quotKerEquivRange_apply_mk (x : M) :
(f.quotKerEquivRange (Submodule.Quotient.mk x) : M₂) = f x :=
rfl
@[simp]
theorem quotKerEquivRange_symm_apply_image (x : M) (h : f x ∈ LinearMap.range f) :
f.quotKerEquivRange.symm ⟨f x, h⟩ = f.ker.mkQ x :=
f.quotKerEquivRange.symm_apply_apply (f.ker.mkQ x)
-- Porting note: breaking up original definition of quotientInfToSupQuotient to avoid timing out
/-- Linear map from `p` to `p+p'/p'` where `p p'` are submodules of `R` -/
abbrev subToSupQuotient (p p' : Submodule R M) :
{ x // x ∈ p } →ₗ[R] { x // x ∈ p ⊔ p' } ⧸ comap (Submodule.subtype (p ⊔ p')) p' :=
(comap (p ⊔ p').subtype p').mkQ.comp (Submodule.inclusion le_sup_left)
-- Porting note: breaking up original definition of quotientInfToSupQuotient to avoid timing out
theorem comap_leq_ker_subToSupQuotient (p p' : Submodule R M) :
comap (Submodule.subtype p) (p ⊓ p') ≤ ker (subToSupQuotient p p') := by
rw [LinearMap.ker_comp, Submodule.inclusion, comap_codRestrict, ker_mkQ, map_comap_subtype]
exact comap_mono (inf_le_inf_right _ le_sup_left)
/-- Canonical linear map from the quotient `p/(p ∩ p')` to `(p+p')/p'`, mapping `x + (p ∩ p')`
to `x + p'`, where `p` and `p'` are submodules of an ambient module.
-/
def quotientInfToSupQuotient (p p' : Submodule R M) :
(↥p) ⧸ (comap p.subtype (p ⊓ p')) →ₗ[R] (↥(p ⊔ p')) ⧸ (comap (p ⊔ p').subtype p') :=
(comap p.subtype (p ⊓ p')).liftQ (subToSupQuotient p p') (comap_leq_ker_subToSupQuotient p p')
-- Porting note: breaking up original definition of quotientInfEquivSupQuotient to avoid timing out
theorem quotientInfEquivSupQuotient_injective (p p' : Submodule R M) :
Function.Injective (quotientInfToSupQuotient p p') := by
rw [← ker_eq_bot, quotientInfToSupQuotient, ker_liftQ_eq_bot]
rw [ker_comp, ker_mkQ]
exact fun ⟨x, hx1⟩ hx2 => ⟨hx1, hx2⟩
-- Porting note: breaking up original definition of quotientInfEquivSupQuotient to avoid timing out
theorem quotientInfEquivSupQuotient_surjective (p p' : Submodule R M) :
Function.Surjective (quotientInfToSupQuotient p p') := by
rw [← range_eq_top, quotientInfToSupQuotient, range_liftQ, eq_top_iff']
rintro ⟨x, hx⟩; rcases mem_sup.1 hx with ⟨y, hy, z, hz, rfl⟩
use ⟨y, hy⟩; apply (Submodule.Quotient.eq _).2
simp only [mem_comap, map_sub, coeSubtype, coe_inclusion, sub_add_cancel_left, neg_mem_iff, hz]
/--
Second Isomorphism Law : the canonical map from `p/(p ∩ p')` to `(p+p')/p'` as a linear isomorphism.
-/
noncomputable def quotientInfEquivSupQuotient (p p' : Submodule R M) :
(p ⧸ comap p.subtype (p ⊓ p')) ≃ₗ[R] _ ⧸ comap (p ⊔ p').subtype p' :=
LinearEquiv.ofBijective (quotientInfToSupQuotient p p')
⟨quotientInfEquivSupQuotient_injective p p', quotientInfEquivSupQuotient_surjective p p'⟩
-- @[simp]
-- Porting note: `simp` affects the type arguments of `DFunLike.coe`, so this theorem can't be
-- a simp theorem anymore, even if it has high priority.
theorem coe_quotientInfToSupQuotient (p p' : Submodule R M) :
⇑(quotientInfToSupQuotient p p') = quotientInfEquivSupQuotient p p' :=
rfl
-- This lemma was always bad, but the linter only noticed after lean4#2644
@[simp, nolint simpNF]
theorem quotientInfEquivSupQuotient_apply_mk (p p' : Submodule R M) (x : p) :
let map := inclusion (le_sup_left : p ≤ p ⊔ p')
quotientInfEquivSupQuotient p p' (Submodule.Quotient.mk x) =
@Submodule.Quotient.mk R (p ⊔ p' : Submodule R M) _ _ _ (comap (p ⊔ p').subtype p') (map x) :=
rfl
theorem quotientInfEquivSupQuotient_symm_apply_left (p p' : Submodule R M) (x : ↥(p ⊔ p'))
(hx : (x : M) ∈ p) :
(quotientInfEquivSupQuotient p p').symm (Submodule.Quotient.mk x) =
Submodule.Quotient.mk ⟨x, hx⟩ :=
(LinearEquiv.symm_apply_eq _).2 <| by
-- porting note (#10745): was `simp`.
rw [quotientInfEquivSupQuotient_apply_mk, inclusion_apply]
-- @[simp] -- Porting note (#10618): simp can prove this
theorem quotientInfEquivSupQuotient_symm_apply_eq_zero_iff {p p' : Submodule R M} {x : ↥(p ⊔ p')} :
(quotientInfEquivSupQuotient p p').symm (Submodule.Quotient.mk x) = 0 ↔ (x : M) ∈ p' :=
(LinearEquiv.symm_apply_eq _).trans <| by
-- porting note (#10745): was `simp`.
rw [_root_.map_zero, Quotient.mk_eq_zero, mem_comap, Submodule.coeSubtype]
theorem quotientInfEquivSupQuotient_symm_apply_right (p p' : Submodule R M) {x : ↥(p ⊔ p')}
(hx : (x : M) ∈ p') : (quotientInfEquivSupQuotient p p').symm (Submodule.Quotient.mk x)
= 0 :=
quotientInfEquivSupQuotient_symm_apply_eq_zero_iff.2 hx
end IsomorphismLaws
end LinearMap
/-! The third isomorphism theorem for modules. -/
namespace Submodule
variable (S T : Submodule R M) (h : S ≤ T)
/-- The map from the third isomorphism theorem for modules: `(M / S) / (T / S) → M / T`. -/
def quotientQuotientEquivQuotientAux (h : S ≤ T) : (M ⧸ S) ⧸ T.map S.mkQ →ₗ[R] M ⧸ T :=
liftQ _ (mapQ S T LinearMap.id h)
(by
rintro _ ⟨x, hx, rfl⟩
rw [LinearMap.mem_ker, mkQ_apply, mapQ_apply]
exact (Quotient.mk_eq_zero _).mpr hx)
@[simp]
theorem quotientQuotientEquivQuotientAux_mk (x : M ⧸ S) :
quotientQuotientEquivQuotientAux S T h (Quotient.mk x) = mapQ S T LinearMap.id h x :=
liftQ_apply _ _ _
-- @[simp] -- Porting note (#10618): simp can prove this
theorem quotientQuotientEquivQuotientAux_mk_mk (x : M) :
quotientQuotientEquivQuotientAux S T h (Quotient.mk (Quotient.mk x)) = Quotient.mk x := by simp
/-- **Noether's third isomorphism theorem** for modules: `(M / S) / (T / S) ≃ M / T`. -/
def quotientQuotientEquivQuotient : ((M ⧸ S) ⧸ T.map S.mkQ) ≃ₗ[R] M ⧸ T :=
{ quotientQuotientEquivQuotientAux S T h with
toFun := quotientQuotientEquivQuotientAux S T h
invFun := mapQ _ _ (mkQ S) (le_comap_map _ _)
left_inv := fun x => Quotient.inductionOn' x fun x => Quotient.inductionOn' x fun x => by simp
right_inv := fun x => Quotient.inductionOn' x fun x => by simp }
/-- Essentially the same equivalence as in the third isomorphism theorem,
except restated in terms of suprema/addition of submodules instead of `≤`. -/
def quotientQuotientEquivQuotientSup : ((M ⧸ S) ⧸ T.map S.mkQ) ≃ₗ[R] M ⧸ S ⊔ T :=
quotEquivOfEq _ _ (by rw [map_sup, mkQ_map_self, bot_sup_eq]) ≪≫ₗ
quotientQuotientEquivQuotient S (S ⊔ T) le_sup_left
/-- Corollary of the third isomorphism theorem: `[S : T] [M : S] = [M : T]` -/
theorem card_quotient_mul_card_quotient (S T : Submodule R M) (hST : T ≤ S) :
Nat.card (S.map T.mkQ) * Nat.card (M ⧸ S) = Nat.card (M ⧸ T) := by
rw [Submodule.card_eq_card_quotient_mul_card (map T.mkQ S),
Nat.card_congr (quotientQuotientEquivQuotient T S hST).toEquiv]
end Submodule
|
LinearAlgebra\JordanChevalley.lean | /-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Dynamics.Newton
import Mathlib.LinearAlgebra.Semisimple
/-!
# Jordan-Chevalley-Dunford decomposition
Given a finite-dimensional linear endomorphism `f`, the Jordan-Chevalley-Dunford theorem provides a
sufficient condition for there to exist a nilpotent endomorphism `n` and a semisimple endomorphism
`s`, such that `f = n + s` and both `n` and `s` are polynomial expressions in `f`.
The condition is that there exists a separable polynomial `P` such that the endomorphism `P(f)` is
nilpotent. This condition is always satisfied when the coefficients are a perfect field.
The proof given here uses Newton's method and is taken from Chambert-Loir's notes:
[Algebre](http://webusers.imj-prg.fr/~antoine.chambert-loir/enseignement/2022-23/agreg/algebre.pdf)
## Main definitions / results:
* `Module.End.exists_isNilpotent_isSemisimple`: an endomorphism of a finite-dimensional vector
space over a perfect field may be written as a sum of nilpotent and semisimple endomorphisms.
Moreover these nilpotent and semisimple components are polynomial expressions in the original
endomorphism.
## TODO
* Uniqueness of decomposition (once we prove that the sum of commuting semisimple endomorphims is
semisimple, this will follow from `Module.End.eq_zero_of_isNilpotent_isSemisimple`).
-/
open Algebra Polynomial
namespace Module.End
variable {K V : Type*} [Field K] [AddCommGroup V] [Module K V] {f : End K V}
theorem exists_isNilpotent_isSemisimple_of_separable_of_dvd_pow {P : K[X]} {k : ℕ}
(sep : P.Separable) (nil : minpoly K f ∣ P ^ k) :
∃ᵉ (n ∈ adjoin K {f}) (s ∈ adjoin K {f}), IsNilpotent n ∧ IsSemisimple s ∧ f = n + s := by
set ff : adjoin K {f} := ⟨f, self_mem_adjoin_singleton K f⟩
set P' := derivative P
have nil' : IsNilpotent (aeval ff P) := by
use k
obtain ⟨q, hq⟩ := nil
rw [← map_pow, Subtype.ext_iff]
simp [ff, hq]
have sep' : IsUnit (aeval ff P') := by
obtain ⟨a, b, h⟩ : IsCoprime (P ^ k) P' := sep.pow_left
replace h : (aeval f b) * (aeval f P') = 1 := by
simpa only [map_add, map_mul, map_one, minpoly.dvd_iff.mp nil, mul_zero, zero_add]
using (aeval f).congr_arg h
refine isUnit_of_mul_eq_one_right (aeval ff b) _ (Subtype.ext_iff.mpr ?_)
simpa [ff, coe_aeval_mk_apply] using h
obtain ⟨⟨s, mem⟩, ⟨⟨k, hk⟩, hss⟩, -⟩ := exists_unique_nilpotent_sub_and_aeval_eq_zero nil' sep'
refine ⟨f - s, ?_, s, mem, ⟨k, ?_⟩, ?_, (sub_add_cancel f s).symm⟩
· exact sub_mem (self_mem_adjoin_singleton K f) mem
· rw [Subtype.ext_iff] at hk
simpa using hk
· replace hss : aeval s P = 0 := by rwa [Subtype.ext_iff, coe_aeval_mk_apply] at hss
exact isSemisimple_of_squarefree_aeval_eq_zero sep.squarefree hss
variable [FiniteDimensional K V]
/-- **Jordan-Chevalley-Dunford decomposition**: an endomorphism of a finite-dimensional vector space
over a perfect field may be written as a sum of nilpotent and semisimple endomorphisms. Moreover
these nilpotent and semisimple components are polynomial expressions in the original endomorphism.
-/
theorem exists_isNilpotent_isSemisimple [PerfectField K] :
∃ᵉ (n ∈ adjoin K {f}) (s ∈ adjoin K {f}), IsNilpotent n ∧ IsSemisimple s ∧ f = n + s := by
obtain ⟨g, k, sep, -, nil⟩ := exists_squarefree_dvd_pow_of_ne_zero (minpoly.ne_zero_of_finite K f)
rw [← PerfectField.separable_iff_squarefree] at sep
exact exists_isNilpotent_isSemisimple_of_separable_of_dvd_pow sep nil
end Module.End
|
LinearAlgebra\Lagrange.lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Wrenna Robson
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.LinearAlgebra.Vandermonde
import Mathlib.RingTheory.Polynomial.Basic
/-!
# Lagrange interpolation
## Main definitions
* In everything that follows, `s : Finset ι` is a finite set of indexes, with `v : ι → F` an
indexing of the field over some type. We call the image of v on s the interpolation nodes,
though strictly unique nodes are only defined when v is injective on s.
* `Lagrange.basisDivisor x y`, with `x y : F`. These are the normalised irreducible factors of
the Lagrange basis polynomials. They evaluate to `1` at `x` and `0` at `y` when `x` and `y`
are distinct.
* `Lagrange.basis v i` with `i : ι`: the Lagrange basis polynomial that evaluates to `1` at `v i`
and `0` at `v j` for `i ≠ j`.
* `Lagrange.interpolate v r` where `r : ι → F` is a function from the fintype to the field: the
Lagrange interpolant that evaluates to `r i` at `x i` for all `i : ι`. The `r i` are the _values_
associated with the _nodes_`x i`.
-/
open Polynomial
section PolynomialDetermination
namespace Polynomial
variable {R : Type*} [CommRing R] [IsDomain R] {f g : R[X]}
section Finset
open Function Fintype
variable (s : Finset R)
theorem eq_zero_of_degree_lt_of_eval_finset_eq_zero (degree_f_lt : f.degree < s.card)
(eval_f : ∀ x ∈ s, f.eval x = 0) : f = 0 := by
rw [← mem_degreeLT] at degree_f_lt
simp_rw [eval_eq_sum_degreeLTEquiv degree_f_lt] at eval_f
rw [← degreeLTEquiv_eq_zero_iff_eq_zero degree_f_lt]
exact
Matrix.eq_zero_of_forall_index_sum_mul_pow_eq_zero
(Injective.comp (Embedding.subtype _).inj' (equivFinOfCardEq (card_coe _)).symm.injective)
fun _ => eval_f _ (Finset.coe_mem _)
theorem eq_of_degree_sub_lt_of_eval_finset_eq (degree_fg_lt : (f - g).degree < s.card)
(eval_fg : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by
rw [← sub_eq_zero]
refine eq_zero_of_degree_lt_of_eval_finset_eq_zero _ degree_fg_lt ?_
simp_rw [eval_sub, sub_eq_zero]
exact eval_fg
theorem eq_of_degrees_lt_of_eval_finset_eq (degree_f_lt : f.degree < s.card)
(degree_g_lt : g.degree < s.card) (eval_fg : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by
rw [← mem_degreeLT] at degree_f_lt degree_g_lt
refine eq_of_degree_sub_lt_of_eval_finset_eq _ ?_ eval_fg
rw [← mem_degreeLT]; exact Submodule.sub_mem _ degree_f_lt degree_g_lt
/--
Two polynomials, with the same degree and leading coefficient, which have the same evaluation
on a set of distinct values with cardinality equal to the degree, are equal.
-/
theorem eq_of_degree_le_of_eval_finset_eq
(h_deg_le : f.degree ≤ s.card)
(h_deg_eq : f.degree = g.degree)
(hlc : f.leadingCoeff = g.leadingCoeff)
(h_eval : ∀ x ∈ s, f.eval x = g.eval x) :
f = g := by
rcases eq_or_ne f 0 with rfl | hf
· rwa [degree_zero, eq_comm, degree_eq_bot, eq_comm] at h_deg_eq
· exact eq_of_degree_sub_lt_of_eval_finset_eq s
(lt_of_lt_of_le (degree_sub_lt h_deg_eq hf hlc) h_deg_le) h_eval
end Finset
section Indexed
open Finset
variable {ι : Type*} {v : ι → R} (s : Finset ι)
theorem eq_zero_of_degree_lt_of_eval_index_eq_zero (hvs : Set.InjOn v s)
(degree_f_lt : f.degree < s.card) (eval_f : ∀ i ∈ s, f.eval (v i) = 0) : f = 0 := by
classical
rw [← card_image_of_injOn hvs] at degree_f_lt
refine eq_zero_of_degree_lt_of_eval_finset_eq_zero _ degree_f_lt ?_
intro x hx
rcases mem_image.mp hx with ⟨_, hj, rfl⟩
exact eval_f _ hj
theorem eq_of_degree_sub_lt_of_eval_index_eq (hvs : Set.InjOn v s)
(degree_fg_lt : (f - g).degree < s.card) (eval_fg : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) :
f = g := by
rw [← sub_eq_zero]
refine eq_zero_of_degree_lt_of_eval_index_eq_zero _ hvs degree_fg_lt ?_
simp_rw [eval_sub, sub_eq_zero]
exact eval_fg
theorem eq_of_degrees_lt_of_eval_index_eq (hvs : Set.InjOn v s) (degree_f_lt : f.degree < s.card)
(degree_g_lt : g.degree < s.card) (eval_fg : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by
refine eq_of_degree_sub_lt_of_eval_index_eq _ hvs ?_ eval_fg
rw [← mem_degreeLT] at degree_f_lt degree_g_lt ⊢
exact Submodule.sub_mem _ degree_f_lt degree_g_lt
theorem eq_of_degree_le_of_eval_index_eq (hvs : Set.InjOn v s)
(h_deg_le : f.degree ≤ s.card)
(h_deg_eq : f.degree = g.degree)
(hlc : f.leadingCoeff = g.leadingCoeff)
(h_eval : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by
rcases eq_or_ne f 0 with rfl | hf
· rwa [degree_zero, eq_comm, degree_eq_bot, eq_comm] at h_deg_eq
· exact eq_of_degree_sub_lt_of_eval_index_eq s hvs
(lt_of_lt_of_le (degree_sub_lt h_deg_eq hf hlc) h_deg_le)
h_eval
end Indexed
end Polynomial
end PolynomialDetermination
noncomputable section
namespace Lagrange
open Polynomial
section BasisDivisor
variable {F : Type*} [Field F]
variable {x y : F}
/-- `basisDivisor x y` is the unique linear or constant polynomial such that
when evaluated at `x` it gives `1` and `y` it gives `0` (where when `x = y` it is identically `0`).
Such polynomials are the building blocks for the Lagrange interpolants. -/
def basisDivisor (x y : F) : F[X] :=
C (x - y)⁻¹ * (X - C y)
theorem basisDivisor_self : basisDivisor x x = 0 := by
simp only [basisDivisor, sub_self, inv_zero, map_zero, zero_mul]
theorem basisDivisor_inj (hxy : basisDivisor x y = 0) : x = y := by
simp_rw [basisDivisor, mul_eq_zero, X_sub_C_ne_zero, or_false_iff, C_eq_zero, inv_eq_zero,
sub_eq_zero] at hxy
exact hxy
@[simp]
theorem basisDivisor_eq_zero_iff : basisDivisor x y = 0 ↔ x = y :=
⟨basisDivisor_inj, fun H => H ▸ basisDivisor_self⟩
theorem basisDivisor_ne_zero_iff : basisDivisor x y ≠ 0 ↔ x ≠ y := by
rw [Ne, basisDivisor_eq_zero_iff]
theorem degree_basisDivisor_of_ne (hxy : x ≠ y) : (basisDivisor x y).degree = 1 := by
rw [basisDivisor, degree_mul, degree_X_sub_C, degree_C, zero_add]
exact inv_ne_zero (sub_ne_zero_of_ne hxy)
@[simp]
theorem degree_basisDivisor_self : (basisDivisor x x).degree = ⊥ := by
rw [basisDivisor_self, degree_zero]
theorem natDegree_basisDivisor_self : (basisDivisor x x).natDegree = 0 := by
rw [basisDivisor_self, natDegree_zero]
theorem natDegree_basisDivisor_of_ne (hxy : x ≠ y) : (basisDivisor x y).natDegree = 1 :=
natDegree_eq_of_degree_eq_some (degree_basisDivisor_of_ne hxy)
@[simp]
theorem eval_basisDivisor_right : eval y (basisDivisor x y) = 0 := by
simp only [basisDivisor, eval_mul, eval_C, eval_sub, eval_X, sub_self, mul_zero]
theorem eval_basisDivisor_left_of_ne (hxy : x ≠ y) : eval x (basisDivisor x y) = 1 := by
simp only [basisDivisor, eval_mul, eval_C, eval_sub, eval_X]
exact inv_mul_cancel (sub_ne_zero_of_ne hxy)
end BasisDivisor
section Basis
variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι]
variable {s : Finset ι} {v : ι → F} {i j : ι}
open Finset
/-- Lagrange basis polynomials indexed by `s : Finset ι`, defined at nodes `v i` for a
map `v : ι → F`. For `i, j ∈ s`, `basis s v i` evaluates to 0 at `v j` for `i ≠ j`. When
`v` is injective on `s`, `basis s v i` evaluates to 1 at `v i`. -/
protected def basis (s : Finset ι) (v : ι → F) (i : ι) : F[X] :=
∏ j ∈ s.erase i, basisDivisor (v i) (v j)
@[simp]
theorem basis_empty : Lagrange.basis ∅ v i = 1 :=
rfl
@[simp]
theorem basis_singleton (i : ι) : Lagrange.basis {i} v i = 1 := by
rw [Lagrange.basis, erase_singleton, prod_empty]
@[simp]
theorem basis_pair_left (hij : i ≠ j) : Lagrange.basis {i, j} v i = basisDivisor (v i) (v j) := by
simp only [Lagrange.basis, hij, erase_insert_eq_erase, erase_eq_of_not_mem, mem_singleton,
not_false_iff, prod_singleton]
@[simp]
theorem basis_pair_right (hij : i ≠ j) : Lagrange.basis {i, j} v j = basisDivisor (v j) (v i) := by
rw [pair_comm]
exact basis_pair_left hij.symm
theorem basis_ne_zero (hvs : Set.InjOn v s) (hi : i ∈ s) : Lagrange.basis s v i ≠ 0 := by
simp_rw [Lagrange.basis, prod_ne_zero_iff, Ne, mem_erase]
rintro j ⟨hij, hj⟩
rw [basisDivisor_eq_zero_iff, hvs.eq_iff hi hj]
exact hij.symm
@[simp]
theorem eval_basis_self (hvs : Set.InjOn v s) (hi : i ∈ s) :
(Lagrange.basis s v i).eval (v i) = 1 := by
rw [Lagrange.basis, eval_prod]
refine prod_eq_one fun j H => ?_
rw [eval_basisDivisor_left_of_ne]
rcases mem_erase.mp H with ⟨hij, hj⟩
exact mt (hvs hi hj) hij.symm
@[simp]
theorem eval_basis_of_ne (hij : i ≠ j) (hj : j ∈ s) : (Lagrange.basis s v i).eval (v j) = 0 := by
simp_rw [Lagrange.basis, eval_prod, prod_eq_zero_iff]
exact ⟨j, ⟨mem_erase.mpr ⟨hij.symm, hj⟩, eval_basisDivisor_right⟩⟩
@[simp]
theorem natDegree_basis (hvs : Set.InjOn v s) (hi : i ∈ s) :
(Lagrange.basis s v i).natDegree = s.card - 1 := by
have H : ∀ j, j ∈ s.erase i → basisDivisor (v i) (v j) ≠ 0 := by
simp_rw [Ne, mem_erase, basisDivisor_eq_zero_iff]
exact fun j ⟨hij₁, hj⟩ hij₂ => hij₁ (hvs hj hi hij₂.symm)
rw [← card_erase_of_mem hi, card_eq_sum_ones]
convert natDegree_prod _ _ H using 1
refine sum_congr rfl fun j hj => (natDegree_basisDivisor_of_ne ?_).symm
rw [Ne, ← basisDivisor_eq_zero_iff]
exact H _ hj
theorem degree_basis (hvs : Set.InjOn v s) (hi : i ∈ s) :
(Lagrange.basis s v i).degree = ↑(s.card - 1) := by
rw [degree_eq_natDegree (basis_ne_zero hvs hi), natDegree_basis hvs hi]
-- Porting note: Added `Nat.cast_withBot` rewrites
theorem sum_basis (hvs : Set.InjOn v s) (hs : s.Nonempty) :
∑ j ∈ s, Lagrange.basis s v j = 1 := by
refine eq_of_degrees_lt_of_eval_index_eq s hvs (lt_of_le_of_lt (degree_sum_le _ _) ?_) ?_ ?_
· rw [Nat.cast_withBot, Finset.sup_lt_iff (WithBot.bot_lt_coe s.card)]
intro i hi
rw [degree_basis hvs hi, Nat.cast_withBot, WithBot.coe_lt_coe]
exact Nat.pred_lt (card_ne_zero_of_mem hi)
· rw [degree_one, ← WithBot.coe_zero, Nat.cast_withBot, WithBot.coe_lt_coe]
exact Nonempty.card_pos hs
· intro i hi
rw [eval_finset_sum, eval_one, ← add_sum_erase _ _ hi, eval_basis_self hvs hi,
add_right_eq_self]
refine sum_eq_zero fun j hj => ?_
rcases mem_erase.mp hj with ⟨hij, _⟩
rw [eval_basis_of_ne hij hi]
theorem basisDivisor_add_symm {x y : F} (hxy : x ≠ y) :
basisDivisor x y + basisDivisor y x = 1 := by
classical
rw [← sum_basis Function.injective_id.injOn ⟨x, mem_insert_self _ {y}⟩,
sum_insert (not_mem_singleton.mpr hxy), sum_singleton, basis_pair_left hxy,
basis_pair_right hxy, id, id]
end Basis
section Interpolate
variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι]
variable {s t : Finset ι} {i j : ι} {v : ι → F} (r r' : ι → F)
open Finset
/-- Lagrange interpolation: given a finset `s : Finset ι`, a nodal map `v : ι → F` injective on
`s` and a value function `r : ι → F`, `interpolate s v r` is the unique
polynomial of degree `< s.card` that takes value `r i` on `v i` for all `i` in `s`. -/
@[simps]
def interpolate (s : Finset ι) (v : ι → F) : (ι → F) →ₗ[F] F[X] where
toFun r := ∑ i ∈ s, C (r i) * Lagrange.basis s v i
map_add' f g := by
simp_rw [← Finset.sum_add_distrib]
have h : (fun x => C (f x) * Lagrange.basis s v x + C (g x) * Lagrange.basis s v x) =
(fun x => C ((f + g) x) * Lagrange.basis s v x) := by
simp_rw [← add_mul, ← C_add, Pi.add_apply]
rw [h]
map_smul' c f := by
simp_rw [Finset.smul_sum, C_mul', smul_smul, Pi.smul_apply, RingHom.id_apply, smul_eq_mul]
-- Porting note (#10618): There was originally '@[simp]' on this line but it was removed because
-- 'simp' could prove 'interpolate_empty'
theorem interpolate_empty : interpolate ∅ v r = 0 := by rw [interpolate_apply, sum_empty]
-- Porting note (#10618): There was originally '@[simp]' on this line but it was removed because
-- 'simp' could prove 'interpolate_singleton'
theorem interpolate_singleton : interpolate {i} v r = C (r i) := by
rw [interpolate_apply, sum_singleton, basis_singleton, mul_one]
theorem interpolate_one (hvs : Set.InjOn v s) (hs : s.Nonempty) : interpolate s v 1 = 1 := by
simp_rw [interpolate_apply, Pi.one_apply, map_one, one_mul]
exact sum_basis hvs hs
theorem eval_interpolate_at_node (hvs : Set.InjOn v s) (hi : i ∈ s) :
eval (v i) (interpolate s v r) = r i := by
rw [interpolate_apply, eval_finset_sum, ← add_sum_erase _ _ hi]
simp_rw [eval_mul, eval_C, eval_basis_self hvs hi, mul_one, add_right_eq_self]
refine sum_eq_zero fun j H => ?_
rw [eval_basis_of_ne (mem_erase.mp H).1 hi, mul_zero]
theorem degree_interpolate_le (hvs : Set.InjOn v s) :
(interpolate s v r).degree ≤ ↑(s.card - 1) := by
refine (degree_sum_le _ _).trans ?_
rw [Finset.sup_le_iff]
intro i hi
rw [degree_mul, degree_basis hvs hi]
by_cases hr : r i = 0
· simpa only [hr, map_zero, degree_zero, WithBot.bot_add] using bot_le
· rw [degree_C hr, zero_add]
-- Porting note: Added `Nat.cast_withBot` rewrites
theorem degree_interpolate_lt (hvs : Set.InjOn v s) : (interpolate s v r).degree < s.card := by
rw [Nat.cast_withBot]
rcases eq_empty_or_nonempty s with (rfl | h)
· rw [interpolate_empty, degree_zero, card_empty]
exact WithBot.bot_lt_coe _
· refine lt_of_le_of_lt (degree_interpolate_le _ hvs) ?_
rw [Nat.cast_withBot, WithBot.coe_lt_coe]
exact Nat.sub_lt (Nonempty.card_pos h) zero_lt_one
theorem degree_interpolate_erase_lt (hvs : Set.InjOn v s) (hi : i ∈ s) :
(interpolate (s.erase i) v r).degree < ↑(s.card - 1) := by
rw [← Finset.card_erase_of_mem hi]
exact degree_interpolate_lt _ (Set.InjOn.mono (coe_subset.mpr (erase_subset _ _)) hvs)
theorem values_eq_on_of_interpolate_eq (hvs : Set.InjOn v s)
(hrr' : interpolate s v r = interpolate s v r') : ∀ i ∈ s, r i = r' i := fun _ hi => by
rw [← eval_interpolate_at_node r hvs hi, hrr', eval_interpolate_at_node r' hvs hi]
theorem interpolate_eq_of_values_eq_on (hrr' : ∀ i ∈ s, r i = r' i) :
interpolate s v r = interpolate s v r' :=
sum_congr rfl fun i hi => by rw [hrr' _ hi]
theorem interpolate_eq_iff_values_eq_on (hvs : Set.InjOn v s) :
interpolate s v r = interpolate s v r' ↔ ∀ i ∈ s, r i = r' i :=
⟨values_eq_on_of_interpolate_eq _ _ hvs, interpolate_eq_of_values_eq_on _ _⟩
theorem eq_interpolate {f : F[X]} (hvs : Set.InjOn v s) (degree_f_lt : f.degree < s.card) :
f = interpolate s v fun i => f.eval (v i) :=
eq_of_degrees_lt_of_eval_index_eq _ hvs degree_f_lt (degree_interpolate_lt _ hvs) fun _ hi =>
(eval_interpolate_at_node (fun x ↦ eval (v x) f) hvs hi).symm
theorem eq_interpolate_of_eval_eq {f : F[X]} (hvs : Set.InjOn v s) (degree_f_lt : f.degree < s.card)
(eval_f : ∀ i ∈ s, f.eval (v i) = r i) : f = interpolate s v r := by
rw [eq_interpolate hvs degree_f_lt]
exact interpolate_eq_of_values_eq_on _ _ eval_f
/-- This is the characteristic property of the interpolation: the interpolation is the
unique polynomial of `degree < Fintype.card ι` which takes the value of the `r i` on the `v i`.
-/
theorem eq_interpolate_iff {f : F[X]} (hvs : Set.InjOn v s) :
(f.degree < s.card ∧ ∀ i ∈ s, eval (v i) f = r i) ↔ f = interpolate s v r := by
constructor <;> intro h
· exact eq_interpolate_of_eval_eq _ hvs h.1 h.2
· rw [h]
exact ⟨degree_interpolate_lt _ hvs, fun _ hi => eval_interpolate_at_node _ hvs hi⟩
/-- Lagrange interpolation induces isomorphism between functions from `s`
and polynomials of degree less than `Fintype.card ι`. -/
def funEquivDegreeLT (hvs : Set.InjOn v s) : degreeLT F s.card ≃ₗ[F] s → F where
toFun f i := f.1.eval (v i)
map_add' f g := funext fun v => eval_add
map_smul' c f := funext <| by simp
invFun r :=
⟨interpolate s v fun x => if hx : x ∈ s then r ⟨x, hx⟩ else 0,
mem_degreeLT.2 <| degree_interpolate_lt _ hvs⟩
left_inv := by
rintro ⟨f, hf⟩
simp only [Subtype.mk_eq_mk, Subtype.coe_mk, dite_eq_ite]
rw [mem_degreeLT] at hf
conv => rhs; rw [eq_interpolate hvs hf]
exact interpolate_eq_of_values_eq_on _ _ fun _ hi => if_pos hi
right_inv := by
intro f
ext ⟨i, hi⟩
simp only [Subtype.coe_mk, eval_interpolate_at_node _ hvs hi]
exact dif_pos hi
-- Porting note: Added `Nat.cast_withBot` rewrites
theorem interpolate_eq_sum_interpolate_insert_sdiff (hvt : Set.InjOn v t) (hs : s.Nonempty)
(hst : s ⊆ t) :
interpolate t v r = ∑ i ∈ s, interpolate (insert i (t \ s)) v r * Lagrange.basis s v i := by
symm
refine eq_interpolate_of_eval_eq _ hvt (lt_of_le_of_lt (degree_sum_le _ _) ?_) fun i hi => ?_
· simp_rw [Nat.cast_withBot, Finset.sup_lt_iff (WithBot.bot_lt_coe t.card), degree_mul]
intro i hi
have hs : 1 ≤ s.card := Nonempty.card_pos ⟨_, hi⟩
have hst' : s.card ≤ t.card := card_le_card hst
have H : t.card = 1 + (t.card - s.card) + (s.card - 1) := by
rw [add_assoc, tsub_add_tsub_cancel hst' hs, ← add_tsub_assoc_of_le (hs.trans hst'),
Nat.succ_add_sub_one, zero_add]
rw [degree_basis (Set.InjOn.mono hst hvt) hi, H, WithBot.coe_add, Nat.cast_withBot,
WithBot.add_lt_add_iff_right (@WithBot.coe_ne_bot _ (s.card - 1))]
convert degree_interpolate_lt _
(hvt.mono (coe_subset.mpr (insert_subset_iff.mpr ⟨hst hi, sdiff_subset⟩)))
rw [card_insert_of_not_mem (not_mem_sdiff_of_mem_right hi), card_sdiff hst, add_comm]
· simp_rw [eval_finset_sum, eval_mul]
by_cases hi' : i ∈ s
· rw [← add_sum_erase _ _ hi', eval_basis_self (hvt.mono hst) hi',
eval_interpolate_at_node _
(hvt.mono (coe_subset.mpr (insert_subset_iff.mpr ⟨hi, sdiff_subset⟩)))
(mem_insert_self _ _),
mul_one, add_right_eq_self]
refine sum_eq_zero fun j hj => ?_
rcases mem_erase.mp hj with ⟨hij, _⟩
rw [eval_basis_of_ne hij hi', mul_zero]
· have H : (∑ j ∈ s, eval (v i) (Lagrange.basis s v j)) = 1 := by
rw [← eval_finset_sum, sum_basis (hvt.mono hst) hs, eval_one]
rw [← mul_one (r i), ← H, mul_sum]
refine sum_congr rfl fun j hj => ?_
congr
exact
eval_interpolate_at_node _ (hvt.mono (insert_subset_iff.mpr ⟨hst hj, sdiff_subset⟩))
(mem_insert.mpr (Or.inr (mem_sdiff.mpr ⟨hi, hi'⟩)))
theorem interpolate_eq_add_interpolate_erase (hvs : Set.InjOn v s) (hi : i ∈ s) (hj : j ∈ s)
(hij : i ≠ j) :
interpolate s v r =
interpolate (s.erase j) v r * basisDivisor (v i) (v j) +
interpolate (s.erase i) v r * basisDivisor (v j) (v i) := by
rw [interpolate_eq_sum_interpolate_insert_sdiff _ hvs ⟨i, mem_insert_self i {j}⟩ _,
sum_insert (not_mem_singleton.mpr hij), sum_singleton, basis_pair_left hij,
basis_pair_right hij, sdiff_insert_insert_of_mem_of_not_mem hi (not_mem_singleton.mpr hij),
sdiff_singleton_eq_erase, pair_comm,
sdiff_insert_insert_of_mem_of_not_mem hj (not_mem_singleton.mpr hij.symm),
sdiff_singleton_eq_erase]
exact insert_subset_iff.mpr ⟨hi, singleton_subset_iff.mpr hj⟩
end Interpolate
section Nodal
variable {R : Type*} [CommRing R] {ι : Type*}
variable {s : Finset ι} {v : ι → R}
open Finset Polynomial
/-- `nodal s v` is the unique monic polynomial whose roots are the nodes defined by `v` and `s`.
That is, the roots of `nodal s v` are exactly the image of `v` on `s`,
with appropriate multiplicity.
We can use `nodal` to define the barycentric forms of the evaluated interpolant.
-/
def nodal (s : Finset ι) (v : ι → R) : R[X] :=
∏ i ∈ s, (X - C (v i))
theorem nodal_eq (s : Finset ι) (v : ι → R) : nodal s v = ∏ i ∈ s, (X - C (v i)) :=
rfl
@[simp]
theorem nodal_empty : nodal ∅ v = 1 := by
rfl
@[simp]
theorem natDegree_nodal [Nontrivial R] : (nodal s v).natDegree = s.card := by
simp_rw [nodal, natDegree_prod_of_monic (h := fun i _ => monic_X_sub_C (v i)),
natDegree_X_sub_C, sum_const, smul_eq_mul, mul_one]
theorem nodal_ne_zero [Nontrivial R] : nodal s v ≠ 0 := by
rcases s.eq_empty_or_nonempty with (rfl | h)
· exact one_ne_zero
· apply ne_zero_of_natDegree_gt (n := 0)
simp only [natDegree_nodal, h.card_pos]
@[simp]
theorem degree_nodal [Nontrivial R] : (nodal s v).degree = s.card := by
simp_rw [degree_eq_natDegree nodal_ne_zero, natDegree_nodal]
theorem nodal_monic : (nodal s v).Monic :=
monic_prod_of_monic s (fun i ↦ X - C (v i)) fun i _ ↦ monic_X_sub_C (v i)
theorem eval_nodal {x : R} : (nodal s v).eval x = ∏ i ∈ s, (x - v i) := by
simp_rw [nodal, eval_prod, eval_sub, eval_X, eval_C]
theorem eval_nodal_at_node {i : ι} (hi : i ∈ s) : eval (v i) (nodal s v) = 0 := by
rw [eval_nodal]
exact s.prod_eq_zero hi (sub_self (v i))
theorem eval_nodal_not_at_node [Nontrivial R] [NoZeroDivisors R] {x : R}
(hx : ∀ i ∈ s, x ≠ v i) : eval x (nodal s v) ≠ 0 := by
simp_rw [nodal, eval_prod, prod_ne_zero_iff, eval_sub, eval_X, eval_C, sub_ne_zero]
exact hx
theorem nodal_eq_mul_nodal_erase [DecidableEq ι] {i : ι} (hi : i ∈ s) :
nodal s v = (X - C (v i)) * nodal (s.erase i) v := by
simp_rw [nodal, Finset.mul_prod_erase _ (fun x => X - C (v x)) hi]
theorem X_sub_C_dvd_nodal (v : ι → R) {i : ι} (hi : i ∈ s) : X - C (v i) ∣ nodal s v :=
⟨_, by classical exact nodal_eq_mul_nodal_erase hi⟩
theorem nodal_insert_eq_nodal [DecidableEq ι] {i : ι} (hi : i ∉ s) :
nodal (insert i s) v = (X - C (v i)) * nodal s v := by
simp_rw [nodal, prod_insert hi]
theorem derivative_nodal [DecidableEq ι] :
derivative (nodal s v) = ∑ i ∈ s, nodal (s.erase i) v := by
refine s.induction_on ?_ fun i t hit IH => ?_
· rw [nodal_empty, derivative_one, sum_empty]
· rw [nodal_insert_eq_nodal hit, derivative_mul, IH, derivative_sub, derivative_X, derivative_C,
sub_zero, one_mul, sum_insert hit, mul_sum, erase_insert hit, add_right_inj]
refine sum_congr rfl fun j hjt => ?_
rw [t.erase_insert_of_ne (ne_of_mem_of_not_mem hjt hit).symm,
nodal_insert_eq_nodal (mem_of_mem_erase.mt hit)]
theorem eval_nodal_derivative_eval_node_eq [DecidableEq ι] {i : ι} (hi : i ∈ s) :
eval (v i) (derivative (nodal s v)) = eval (v i) (nodal (s.erase i) v) := by
rw [derivative_nodal, eval_finset_sum, ← add_sum_erase _ _ hi, add_right_eq_self]
exact sum_eq_zero fun j hj => (eval_nodal_at_node (mem_erase.mpr ⟨(mem_erase.mp hj).1.symm, hi⟩))
/-- The vanishing polynomial on a multiplicative subgroup is of the form X ^ n - 1. -/
@[simp] theorem nodal_subgroup_eq_X_pow_card_sub_one [IsDomain R]
(G : Subgroup Rˣ) [Fintype G] :
nodal (G : Set Rˣ).toFinset ((↑) : Rˣ → R) = X ^ (Fintype.card G) - 1 := by
have h : degree (1 : R[X]) < degree ((X : R[X]) ^ Fintype.card G) := by simp [Fintype.card_pos]
apply eq_of_degree_le_of_eval_index_eq (v := ((↑) : Rˣ → R)) (G : Set Rˣ).toFinset
· exact Set.injOn_of_injective Units.ext
· simp
· rw [degree_sub_eq_left_of_degree_lt h, degree_nodal, Set.toFinset_card, degree_pow, degree_X,
nsmul_eq_mul, mul_one, Nat.cast_inj]
exact rfl
· rw [nodal_monic, leadingCoeff_sub_of_degree_lt h, monic_X_pow]
· intros i hi
rw [eval_nodal_at_node hi]
replace hi : i ∈ G := by simpa using hi
obtain ⟨g, rfl⟩ : ∃ g : G, g.val = i := ⟨⟨i, hi⟩, rfl⟩
simp [← Units.val_pow_eq_pow_val, ← Subgroup.coe_pow G]
end Nodal
section NodalWeight
variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι]
variable {s : Finset ι} {v : ι → F} {i : ι}
open Finset
/-- This defines the nodal weight for a given set of node indexes and node mapping function `v`. -/
def nodalWeight (s : Finset ι) (v : ι → F) (i : ι) :=
∏ j ∈ s.erase i, (v i - v j)⁻¹
theorem nodalWeight_eq_eval_nodal_erase_inv :
nodalWeight s v i = (eval (v i) (nodal (s.erase i) v))⁻¹ := by
rw [eval_nodal, nodalWeight, prod_inv_distrib]
theorem nodal_erase_eq_nodal_div (hi : i ∈ s) :
nodal (s.erase i) v = nodal s v / (X - C (v i)) := by
rw [nodal_eq_mul_nodal_erase hi, mul_div_cancel_left₀]
exact X_sub_C_ne_zero _
theorem nodalWeight_eq_eval_nodal_derative (hi : i ∈ s) :
nodalWeight s v i = (eval (v i) (Polynomial.derivative (nodal s v)))⁻¹ := by
rw [eval_nodal_derivative_eval_node_eq hi, nodalWeight_eq_eval_nodal_erase_inv]
theorem nodalWeight_ne_zero (hvs : Set.InjOn v s) (hi : i ∈ s) : nodalWeight s v i ≠ 0 := by
rw [nodalWeight, prod_ne_zero_iff]
intro j hj
rcases mem_erase.mp hj with ⟨hij, hj⟩
exact inv_ne_zero (sub_ne_zero_of_ne (mt (hvs.eq_iff hi hj).mp hij.symm))
end NodalWeight
section LagrangeBarycentric
variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι]
variable {s : Finset ι} {v : ι → F} (r : ι → F) {i : ι} {x : F}
open Finset
theorem basis_eq_prod_sub_inv_mul_nodal_div (hi : i ∈ s) :
Lagrange.basis s v i = C (nodalWeight s v i) * (nodal s v / (X - C (v i))) := by
simp_rw [Lagrange.basis, basisDivisor, nodalWeight, prod_mul_distrib, map_prod, ←
nodal_erase_eq_nodal_div hi, nodal]
theorem eval_basis_not_at_node (hi : i ∈ s) (hxi : x ≠ v i) :
eval x (Lagrange.basis s v i) = eval x (nodal s v) * (nodalWeight s v i * (x - v i)⁻¹) := by
rw [mul_comm, basis_eq_prod_sub_inv_mul_nodal_div hi, eval_mul, eval_C, ←
nodal_erase_eq_nodal_div hi, eval_nodal, eval_nodal, mul_assoc, ← mul_prod_erase _ _ hi, ←
mul_assoc (x - v i)⁻¹, inv_mul_cancel (sub_ne_zero_of_ne hxi), one_mul]
theorem interpolate_eq_nodalWeight_mul_nodal_div_X_sub_C :
interpolate s v r = ∑ i ∈ s, C (nodalWeight s v i) * (nodal s v / (X - C (v i))) * C (r i) :=
sum_congr rfl fun j hj => by rw [mul_comm, basis_eq_prod_sub_inv_mul_nodal_div hj]
/-- This is the first barycentric form of the Lagrange interpolant. -/
theorem eval_interpolate_not_at_node (hx : ∀ i ∈ s, x ≠ v i) :
eval x (interpolate s v r) =
eval x (nodal s v) * ∑ i ∈ s, nodalWeight s v i * (x - v i)⁻¹ * r i := by
simp_rw [interpolate_apply, mul_sum, eval_finset_sum, eval_mul, eval_C]
refine sum_congr rfl fun i hi => ?_
rw [← mul_assoc, mul_comm, eval_basis_not_at_node hi (hx _ hi)]
theorem sum_nodalWeight_mul_inv_sub_ne_zero (hvs : Set.InjOn v s) (hx : ∀ i ∈ s, x ≠ v i)
(hs : s.Nonempty) : (∑ i ∈ s, nodalWeight s v i * (x - v i)⁻¹) ≠ 0 :=
@right_ne_zero_of_mul_eq_one _ _ _ (eval x (nodal s v)) _ <| by
simpa only [Pi.one_apply, interpolate_one hvs hs, eval_one, mul_one] using
(eval_interpolate_not_at_node 1 hx).symm
/-- This is the second barycentric form of the Lagrange interpolant. -/
theorem eval_interpolate_not_at_node' (hvs : Set.InjOn v s) (hs : s.Nonempty)
(hx : ∀ i ∈ s, x ≠ v i) :
eval x (interpolate s v r) =
(∑ i ∈ s, nodalWeight s v i * (x - v i)⁻¹ * r i) /
∑ i ∈ s, nodalWeight s v i * (x - v i)⁻¹ := by
rw [← div_one (eval x (interpolate s v r)), ← @eval_one _ _ x, ← interpolate_one hvs hs,
eval_interpolate_not_at_node r hx, eval_interpolate_not_at_node 1 hx]
simp only [mul_div_mul_left _ _ (eval_nodal_not_at_node hx), Pi.one_apply, mul_one]
end LagrangeBarycentric
end Lagrange
|
LinearAlgebra\LinearDisjoint.lean | /-
Copyright (c) 2024 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.LinearAlgebra.TensorProduct.Tower
import Mathlib.LinearAlgebra.TensorProduct.Finiteness
import Mathlib.LinearAlgebra.TensorProduct.Submodule
import Mathlib.LinearAlgebra.Dimension.Finite
import Mathlib.RingTheory.Flat.Basic
/-!
# Linearly disjoint of submodules
This file contains basics about the linearly disjoint of submodules.
## Mathematical background
We adapt the definitions in <https://en.wikipedia.org/wiki/Linearly_disjoint>.
Let `R` be a commutative ring, `S` be an `R`-algebra (not necessarily commutative).
Let `M` and `N` be `R`-submodules in `S` (`Submodule R S`).
- `M` and `N` are linearly disjoint (`Submodule.LinearDisjoint M N` or simply
`M.LinearDisjoint N`), if the natural `R`-linear map `M ⊗[R] N →ₗ[R] S`
(`Submodule.mulMap M N`) induced by the multiplication in `S` is injective.
The following is the first equivalent characterization of linearly disjointness:
- `Submodule.LinearDisjoint.linearIndependent_left_of_flat`:
if `M` and `N` are linearly disjoint, if `N` is a flat `R`-module, then for any family of
`R`-linearly independent elements `{ m_i }` of `M`, they are also `N`-linearly independent,
in the sense that the `R`-linear map from `ι →₀ N` to `S` which maps `{ n_i }`
to the sum of `m_i * n_i` (`Submodule.mulLeftMap N m`) is injective.
- `Submodule.LinearDisjoint.of_basis_left`:
conversely, if `{ m_i }` is an `R`-basis of `M`, which is also `N`-linearly independent,
then `M` and `N` are linearly disjoint.
Dually, we have:
- `Submodule.LinearDisjoint.linearIndependent_right_of_flat`:
if `M` and `N` are linearly disjoint, if `M` is a flat `R`-module, then for any family of
`R`-linearly independent elements `{ n_i }` of `N`, they are also `M`-linearly independent,
in the sense that the `R`-linear map from `ι →₀ M` to `S` which maps `{ m_i }`
to the sum of `m_i * n_i` (`Submodule.mulRightMap M n`) is injective.
- `Submodule.LinearDisjoint.of_basis_right`:
conversely, if `{ n_i }` is an `R`-basis of `N`, which is also `M`-linearly independent,
then `M` and `N` are linearly disjoint.
The following is the second equivalent characterization of linearly disjointness:
- `Submodule.LinearDisjoint.linearIndependent_mul_of_flat`:
if `M` and `N` are linearly disjoint, if one of `M` and `N` is flat, then for any family of
`R`-linearly independent elements `{ m_i }` of `M`, and any family of
`R`-linearly independent elements `{ n_j }` of `N`, the family `{ m_i * n_j }` in `S` is
also `R`-linearly independent.
- `Submodule.LinearDisjoint.of_basis_mul`:
conversely, if `{ m_i }` is an `R`-basis of `M`, if `{ n_i }` is an `R`-basis of `N`,
such that the family `{ m_i * n_j }` in `S` is `R`-linearly independent,
then `M` and `N` are linearly disjoint.
## Other main results
- `Submodule.LinearDisjoint.symm_of_commute`, `Submodule.linearDisjoint_symm_of_commute`:
linearly disjoint is symmetric under some commutative conditions.
- `Submodule.linearDisjoint_op`:
linearly disjoint is preserved by taking multiplicative opposite.
- `Submodule.LinearDisjoint.of_le_left_of_flat`, `Submodule.LinearDisjoint.of_le_right_of_flat`,
`Submodule.LinearDisjoint.of_le_of_flat_left`, `Submodule.LinearDisjoint.of_le_of_flat_right`:
linearly disjoint is preserved by taking submodules under some flatness conditions.
- `Submodule.LinearDisjoint.of_linearDisjoint_fg_left`,
`Submodule.LinearDisjoint.of_linearDisjoint_fg_right`,
`Submodule.LinearDisjoint.of_linearDisjoint_fg`:
conversely, if any finitely generated submodules of `M` and `N` are linearly disjoint,
then `M` and `N` themselves are linearly disjoint.
- `Submodule.LinearDisjoint.bot_left`, `Submodule.LinearDisjoint.bot_right`:
the zero module is linearly disjoint with any other submodules.
- `Submodule.LinearDisjoint.one_left`, `Submodule.LinearDisjoint.one_right`:
the image of `R` in `S` is linearly disjoint with any other submodules.
- `Submodule.LinearDisjoint.of_left_le_one_of_flat`,
`Submodule.LinearDisjoint.of_right_le_one_of_flat`:
if a submodule is contained in the image of `R` in `S`, then it is linearly disjoint with
any other submodules, under some flatness conditions.
- `Submodule.LinearDisjoint.not_linearIndependent_pair_of_commute_of_flat`,
`Submodule.LinearDisjoint.rank_inf_le_one_of_commute_of_flat`:
if `M` and `N` are linearly disjoint, if one of `M` and `N` is flat, then any two commutative
elements contained in the intersection of `M` and `N` are not `R`-linearly independent (namely,
their span is not `R ^ 2`). In particular, if any two elements in the intersection of `M` and `N`
are commutative, then the rank of the intersection of `M` and `N` is at most one.
These results are stated using bundled version (i.e. `a : ↥(M ⊓ N)`). If you want a not bundled
version (i.e. `a : S` with `ha : a ∈ M ⊓ N`), you may use `LinearIndependent.of_comp` and
`FinVec.map_eq` (in `Mathlib/Data/Fin/Tuple/Reflection.lean`),
see the following code snippet:
```
have h := H.not_linearIndependent_pair_of_commute_of_flat hf ⟨a, ha⟩ ⟨b, hb⟩ hc
contrapose! h
refine .of_comp (M ⊓ N).subtype ?_
convert h
exact (FinVec.map_eq _ _).symm
```
- `Submodule.LinearDisjoint.rank_le_one_of_commute_of_flat_of_self`:
if `M` and itself are linearly disjoint, if `M` is flat, if any two elements in `M`
are commutative, then the rank of `M` is at most one.
The results with name containing "of_commute" also have corresponding specified versions
assuming `S` is commutative.
## Tags
linearly disjoint, linearly independent, tensor product
-/
open scoped TensorProduct
noncomputable section
universe u v w
namespace Submodule
variable {R : Type u} {S : Type v}
section Semiring
variable [CommSemiring R] [Semiring S] [Algebra R S]
variable (M N : Submodule R S)
/-- Two submodules `M` and `N` in an algebra `S` over `R` are linearly disjoint if the natural map
`M ⊗[R] N →ₗ[R] S` induced by multiplication in `S` is injective. -/
@[mk_iff]
protected structure LinearDisjoint : Prop where
injective : Function.Injective (mulMap M N)
variable {M N}
/-- If `M` and `N` are linearly disjoint submodules, then there is the natural isomorphism
`M ⊗[R] N ≃ₗ[R] M * N` induced by multiplication in `S`. -/
protected def LinearDisjoint.mulMap (H : M.LinearDisjoint N) : M ⊗[R] N ≃ₗ[R] M * N :=
LinearEquiv.ofInjective (M.mulMap N) H.injective ≪≫ₗ LinearEquiv.ofEq _ _ (mulMap_range M N)
@[simp]
theorem LinearDisjoint.val_mulMap_tmul (H : M.LinearDisjoint N) (m : M) (n : N) :
(H.mulMap (m ⊗ₜ[R] n) : S) = m.1 * n.1 := rfl
@[nontriviality]
theorem LinearDisjoint.of_subsingleton [Subsingleton R] : M.LinearDisjoint N := by
haveI : Subsingleton S := Module.subsingleton R S
exact ⟨Function.injective_of_subsingleton _⟩
/-- Linearly disjoint is preserved by taking multiplicative opposite. -/
theorem linearDisjoint_op :
M.LinearDisjoint N ↔ (equivOpposite.symm (MulOpposite.op N)).LinearDisjoint
(equivOpposite.symm (MulOpposite.op M)) := by
simp only [linearDisjoint_iff, mulMap_op, LinearMap.coe_comp,
LinearEquiv.coe_coe, EquivLike.comp_injective, EquivLike.injective_comp]
alias ⟨LinearDisjoint.op, LinearDisjoint.of_op⟩ := linearDisjoint_op
/-- Linearly disjoint is symmetric if elements in the module commute. -/
theorem LinearDisjoint.symm_of_commute (H : M.LinearDisjoint N)
(hc : ∀ (m : M) (n : N), Commute m.1 n.1) : N.LinearDisjoint M := by
rw [linearDisjoint_iff, mulMap_comm_of_commute M N hc]
exact ((TensorProduct.comm R N M).toEquiv.injective_comp _).2 H.injective
/-- Linearly disjoint is symmetric if elements in the module commute. -/
theorem linearDisjoint_symm_of_commute
(hc : ∀ (m : M) (n : N), Commute m.1 n.1) : M.LinearDisjoint N ↔ N.LinearDisjoint M :=
⟨fun H ↦ H.symm_of_commute hc, fun H ↦ H.symm_of_commute fun _ _ ↦ (hc _ _).symm⟩
namespace LinearDisjoint
variable (M N)
/-- If `{ m_i }` is an `R`-basis of `M`, which is also `N`-linearly independent
(in this result it is stated as `Submodule.mulLeftMap` is injective),
then `M` and `N` are linearly disjoint. -/
theorem of_basis_left' {ι : Type*} (m : Basis ι R M)
(H : Function.Injective (mulLeftMap N m)) : M.LinearDisjoint N := by
classical simp_rw [mulLeftMap_eq_mulMap_comp, ← Basis.coe_repr_symm,
← LinearEquiv.coe_rTensor, LinearEquiv.comp_coe, LinearMap.coe_comp,
LinearEquiv.coe_coe, EquivLike.injective_comp] at H
exact ⟨H⟩
/-- If `{ n_i }` is an `R`-basis of `N`, which is also `M`-linearly independent
(in this result it is stated as `Submodule.mulRightMap` is injective),
then `M` and `N` are linearly disjoint. -/
theorem of_basis_right' {ι : Type*} (n : Basis ι R N)
(H : Function.Injective (mulRightMap M n)) : M.LinearDisjoint N := by
classical simp_rw [mulRightMap_eq_mulMap_comp, ← Basis.coe_repr_symm,
← LinearEquiv.coe_lTensor, LinearEquiv.comp_coe, LinearMap.coe_comp,
LinearEquiv.coe_coe, EquivLike.injective_comp] at H
exact ⟨H⟩
/-- If `{ m_i }` is an `R`-basis of `M`, if `{ n_i }` is an `R`-basis of `N`,
such that the family `{ m_i * n_j }` in `S` is `R`-linearly independent
(in this result it is stated as the relevant `Finsupp.total` is injective),
then `M` and `N` are linearly disjoint. -/
theorem of_basis_mul' {κ ι : Type*} (m : Basis κ R M) (n : Basis ι R N)
(H : Function.Injective (Finsupp.total (κ × ι) S R fun i ↦ m i.1 * n i.2)) :
M.LinearDisjoint N := by
let i0 := (finsuppTensorFinsupp' R κ ι).symm
let i1 := TensorProduct.congr m.repr n.repr
let i := mulMap M N ∘ₗ (i0.trans i1.symm).toLinearMap
have : i = Finsupp.total (κ × ι) S R fun i ↦ m i.1 * n i.2 := by
ext x
simp [i, i0, i1, finsuppTensorFinsupp'_symm_single_eq_single_one_tmul]
simp_rw [← this, i, LinearMap.coe_comp, LinearEquiv.coe_coe, EquivLike.injective_comp] at H
exact ⟨H⟩
/-- The zero module is linearly disjoint with any other submodules. -/
theorem bot_left : (⊥ : Submodule R S).LinearDisjoint N :=
⟨Function.injective_of_subsingleton _⟩
/-- The zero module is linearly disjoint with any other submodules. -/
theorem bot_right : M.LinearDisjoint (⊥ : Submodule R S) :=
⟨Function.injective_of_subsingleton _⟩
/-- The image of `R` in `S` is linearly disjoint with any other submodules. -/
theorem one_left : (1 : Submodule R S).LinearDisjoint N := by
rw [linearDisjoint_iff, mulMap_one_left_eq]
exact N.injective_subtype.comp N.lTensorOne.injective
/-- The image of `R` in `S` is linearly disjoint with any other submodules. -/
theorem one_right : M.LinearDisjoint (1 : Submodule R S) := by
rw [linearDisjoint_iff, mulMap_one_right_eq]
exact M.injective_subtype.comp M.rTensorOne.injective
/-- If for any finitely generated submodules `M'` of `M`, `M'` and `N` are linearly disjoint,
then `M` and `N` themselves are linearly disjoint. -/
theorem of_linearDisjoint_fg_left
(H : ∀ M' : Submodule R S, M' ≤ M → M'.FG → M'.LinearDisjoint N) :
M.LinearDisjoint N := (linearDisjoint_iff _ _).2 fun x y hxy ↦ by
obtain ⟨M', hM, hFG, h⟩ :=
TensorProduct.exists_finite_submodule_left_of_finite' {x, y} (Set.toFinite _)
rw [Module.Finite.iff_fg] at hFG
obtain ⟨x', hx'⟩ := h (show x ∈ {x, y} by simp)
obtain ⟨y', hy'⟩ := h (show y ∈ {x, y} by simp)
rw [← hx', ← hy']; congr
exact (H M' hM hFG).injective (by simp [← mulMap_comp_rTensor _ hM, hx', hy', hxy])
/-- If for any finitely generated submodules `N'` of `N`, `M` and `N'` are linearly disjoint,
then `M` and `N` themselves are linearly disjoint. -/
theorem of_linearDisjoint_fg_right
(H : ∀ N' : Submodule R S, N' ≤ N → N'.FG → M.LinearDisjoint N') :
M.LinearDisjoint N := (linearDisjoint_iff _ _).2 fun x y hxy ↦ by
obtain ⟨N', hN, hFG, h⟩ :=
TensorProduct.exists_finite_submodule_right_of_finite' {x, y} (Set.toFinite _)
rw [Module.Finite.iff_fg] at hFG
obtain ⟨x', hx'⟩ := h (show x ∈ {x, y} by simp)
obtain ⟨y', hy'⟩ := h (show y ∈ {x, y} by simp)
rw [← hx', ← hy']; congr
exact (H N' hN hFG).injective (by simp [← mulMap_comp_lTensor _ hN, hx', hy', hxy])
/-- If for any finitely generated submodules `M'` and `N'` of `M` and `N`, respectively,
`M'` and `N'` are linearly disjoint, then `M` and `N` themselves are linearly disjoint. -/
theorem of_linearDisjoint_fg
(H : ∀ (M' N' : Submodule R S), M' ≤ M → N' ≤ N → M'.FG → N'.FG → M'.LinearDisjoint N') :
M.LinearDisjoint N :=
of_linearDisjoint_fg_left _ _ fun _ hM hM' ↦
of_linearDisjoint_fg_right _ _ fun _ hN hN' ↦ H _ _ hM hN hM' hN'
end LinearDisjoint
end Semiring
section CommSemiring
variable [CommSemiring R] [CommSemiring S] [Algebra R S]
variable {M N : Submodule R S}
/-- Linearly disjoint is symmetric in a commutative ring. -/
theorem LinearDisjoint.symm (H : M.LinearDisjoint N) : N.LinearDisjoint M :=
H.symm_of_commute fun _ _ ↦ mul_comm _ _
/-- Linearly disjoint is symmetric in a commutative ring. -/
theorem linearDisjoint_symm : M.LinearDisjoint N ↔ N.LinearDisjoint M :=
⟨LinearDisjoint.symm, LinearDisjoint.symm⟩
end CommSemiring
section Ring
namespace LinearDisjoint
variable [CommRing R] [Ring S] [Algebra R S]
variable (M N : Submodule R S)
variable {M N} in
/-- If `M` and `N` are linearly disjoint, if `N` is a flat `R`-module, then for any family of
`R`-linearly independent elements `{ m_i }` of `M`, they are also `N`-linearly independent,
in the sense that the `R`-linear map from `ι →₀ N` to `S` which maps `{ n_i }`
to the sum of `m_i * n_i` (`Submodule.mulLeftMap N m`) has trivial kernel. -/
theorem linearIndependent_left_of_flat (H : M.LinearDisjoint N) [Module.Flat R N]
{ι : Type*} {m : ι → M} (hm : LinearIndependent R m) : LinearMap.ker (mulLeftMap N m) = ⊥ := by
refine LinearMap.ker_eq_bot_of_injective ?_
classical simp_rw [mulLeftMap_eq_mulMap_comp, LinearMap.coe_comp, LinearEquiv.coe_coe,
← Function.comp.assoc, EquivLike.injective_comp]
rw [LinearIndependent, LinearMap.ker_eq_bot] at hm
exact H.injective.comp (Module.Flat.rTensor_preserves_injective_linearMap (M := N) _ hm)
/-- If `{ m_i }` is an `R`-basis of `M`, which is also `N`-linearly independent,
then `M` and `N` are linearly disjoint. -/
theorem of_basis_left {ι : Type*} (m : Basis ι R M)
(H : LinearMap.ker (mulLeftMap N m) = ⊥) : M.LinearDisjoint N := by
-- need this instance otherwise `LinearMap.ker_eq_bot` does not work
letI : AddCommGroup (ι →₀ N) := Finsupp.instAddCommGroup
exact of_basis_left' M N m (LinearMap.ker_eq_bot.1 H)
variable {M N} in
/-- If `M` and `N` are linearly disjoint, if `M` is a flat `R`-module, then for any family of
`R`-linearly independent elements `{ n_i }` of `N`, they are also `M`-linearly independent,
in the sense that the `R`-linear map from `ι →₀ M` to `S` which maps `{ m_i }`
to the sum of `m_i * n_i` (`Submodule.mulRightMap M n`) has trivial kernel. -/
theorem linearIndependent_right_of_flat (H : M.LinearDisjoint N) [Module.Flat R M]
{ι : Type*} {n : ι → N} (hn : LinearIndependent R n) : LinearMap.ker (mulRightMap M n) = ⊥ := by
refine LinearMap.ker_eq_bot_of_injective ?_
classical simp_rw [mulRightMap_eq_mulMap_comp, LinearMap.coe_comp, LinearEquiv.coe_coe,
← Function.comp.assoc, EquivLike.injective_comp]
rw [LinearIndependent, LinearMap.ker_eq_bot] at hn
exact H.injective.comp (Module.Flat.lTensor_preserves_injective_linearMap (M := M) _ hn)
/-- If `{ n_i }` is an `R`-basis of `N`, which is also `M`-linearly independent,
then `M` and `N` are linearly disjoint. -/
theorem of_basis_right {ι : Type*} (n : Basis ι R N)
(H : LinearMap.ker (mulRightMap M n) = ⊥) : M.LinearDisjoint N := by
-- need this instance otherwise `LinearMap.ker_eq_bot` does not work
letI : AddCommGroup (ι →₀ M) := Finsupp.instAddCommGroup
exact of_basis_right' M N n (LinearMap.ker_eq_bot.1 H)
variable {M N} in
/-- If `M` and `N` are linearly disjoint, if `M` is flat, then for any family of
`R`-linearly independent elements `{ m_i }` of `M`, and any family of
`R`-linearly independent elements `{ n_j }` of `N`, the family `{ m_i * n_j }` in `S` is
also `R`-linearly independent. -/
theorem linearIndependent_mul_of_flat_left (H : M.LinearDisjoint N) [Module.Flat R M]
{κ ι : Type*} {m : κ → M} {n : ι → N} (hm : LinearIndependent R m)
(hn : LinearIndependent R n) : LinearIndependent R fun (i : κ × ι) ↦ (m i.1).1 * (n i.2).1 := by
rw [LinearIndependent, LinearMap.ker_eq_bot] at hm hn ⊢
let i0 := (finsuppTensorFinsupp' R κ ι).symm
let i1 := LinearMap.rTensor (ι →₀ R) (Finsupp.total κ M R m)
let i2 := LinearMap.lTensor M (Finsupp.total ι N R n)
let i := mulMap M N ∘ₗ i2 ∘ₗ i1 ∘ₗ i0.toLinearMap
have h1 : Function.Injective i1 := Module.Flat.rTensor_preserves_injective_linearMap _ hm
have h2 : Function.Injective i2 := Module.Flat.lTensor_preserves_injective_linearMap _ hn
have h : Function.Injective i := H.injective.comp h2 |>.comp h1 |>.comp i0.injective
have : i = Finsupp.total (κ × ι) S R fun i ↦ (m i.1).1 * (n i.2).1 := by
ext x
simp [i, i0, i1, i2, finsuppTensorFinsupp'_symm_single_eq_single_one_tmul]
rwa [this] at h
variable {M N} in
/-- If `M` and `N` are linearly disjoint, if `N` is flat, then for any family of
`R`-linearly independent elements `{ m_i }` of `M`, and any family of
`R`-linearly independent elements `{ n_j }` of `N`, the family `{ m_i * n_j }` in `S` is
also `R`-linearly independent. -/
theorem linearIndependent_mul_of_flat_right (H : M.LinearDisjoint N) [Module.Flat R N]
{κ ι : Type*} {m : κ → M} {n : ι → N} (hm : LinearIndependent R m)
(hn : LinearIndependent R n) : LinearIndependent R fun (i : κ × ι) ↦ (m i.1).1 * (n i.2).1 := by
rw [LinearIndependent, LinearMap.ker_eq_bot] at hm hn ⊢
let i0 := (finsuppTensorFinsupp' R κ ι).symm
let i1 := LinearMap.lTensor (κ →₀ R) (Finsupp.total ι N R n)
let i2 := LinearMap.rTensor N (Finsupp.total κ M R m)
let i := mulMap M N ∘ₗ i2 ∘ₗ i1 ∘ₗ i0.toLinearMap
have h1 : Function.Injective i1 := Module.Flat.lTensor_preserves_injective_linearMap _ hn
have h2 : Function.Injective i2 := Module.Flat.rTensor_preserves_injective_linearMap _ hm
have h : Function.Injective i := H.injective.comp h2 |>.comp h1 |>.comp i0.injective
have : i = Finsupp.total (κ × ι) S R fun i ↦ (m i.1).1 * (n i.2).1 := by
ext x
simp [i, i0, i1, i2, finsuppTensorFinsupp'_symm_single_eq_single_one_tmul]
rwa [this] at h
variable {M N} in
/-- If `M` and `N` are linearly disjoint, if one of `M` and `N` is flat, then for any family of
`R`-linearly independent elements `{ m_i }` of `M`, and any family of
`R`-linearly independent elements `{ n_j }` of `N`, the family `{ m_i * n_j }` in `S` is
also `R`-linearly independent. -/
theorem linearIndependent_mul_of_flat (H : M.LinearDisjoint N)
(hf : Module.Flat R M ∨ Module.Flat R N)
{κ ι : Type*} {m : κ → M} {n : ι → N} (hm : LinearIndependent R m)
(hn : LinearIndependent R n) : LinearIndependent R fun (i : κ × ι) ↦ (m i.1).1 * (n i.2).1 := by
rcases hf with _ | _
· exact H.linearIndependent_mul_of_flat_left hm hn
· exact H.linearIndependent_mul_of_flat_right hm hn
/-- If `{ m_i }` is an `R`-basis of `M`, if `{ n_i }` is an `R`-basis of `N`,
such that the family `{ m_i * n_j }` in `S` is `R`-linearly independent,
then `M` and `N` are linearly disjoint. -/
theorem of_basis_mul {κ ι : Type*} (m : Basis κ R M) (n : Basis ι R N)
(H : LinearIndependent R fun (i : κ × ι) ↦ (m i.1).1 * (n i.2).1) : M.LinearDisjoint N := by
rw [LinearIndependent, LinearMap.ker_eq_bot] at H
exact of_basis_mul' M N m n H
variable {M N} in
/-- If `M` and `N` are linearly disjoint, if `N` is flat, then for any submodule `M'` of `M`,
`M'` and `N` are also linearly disjoint. -/
theorem of_le_left_of_flat (H : M.LinearDisjoint N) {M' : Submodule R S}
(h : M' ≤ M) [Module.Flat R N] : M'.LinearDisjoint N := by
let i := mulMap M N ∘ₗ (inclusion h).rTensor N
have hi : Function.Injective i := H.injective.comp <|
Module.Flat.rTensor_preserves_injective_linearMap _ <| inclusion_injective h
have : i = mulMap M' N := by ext; simp [i]
exact ⟨this ▸ hi⟩
variable {M N} in
/-- If `M` and `N` are linearly disjoint, if `M` is flat, then for any submodule `N'` of `N`,
`M` and `N'` are also linearly disjoint. -/
theorem of_le_right_of_flat (H : M.LinearDisjoint N) {N' : Submodule R S}
(h : N' ≤ N) [Module.Flat R M] : M.LinearDisjoint N' := by
let i := mulMap M N ∘ₗ (inclusion h).lTensor M
have hi : Function.Injective i := H.injective.comp <|
Module.Flat.lTensor_preserves_injective_linearMap _ <| inclusion_injective h
have : i = mulMap M N' := by ext; simp [i]
exact ⟨this ▸ hi⟩
variable {M N} in
/-- If `M` and `N` are linearly disjoint, `M'` and `N'` are submodules of `M` and `N`,
respectively, such that `N` and `M'` are flat, then `M'` and `N'` are also linearly disjoint. -/
theorem of_le_of_flat_right (H : M.LinearDisjoint N) {M' N' : Submodule R S}
(hm : M' ≤ M) (hn : N' ≤ N) [Module.Flat R N] [Module.Flat R M'] :
M'.LinearDisjoint N' := (H.of_le_left_of_flat hm).of_le_right_of_flat hn
variable {M N} in
/-- If `M` and `N` are linearly disjoint, `M'` and `N'` are submodules of `M` and `N`,
respectively, such that `M` and `N'` are flat, then `M'` and `N'` are also linearly disjoint. -/
theorem of_le_of_flat_left (H : M.LinearDisjoint N) {M' N' : Submodule R S}
(hm : M' ≤ M) (hn : N' ≤ N) [Module.Flat R M] [Module.Flat R N'] :
M'.LinearDisjoint N' := (H.of_le_right_of_flat hn).of_le_left_of_flat hm
/-- If `N` is flat, `M` is contained in `i(R)`, where `i : R → S` is the structure map,
then `M` and `N` are linearly disjoint. -/
theorem of_left_le_one_of_flat (h : M ≤ 1) [Module.Flat R N] :
M.LinearDisjoint N := (one_left N).of_le_left_of_flat h
/-- If `M` is flat, `N` is contained in `i(R)`, where `i : R → S` is the structure map,
then `M` and `N` are linearly disjoint. -/
theorem of_right_le_one_of_flat (h : N ≤ 1) [Module.Flat R M] :
M.LinearDisjoint N := (one_right M).of_le_right_of_flat h
section not_linearIndependent_pair
variable {M N}
variable (H : M.LinearDisjoint N)
section
variable [Nontrivial R]
/-- If `M` and `N` are linearly disjoint, if `M` is flat, then any two commutative
elements of `↥(M ⊓ N)` are not `R`-linearly independent (namely, their span is not `R ^ 2`). -/
theorem not_linearIndependent_pair_of_commute_of_flat_left [Module.Flat R M]
(a b : ↥(M ⊓ N)) (hc : Commute a.1 b.1) : ¬LinearIndependent R ![a, b] := fun h ↦ by
let n : Fin 2 → N := (inclusion inf_le_right) ∘ ![a, b]
have hn : LinearIndependent R n := h.map' _ (ker_inclusion _ _ _)
-- need this instance otherwise it only has semigroup structure
letI : AddCommGroup (Fin 2 →₀ M) := Finsupp.instAddCommGroup
let m : Fin 2 →₀ M := .single 0 ⟨b.1, b.2.1⟩ - .single 1 ⟨a.1, a.2.1⟩
have hm : mulRightMap M n m = 0 := by simp [m, n, show _ * _ = _ * _ from hc]
rw [← LinearMap.mem_ker, H.linearIndependent_right_of_flat hn, mem_bot] at hm
simp only [Fin.isValue, sub_eq_zero, Finsupp.single_eq_single_iff, zero_ne_one, Subtype.mk.injEq,
SetLike.coe_eq_coe, false_and, AddSubmonoid.mk_eq_zero, ZeroMemClass.coe_eq_zero,
false_or, m] at hm
exact h.ne_zero 0 hm.2
/-- If `M` and `N` are linearly disjoint, if `N` is flat, then any two commutative
elements of `↥(M ⊓ N)` are not `R`-linearly independent (namely, their span is not `R ^ 2`). -/
theorem not_linearIndependent_pair_of_commute_of_flat_right [Module.Flat R N]
(a b : ↥(M ⊓ N)) (hc : Commute a.1 b.1) : ¬LinearIndependent R ![a, b] := fun h ↦ by
let m : Fin 2 → M := (inclusion inf_le_left) ∘ ![a, b]
have hm : LinearIndependent R m := h.map' _ (ker_inclusion _ _ _)
-- need this instance otherwise it only has semigroup structure
letI : AddCommGroup (Fin 2 →₀ N) := Finsupp.instAddCommGroup
let n : Fin 2 →₀ N := .single 0 ⟨b.1, b.2.2⟩ - .single 1 ⟨a.1, a.2.2⟩
have hn : mulLeftMap N m n = 0 := by simp [m, n, show _ * _ = _ * _ from hc]
rw [← LinearMap.mem_ker, H.linearIndependent_left_of_flat hm, mem_bot] at hn
simp only [Fin.isValue, sub_eq_zero, Finsupp.single_eq_single_iff, zero_ne_one, Subtype.mk.injEq,
SetLike.coe_eq_coe, false_and, AddSubmonoid.mk_eq_zero, ZeroMemClass.coe_eq_zero,
false_or, n] at hn
exact h.ne_zero 0 hn.2
/-- If `M` and `N` are linearly disjoint, if one of `M` and `N` is flat, then any two commutative
elements of `↥(M ⊓ N)` are not `R`-linearly independent (namely, their span is not `R ^ 2`). -/
theorem not_linearIndependent_pair_of_commute_of_flat (hf : Module.Flat R M ∨ Module.Flat R N)
(a b : ↥(M ⊓ N)) (hc : Commute a.1 b.1) : ¬LinearIndependent R ![a, b] := by
rcases hf with _ | _
· exact H.not_linearIndependent_pair_of_commute_of_flat_left a b hc
· exact H.not_linearIndependent_pair_of_commute_of_flat_right a b hc
end
/-- If `M` and `N` are linearly disjoint, if one of `M` and `N` is flat,
if any two elements of `↥(M ⊓ N)` are commutative, then the rank of `↥(M ⊓ N)` is at most one. -/
theorem rank_inf_le_one_of_commute_of_flat (hf : Module.Flat R M ∨ Module.Flat R N)
(hc : ∀ (m n : ↥(M ⊓ N)), Commute m.1 n.1) : Module.rank R ↥(M ⊓ N) ≤ 1 := by
nontriviality R
refine rank_le fun s h ↦ ?_
by_contra hs
rw [not_le, ← Fintype.card_coe, Fintype.one_lt_card_iff_nontrivial] at hs
obtain ⟨a, b, hab⟩ := hs.exists_pair_ne
refine H.not_linearIndependent_pair_of_commute_of_flat hf a.1 b.1 (hc a.1 b.1) ?_
have := h.comp ![a, b] fun i j hij ↦ by
fin_cases i <;> fin_cases j
· rfl
· simp [hab] at hij
· simp [hab.symm] at hij
· rfl
convert this
ext i
fin_cases i <;> simp
/-- If `M` and `N` are linearly disjoint, if `M` is flat,
if any two elements of `↥(M ⊓ N)` are commutative, then the rank of `↥(M ⊓ N)` is at most one. -/
theorem rank_inf_le_one_of_commute_of_flat_left [Module.Flat R M]
(hc : ∀ (m n : ↥(M ⊓ N)), Commute m.1 n.1) : Module.rank R ↥(M ⊓ N) ≤ 1 :=
H.rank_inf_le_one_of_commute_of_flat (Or.inl ‹_›) hc
/-- If `M` and `N` are linearly disjoint, if `N` is flat,
if any two elements of `↥(M ⊓ N)` are commutative, then the rank of `↥(M ⊓ N)` is at most one. -/
theorem rank_inf_le_one_of_commute_of_flat_right [Module.Flat R N]
(hc : ∀ (m n : ↥(M ⊓ N)), Commute m.1 n.1) : Module.rank R ↥(M ⊓ N) ≤ 1 :=
H.rank_inf_le_one_of_commute_of_flat (Or.inr ‹_›) hc
/-- If `M` and itself are linearly disjoint, if `M` is flat,
if any two elements of `M` are commutative, then the rank of `M` is at most one. -/
theorem rank_le_one_of_commute_of_flat_of_self (H : M.LinearDisjoint M) [Module.Flat R M]
(hc : ∀ (m n : M), Commute m.1 n.1) : Module.rank R M ≤ 1 := by
rw [← inf_of_le_left (le_refl M)] at hc ⊢
exact H.rank_inf_le_one_of_commute_of_flat_left hc
end not_linearIndependent_pair
end LinearDisjoint
end Ring
section CommRing
namespace LinearDisjoint
variable [CommRing R] [CommRing S] [Algebra R S]
variable (M N : Submodule R S)
section not_linearIndependent_pair
variable {M N}
variable (H : M.LinearDisjoint N)
section
variable [Nontrivial R]
/-- The `Submodule.LinearDisjoint.not_linearIndependent_pair_of_commute_of_flat_left`
for commutative rings. -/
theorem not_linearIndependent_pair_of_flat_left [Module.Flat R M]
(a b : ↥(M ⊓ N)) : ¬LinearIndependent R ![a, b] :=
H.not_linearIndependent_pair_of_commute_of_flat_left a b (mul_comm _ _)
/-- The `Submodule.LinearDisjoint.not_linearIndependent_pair_of_commute_of_flat_right`
for commutative rings. -/
theorem not_linearIndependent_pair_of_flat_right [Module.Flat R N]
(a b : ↥(M ⊓ N)) : ¬LinearIndependent R ![a, b] :=
H.not_linearIndependent_pair_of_commute_of_flat_right a b (mul_comm _ _)
/-- The `Submodule.LinearDisjoint.not_linearIndependent_pair_of_commute_of_flat`
for commutative rings. -/
theorem not_linearIndependent_pair_of_flat (hf : Module.Flat R M ∨ Module.Flat R N)
(a b : ↥(M ⊓ N)) : ¬LinearIndependent R ![a, b] :=
H.not_linearIndependent_pair_of_commute_of_flat hf a b (mul_comm _ _)
end
/-- The `Submodule.LinearDisjoint.rank_inf_le_one_of_commute_of_flat`
for commutative rings. -/
theorem rank_inf_le_one_of_flat (hf : Module.Flat R M ∨ Module.Flat R N) :
Module.rank R ↥(M ⊓ N) ≤ 1 :=
H.rank_inf_le_one_of_commute_of_flat hf fun _ _ ↦ mul_comm _ _
/-- The `Submodule.LinearDisjoint.rank_inf_le_one_of_commute_of_flat_left`
for commutative rings. -/
theorem rank_inf_le_one_of_flat_left [Module.Flat R M] : Module.rank R ↥(M ⊓ N) ≤ 1 :=
H.rank_inf_le_one_of_commute_of_flat_left fun _ _ ↦ mul_comm _ _
/-- The `Submodule.LinearDisjoint.rank_inf_le_one_of_commute_of_flat_right`
for commutative rings. -/
theorem rank_inf_le_one_of_flat_right [Module.Flat R N] : Module.rank R ↥(M ⊓ N) ≤ 1 :=
H.rank_inf_le_one_of_commute_of_flat_right fun _ _ ↦ mul_comm _ _
/-- The `Submodule.LinearDisjoint.rank_le_one_of_commute_of_flat_of_self`
for commutative rings. -/
theorem rank_le_one_of_flat_of_self (H : M.LinearDisjoint M) [Module.Flat R M] :
Module.rank R M ≤ 1 :=
H.rank_le_one_of_commute_of_flat_of_self fun _ _ ↦ mul_comm _ _
end not_linearIndependent_pair
end LinearDisjoint
end CommRing
end Submodule
|
LinearAlgebra\LinearIndependent.lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Alexander Bentkamp, Anne Baanen
-/
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.LinearAlgebra.Finsupp
import Mathlib.LinearAlgebra.Prod
import Mathlib.SetTheory.Cardinal.Basic
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.LinearCombination
import Mathlib.Lean.Expr.ExtraRecognizers
import Mathlib.Data.Set.Subsingleton
import Mathlib.Tactic.Abel
/-!
# 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 `ker (Finsupp.total ι M R v) = ⊥`. Here `Finsupp.total` is the
linear map sending a function `f : ι →₀ R` with finite support to the linear combination of vectors
from `v` with these coefficients. Then we prove that several other statements are equivalent to this
one, including injectivity of `Finsupp.total ι M 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.
* `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.
## Main statements
We prove several specialized tests for linear independence of families of vectors and of sets of
vectors.
* `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 ι`;
* `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_option`, `linearIndependent_sum`, `linearIndependent_fin_cons`,
`linearIndependent_fin_succ`: type-specific tests for linear independence of families of vector
fields;
* `linearIndependent_insert`, `linearIndependent_union`, `linearIndependent_pair`,
`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.
We also prove that, when working over a division ring,
any family of vectors includes a linear independent subfamily spanning the same subspace.
## Implementation notes
We use families instead of sets because it allows us to say that two identical vectors are linearly
dependent.
If you want to use sets, use the family `(fun x ↦ x : s → M)` given a set `s : Set M`. The lemmas
`LinearIndependent.to_subtype_range` and `LinearIndependent.of_subtype_range` connect those two
worlds.
## Tags
linearly dependent, linear dependence, linearly independent, linear independence
-/
noncomputable section
open Function Set Submodule
open Cardinal
universe u' u
variable {ι : Type u'} {ι' : Type*} {R : Type*} {K : Type*}
variable {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*}
section Module
variable {v : ι → M}
variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M'']
variable [Module R M] [Module R M'] [Module R M'']
variable {a b : R} {x y : M}
variable (R) (v)
/-- `LinearIndependent R v` states the family of vectors `v` is linearly independent over `R`. -/
def LinearIndependent : Prop :=
LinearMap.ker (Finsupp.total ι M 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. -/
@[delab app.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
variable {R} {v}
theorem linearIndependent_iff :
LinearIndependent R v ↔ ∀ l, Finsupp.total ι M R v l = 0 → l = 0 := by
simp [LinearIndependent, LinearMap.ker_eq_bot']
theorem linearIndependent_iff' :
LinearIndependent R v ↔
∀ s : Finset ι, ∀ g : ι → R, ∑ i ∈ s, g i • v i = 0 → ∀ i ∈ s, g i = 0 :=
linearIndependent_iff.trans
⟨fun hf s g hg i his =>
have h :=
hf (∑ i ∈ s, Finsupp.single i (g i)) <| by
simpa only [map_sum, Finsupp.total_single] using hg
calc
g i = (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single i (g i)) := by
{ rw [Finsupp.lapply_apply, Finsupp.single_eq_same] }
_ = ∑ j ∈ s, (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single j (g 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 (g j)) i := (map_sum ..).symm
_ = 0 := DFunLike.ext_iff.1 h i,
fun hf l hl =>
Finsupp.ext fun i =>
_root_.by_contradiction fun hni => hni <| hf _ _ hl _ <| Finsupp.mem_support_iff.2 hni⟩
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 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]
/-- 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]
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
theorem linearIndependent_empty_type [IsEmpty ι] : LinearIndependent R v :=
linearIndependent_iff.mpr fun v _hv => Subsingleton.elim v 0
theorem LinearIndependent.ne_zero [Nontrivial R] (i : ι) (hv : LinearIndependent R v) : v i ≠ 0 :=
fun h =>
zero_ne_one' R <|
Eq.symm
(by
suffices (Finsupp.single i 1 : ι →₀ R) i = 0 by simpa
rw [linearIndependent_iff.1 hv (Finsupp.single i 1)]
· simp
· simp [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
have := linearIndependent_iff'.1 h Finset.univ ![s, t]
simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, h',
Finset.mem_univ, forall_true_left] at this
exact ⟨this 0, this 1⟩
/-- Also see `LinearIndependent.pair_iff'` for a simpler version over fields. -/
lemma LinearIndependent.pair_iff {x y : M} :
LinearIndependent R ![x, y] ↔ ∀ (s t : R), s • x + t • y = 0 → s = 0 ∧ t = 0 := by
refine ⟨fun h s t hst ↦ h.eq_zero_of_pair hst, fun h ↦ ?_⟩
apply Fintype.linearIndependent_iff.2
intro g hg
simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons] at hg
intro i
fin_cases i
exacts [(h _ _ hg).1, (h _ _ hg).2]
/-- 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
rw [linearIndependent_iff, Finsupp.total_comp]
intro l hl
have h_map_domain : ∀ x, (Finsupp.mapDomain f l) (f x) = 0 := by
rw [linearIndependent_iff.1 h (Finsupp.mapDomain f l) hl]; simp
ext x
convert h_map_domain x
rw [Finsupp.mapDomain_apply hf]
/-- 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 g hg i hi ↦
Fintype.linearIndependent_iff.1 (H s) (g ∘ Subtype.val)
(hg ▸ Finset.sum_attach s fun j ↦ g j • v j) ⟨i, hi⟩⟩
theorem LinearIndependent.coe_range (i : LinearIndependent R v) :
LinearIndependent R ((↑) : range v → M) := by simpa using i.comp _ (rangeSplitting_injective v)
/-- 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) := by
rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_total,
map_inf_eq_map_inf_comap, map_le_iff_le_comap, comap_bot, Finsupp.supported_univ, top_inf_eq]
at hf_inj
unfold LinearIndependent at hv ⊢
rw [hv, le_bot_iff] at hf_inj
haveI : Inhabited M := ⟨0⟩
rw [Finsupp.total_comp, Finsupp.lmapDomain_total _ _ f, LinearMap.ker_comp,
hf_inj]
exact fun _ => rfl
/-- 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` -/
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.total_comp, Finsupp.lmapDomain_total R _ f (fun _ ↦ rfl),
LinearMap.ker_comp] at hv
rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_total,
map_inf_eq_map_inf_comap, hv, inf_bot_eq, map_bot]
/-- 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 [hf_inj]
/-- 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' : Type*} {M' : Type*}
[Semiring R'] [AddCommMonoid 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' : Type*} {M' : Type*}
[Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v)
(i : ZeroHom 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) := 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', i.map_zero] at h
rw [hc (i' r) m, hi']
/-- 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 :=
linearIndependent_iff'.2 fun s g hg i his =>
have : (∑ i ∈ s, g i • f (v i)) = 0 := by
simp_rw [← map_smul, ← map_sum, hg, f.map_zero]
linearIndependent_iff'.1 hfv s g this i his
/-- 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 :=
⟨fun h => h.of_comp f, fun h => h.map <| by simp only [hf_inj, disjoint_bot_right]⟩
@[nontriviality]
theorem linearIndependent_of_subsingleton [Subsingleton R] : LinearIndependent R v :=
linearIndependent_iff.2 fun _l _hl => Subsingleton.elim _ _
theorem linearIndependent_equiv (e : ι ≃ ι') {f : ι' → M} :
LinearIndependent R (f ∘ e) ↔ LinearIndependent R f :=
⟨fun h => Function.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 linearIndependent_subtype_range {ι} {f : ι → M} (hf : Injective f) :
LinearIndependent R ((↑) : range f → M) ↔ LinearIndependent R f :=
Iff.symm <| linearIndependent_equiv' (Equiv.ofInjective f hf) rfl
alias ⟨LinearIndependent.of_subtype_range, _⟩ := linearIndependent_subtype_range
theorem linearIndependent_image {ι} {s : Set ι} {f : ι → M} (hf : Set.InjOn f s) :
(LinearIndependent R fun x : s => f x) ↔ LinearIndependent R fun x : f '' s => (x : M) :=
linearIndependent_equiv' (Equiv.Set.imageOfInjOn _ _ hf) rfl
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
/-- 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
/-- A set of linearly independent vectors in a module `M` over a semiring `K` is also linearly
independent over a subring `R` of `K`.
The implementation uses minimal assumptions about the relationship between `R`, `K` and `M`.
The version where `K` is an `R`-algebra is `LinearIndependent.restrict_scalars_algebras`.
-/
theorem LinearIndependent.restrict_scalars [Semiring K] [SMulWithZero R K] [Module K M]
[IsScalarTower R K M] (hinj : Function.Injective fun r : R => r • (1 : K))
(li : LinearIndependent K v) : LinearIndependent R v := by
refine linearIndependent_iff'.mpr fun s g hg i hi => hinj ?_
dsimp only; rw [zero_smul]
refine (linearIndependent_iff'.mp li : _) _ (g · • (1 : K)) ?_ i hi
simp_rw [smul_assoc, one_smul]
exact hg
/-- 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) := by
let f : t.map (Embedding.subtype s) → s := fun x =>
⟨x.1, by
obtain ⟨x, h⟩ := x
rw [Finset.mem_map] at h
obtain ⟨a, _ha, rfl⟩ := h
simp only [Subtype.coe_prop, Embedding.coe_subtype]⟩
convert LinearIndependent.comp li f ?_
rintro ⟨x, hx⟩ ⟨y, hy⟩
rw [Finset.mem_map] at hx hy
obtain ⟨a, _ha, rfl⟩ := hx
obtain ⟨b, _hb, rfl⟩ := hy
simp only [f, imp_self, Subtype.mk_eq_mk]
/-- If every finite set of linearly independent vectors has cardinality at most `n`,
then the same is true for arbitrary sets of linearly independent vectors.
-/
theorem linearIndependent_bounded_of_finset_linearIndependent_bounded {n : ℕ}
(H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) :
∀ s : Set M, LinearIndependent R ((↑) : s → M) → #s ≤ n := by
intro s li
apply Cardinal.card_le_of
intro t
rw [← Finset.card_map (Embedding.subtype s)]
apply H
apply linearIndependent_finset_map_embedding_subtype _ li
section Subtype
/-! The following lemmas use the subtype defined by a set in `M` as the index set `ι`. -/
theorem linearIndependent_comp_subtype {s : Set ι} :
LinearIndependent R (v ∘ (↑) : s → M) ↔
∀ l ∈ Finsupp.supported R R s, (Finsupp.total ι M R v) l = 0 → l = 0 := by
simp only [linearIndependent_iff, (· ∘ ·), Finsupp.mem_supported, Finsupp.total_apply,
Set.subset_def, Finset.mem_coe]
constructor
· intro h l hl₁ hl₂
have := h (l.subtypeDomain s) ((Finsupp.sum_subtypeDomain_index hl₁).trans hl₂)
exact (Finsupp.subtypeDomain_eq_zero_iff hl₁).1 this
· intro h l hl
refine Finsupp.embDomain_eq_zero.1 (h (l.embDomain <| Function.Embedding.subtype s) ?_ ?_)
· suffices ∀ i hi, ¬l ⟨i, hi⟩ = 0 → i ∈ s by simpa
intros
assumption
· rwa [Finsupp.embDomain_eq_mapDomain, Finsupp.sum_mapDomain_index]
exacts [fun _ => zero_smul _ _, fun _ _ _ => add_smul _ _ _]
theorem linearDependent_comp_subtype' {s : Set ι} :
¬LinearIndependent R (v ∘ (↑) : s → M) ↔
∃ f : ι →₀ R, f ∈ Finsupp.supported R R s ∧ Finsupp.total ι M R v f = 0 ∧ f ≠ 0 := by
simp [linearIndependent_comp_subtype, and_left_comm]
/-- A version of `linearDependent_comp_subtype'` with `Finsupp.total` unfolded. -/
theorem linearDependent_comp_subtype {s : Set ι} :
¬LinearIndependent R (v ∘ (↑) : s → M) ↔
∃ f : ι →₀ R, f ∈ Finsupp.supported R R s ∧ ∑ i ∈ f.support, f i • v i = 0 ∧ f ≠ 0 :=
linearDependent_comp_subtype'
theorem linearIndependent_subtype {s : Set M} :
LinearIndependent R (fun x => x : s → M) ↔
∀ l ∈ Finsupp.supported R R s, (Finsupp.total M M R id) l = 0 → l = 0 := by
apply linearIndependent_comp_subtype (v := id)
theorem linearIndependent_comp_subtype_disjoint {s : Set ι} :
LinearIndependent R (v ∘ (↑) : s → M) ↔
Disjoint (Finsupp.supported R R s) (LinearMap.ker <| Finsupp.total ι M R v) := by
rw [linearIndependent_comp_subtype, LinearMap.disjoint_ker]
theorem linearIndependent_subtype_disjoint {s : Set M} :
LinearIndependent R (fun x => x : s → M) ↔
Disjoint (Finsupp.supported R R s) (LinearMap.ker <| Finsupp.total M M R id) := by
apply linearIndependent_comp_subtype_disjoint (v := id)
theorem linearIndependent_iff_totalOn {s : Set M} :
LinearIndependent R (fun x => x : s → M) ↔
(LinearMap.ker <| Finsupp.totalOn M M R id s) = ⊥ := by
rw [Finsupp.totalOn, LinearMap.ker, LinearMap.comap_codRestrict, Submodule.map_bot, comap_bot,
LinearMap.ker_comp, linearIndependent_subtype_disjoint, disjoint_iff_inf_le, ←
map_comap_subtype, map_le_iff_le_comap, comap_bot, ker_subtype, le_bot_iff]
theorem LinearIndependent.restrict_of_comp_subtype {s : Set ι}
(hs : LinearIndependent R (v ∘ (↑) : s → M)) : LinearIndependent R (s.restrict v) :=
hs
variable (R M)
theorem linearIndependent_empty : LinearIndependent R (fun x => x : (∅ : Set M) → M) := by
simp [linearIndependent_subtype_disjoint]
variable {R M}
theorem LinearIndependent.mono {t s : Set M} (h : t ⊆ s) :
LinearIndependent R (fun x => x : s → M) → LinearIndependent R (fun x => x : t → M) := by
simp only [linearIndependent_subtype_disjoint]
exact Disjoint.mono_left (Finsupp.supported_mono h)
theorem linearIndependent_of_finite (s : Set M)
(H : ∀ t ⊆ s, Set.Finite t → LinearIndependent R (fun x => x : t → M)) :
LinearIndependent R (fun x => x : s → M) :=
linearIndependent_subtype.2 fun l hl =>
linearIndependent_subtype.1 (H _ hl (Finset.finite_toSet _)) l (Subset.refl _)
theorem linearIndependent_iUnion_of_directed {η : Type*} {s : η → Set M} (hs : Directed (· ⊆ ·) s)
(h : ∀ i, LinearIndependent R (fun x => x : s i → M)) :
LinearIndependent R (fun x => x : (⋃ i, s i) → M) := by
by_cases hη : Nonempty η
· refine linearIndependent_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 (linearIndependent_empty R M).mono (t := iUnion (s ·)) ?_
rintro _ ⟨_, ⟨i, _⟩, _⟩
exact hη ⟨i⟩
theorem linearIndependent_sUnion_of_directed {s : Set (Set M)} (hs : DirectedOn (· ⊆ ·) s)
(h : ∀ a ∈ s, LinearIndependent R ((↑) : ((a : Set M) : Type _) → M)) :
LinearIndependent R (fun x => x : ⋃₀ s → M) := by
rw [sUnion_eq_iUnion]
exact linearIndependent_iUnion_of_directed hs.directed_val (by simpa using h)
theorem linearIndependent_biUnion_of_directed {η} {s : Set η} {t : η → Set M}
(hs : DirectedOn (t ⁻¹'o (· ⊆ ·)) s) (h : ∀ a ∈ s, LinearIndependent R (fun x => x : t a → M)) :
LinearIndependent R (fun x => x : (⋃ a ∈ s, t a) → M) := by
rw [biUnion_eq_iUnion]
exact
linearIndependent_iUnion_of_directed (directed_comp.2 <| hs.directed_val) (by simpa using h)
end Subtype
end Module
/-! ### Properties which require `Ring R` -/
section Module
variable {v : ι → M}
variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M'']
variable [Module R M] [Module R M'] [Module R M'']
variable {a b : R} {x y : M}
theorem linearIndependent_iff_injective_total :
LinearIndependent R v ↔ Function.Injective (Finsupp.total ι M R v) :=
linearIndependent_iff.trans
(injective_iff_map_eq_zero (Finsupp.total ι M R v).toAddMonoidHom).symm
alias ⟨LinearIndependent.injective_total, _⟩ := linearIndependent_iff_injective_total
theorem LinearIndependent.injective [Nontrivial R] (hv : LinearIndependent R v) : Injective v := by
intro i j hij
let l : ι →₀ R := Finsupp.single i (1 : R) - Finsupp.single j 1
have h_total : Finsupp.total ι M R v l = 0 := by
simp_rw [l, LinearMap.map_sub, Finsupp.total_apply]
simp [hij]
have h_single_eq : Finsupp.single i (1 : R) = Finsupp.single j 1 := by
rw [linearIndependent_iff] at hv
simp [eq_add_of_sub_eq' (hv l h_total)]
simpa [Finsupp.single_eq_single_iff] using h_single_eq
theorem LinearIndependent.to_subtype_range {ι} {f : ι → M} (hf : LinearIndependent R f) :
LinearIndependent R ((↑) : range f → M) := by
nontriviality R
exact (linearIndependent_subtype_range hf.injective).2 hf
theorem LinearIndependent.to_subtype_range' {ι} {f : ι → M} (hf : LinearIndependent R f) {t}
(ht : range f = t) : LinearIndependent R ((↑) : t → M) :=
ht ▸ hf.to_subtype_range
theorem LinearIndependent.image_of_comp {ι ι'} (s : Set ι) (f : ι → ι') (g : ι' → M)
(hs : LinearIndependent R fun x : s => g (f x)) :
LinearIndependent R fun x : f '' s => g x := 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 LinearIndependent.image {ι} {s : Set ι} {f : ι → M}
(hs : LinearIndependent R fun x : s => f x) :
LinearIndependent R fun x : f '' s => (x : M) := by
convert LinearIndependent.image_of_comp s f id hs
theorem LinearIndependent.group_smul {G : Type*} [hG : Group G] [DistribMulAction G R]
[DistribMulAction 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 hgs hsum i
refine (smul_eq_zero_iff_eq (w i)).1 ?_
refine hv s (fun i => w i • g i) (fun i hi => ?_) ?_ i
· dsimp only
exact (hgs i hi).symm ▸ smul_zero _
· rw [← hsum, Finset.sum_congr rfl _]
intros
dsimp
rw [smul_assoc, smul_comm]
-- 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 hgs hsum i
rw [← (w i).mul_left_eq_zero]
refine hv s (fun i => g i • (w i : R)) (fun i hi => ?_) ?_ i
· dsimp only
exact (hgs i hi).symm ▸ zero_smul _ _
· rw [← hsum, Finset.sum_congr rfl _]
intros
erw [Pi.smul_apply, smul_assoc]
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' := by
have : (s - s') • x + (t - t') • y = 0 := by
rw [← sub_eq_zero_of_eq h', ← sub_eq_zero]
simp only [sub_smul]
abel
simpa [sub_eq_zero] using h.eq_zero_of_pair this
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')
/-- If two vectors `x` and `y` are linearly independent, so are their linear combinations
`a x + b y` and `c x + d y` provided the determinant `a * d - b * c` is nonzero. -/
lemma LinearIndependent.linear_combination_pair_of_det_ne_zero {R M : Type*} [CommRing R]
[NoZeroDivisors R] [AddCommGroup M] [Module R M]
{x y : M} (h : LinearIndependent R ![x, y])
{a b c d : R} (h' : a * d - b * c ≠ 0) :
LinearIndependent R ![a • x + b • y, c • x + d • y] := by
apply LinearIndependent.pair_iff.2 (fun s t hst ↦ ?_)
have H : (s * a + t * c) • x + (s * b + t * d) • y = 0 := by
convert hst using 1
simp only [_root_.add_smul, smul_add, smul_smul]
abel
have I1 : s * a + t * c = 0 := (h.eq_zero_of_pair H).1
have I2 : s * b + t * d = 0 := (h.eq_zero_of_pair H).2
have J1 : (a * d - b * c) * s = 0 := by linear_combination d * I1 - c * I2
have J2 : (a * d - b * c) * t = 0 := by linear_combination -b * I1 + a * I2
exact ⟨by simpa [h'] using mul_eq_zero.1 J1, by simpa [h'] using mul_eq_zero.1 J2⟩
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} [Ring R] [Nontrivial R] {M : Type v}
[AddCommGroup 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'.coe_range (range_comp_subset_range _ _)
rw [range_comp, ← image_univ (f := w)] at p
exact range_iff_surjective.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
/-- Linear independent families are injective, even if you multiply either side. -/
theorem LinearIndependent.eq_of_smul_apply_eq_smul_apply {M : Type*} [AddCommGroup 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
let l : ι →₀ R := Finsupp.single i c - Finsupp.single j d
have h_total : Finsupp.total ι M R v l = 0 := by
simp_rw [l, LinearMap.map_sub, Finsupp.total_apply]
simp [h]
have h_single_eq : Finsupp.single i c = Finsupp.single j d := by
rw [linearIndependent_iff] at li
simp [eq_add_of_sub_eq' (li l h_total)]
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_total]
rintro _ ⟨l₁, hl₁, rfl⟩ ⟨l₂, hl₂, H⟩
rw [hv.injective_total.eq_iff] at H; subst l₂
have : l₁ = 0 := Submodule.disjoint_def.mp (Finsupp.disjoint_supported_supported hs) _ hl₁ hl₂
simp [this]
theorem LinearIndependent.not_mem_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
theorem LinearIndependent.total_ne_of_not_mem_support [Nontrivial R] (hv : LinearIndependent R v)
{x : ι} (f : ι →₀ R) (h : x ∉ f.support) : Finsupp.total ι M R v f ≠ v x := by
replace h : x ∉ (f.support : Set ι) := h
have p := hv.not_mem_span_image h
intro w
rw [← w] at p
rw [Finsupp.span_image_eq_map_total] at p
simp only [not_exists, not_and, mem_map] at p -- Porting note: `mem_map` isn't currently triggered
exact p f (f.mem_supported_support R) rfl
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, ?_⟩
refine h.disjoint_span_image ?_
-- Porting note: `isCompl_range_inl_range_inr.1` timeouts.
exact IsCompl.disjoint isCompl_range_inl_range_inr
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]
· -- Porting note: Here was one `exact`, but timeouted.
refine Finset.disjoint_filter.2 fun x _ hx =>
disjoint_left.1 ?_ hx
exact IsCompl.disjoint isCompl_range_inl_range_inr
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⟩)
cases' 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 LinearIndependent.union {s t : Set M} (hs : LinearIndependent R (fun x => x : s → M))
(ht : LinearIndependent R (fun x => x : t → M)) (hst : Disjoint (span R s) (span R t)) :
LinearIndependent R (fun x => x : ↥(s ∪ t) → M) :=
(hs.sum_type ht <| by simpa).to_subtype_range' <| by simp
theorem linearIndependent_iUnion_finite_subtype {ι : Type*} {f : ι → Set M}
(hl : ∀ i, LinearIndependent R (fun x => x : f i → M))
(hd : ∀ i, ∀ t : Set ι, t.Finite → i ∉ t → Disjoint (span R (f i)) (⨆ i ∈ t, span R (f i))) :
LinearIndependent R (fun x => x : (⋃ i, f i) → M) := by
classical
rw [iUnion_eq_iUnion_finset f]
apply linearIndependent_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 i s his ih
· refine (linearIndependent_empty R M).mono ?_
simp
· rw [Finset.set_biUnion_insert]
refine (hl _).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_subtype_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 linearIndependent_iUnion_finite_subtype (fun j => (hindep j).to_subtype_range) hd
end Subtype
section repr
variable (hv : LinearIndependent R v)
/-- Canonical isomorphism between linear combinations and the span of linearly independent vectors.
-/
@[simps (config := { rhsMd := default }) symm_apply]
def LinearIndependent.totalEquiv (hv : LinearIndependent R v) :
(ι →₀ R) ≃ₗ[R] span R (range v) := by
apply LinearEquiv.ofBijective (LinearMap.codRestrict (span R (range v)) (Finsupp.total ι M R v) _)
constructor
· rw [← LinearMap.ker_eq_bot, LinearMap.ker_codRestrict]
· apply hv
· intro l
rw [← Finsupp.range_total]
rw [LinearMap.mem_range]
apply mem_range_self l
· rw [← LinearMap.range_eq_top, LinearMap.range_eq_map, LinearMap.map_codRestrict, ←
LinearMap.range_le_iff_comap, range_subtype, Submodule.map_top]
rw [Finsupp.range_total]
-- Porting note: The original theorem generated by `simps` was
-- different from the theorem on Lean 3, and not simp-normal form.
@[simp]
theorem LinearIndependent.totalEquiv_apply_coe (hv : LinearIndependent R v) (l : ι →₀ R) :
hv.totalEquiv l = Finsupp.total ι M R v l := rfl
/-- 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.total_equiv`. -/
def LinearIndependent.repr (hv : LinearIndependent R v) : span R (range v) →ₗ[R] ι →₀ R :=
hv.totalEquiv.symm
@[simp]
theorem LinearIndependent.total_repr (x) : Finsupp.total ι M R v (hv.repr x) = x :=
Subtype.ext_iff.1 (LinearEquiv.apply_symm_apply hv.totalEquiv x)
theorem LinearIndependent.total_comp_repr :
(Finsupp.total ι M R v).comp hv.repr = Submodule.subtype _ :=
LinearMap.ext <| hv.total_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.total ι M R v l = ↑x) : hv.repr x = l := by
have :
↑((LinearIndependent.totalEquiv hv : (ι →₀ R) →ₗ[R] span R (range v)) l) =
Finsupp.total ι M R v l :=
rfl
have : (LinearIndependent.totalEquiv 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.totalEquiv 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.total_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.totalEquiv hv).injective
ext
simp only [LinearIndependent.totalEquiv_apply_coe, Equiv.self_comp_ofInjective_symm,
LinearIndependent.total_repr, Finsupp.total_equivMapDomain, Span.finsupp_total_repr]
ext ⟨_, ⟨i, rfl⟩⟩
simp [← p]
theorem linearIndependent_iff_not_smul_mem_span :
LinearIndependent R v ↔ ∀ (i : ι) (a : R), a • v i ∈ span R (v '' (univ \ {i})) → a = 0 :=
⟨fun hv i a ha => by
rw [Finsupp.span_image_eq_map_total, mem_map] at ha
rcases ha with ⟨l, hl, e⟩
rw [sub_eq_zero.1 (linearIndependent_iff.1 hv (l - Finsupp.single i a) (by simp [e]))] at hl
by_contra hn
exact (not_mem_of_mem_diff (hl <| by simp [hn])) (mem_singleton _), 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_total 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]⟩
/-- See also `CompleteLattice.independent_iff_linearIndependent_of_ne_zero`. -/
theorem LinearIndependent.independent_span_singleton (hv : LinearIndependent R v) :
CompleteLattice.Independent fun i => R ∙ v i := by
refine CompleteLattice.independent_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 linearIndependent_iff_not_smul_mem_span.mp hv i
-- Porting note: The original proof was using `convert hm`.
suffices v '' (univ \ {i}) = range fun j : { j // j ≠ i } => v j by
rwa [this]
ext
simp
variable (R)
theorem exists_maximal_independent' (s : ι → M) :
∃ I : Set ι,
(LinearIndependent R fun x : I => s x) ∧
∀ J : Set ι, I ⊆ J → (LinearIndependent R fun x : J => s x) → I = J := by
let indep : Set ι → Prop := fun I => LinearIndependent R (s ∘ (↑) : I → M)
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 [linearIndependent_comp_subtype]
intro f hsupport hsum
rcases eq_empty_or_nonempty c with (rfl | hn)
· simpa using hsupport
haveI : IsRefl X r := ⟨fun _ => Set.Subset.refl _⟩
obtain ⟨I, _I_mem, hI⟩ : ∃ I ∈ c, (f.support : Set ι) ⊆ I :=
hc.directedOn.exists_mem_subset_of_finset_subset_biUnion hn hsupport
exact linearIndependent_comp_subtype.mp I.2 f 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)⟩
theorem exists_maximal_independent (s : ι → M) :
∃ I : Set ι,
(LinearIndependent R fun x : I => s x) ∧
∀ i ∉ I, ∃ a : R, a ≠ 0 ∧ a • s i ∈ span R (s '' I) := by
classical
rcases exists_maximal_independent' R s 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⟩ := linearDependent_comp_subtype.mp h
have hfi : f i ≠ 0 := by
contrapose hIlinind
refine linearDependent_comp_subtype.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.not_mem_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)
end repr
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.total ι M R v l = v i := by
dsimp only [l]
rw [Finsupp.total_mapDomain]
rw [(hv.comp f f.injective).total_repr]
-- Porting note: `rfl` isn't necessary.
have h_total_eq : (Finsupp.total ι M R v) l = (Finsupp.total ι M R v) (Finsupp.single i 1) := by
rw [h_total_l, Finsupp.total_single, one_smul]
have l_eq : l = _ := LinearMap.ker_eq_bot.1 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_linearIndependent_of_span_subtype [Nontrivial R] {s t : Set M}
(hs : LinearIndependent R (fun x => x : s → M)) (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]
show 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]
open LinearMap
theorem LinearIndependent.image_subtype {s : Set M} {f : M →ₗ[R] M'}
(hs : LinearIndependent R (fun x => x : s → M))
(hf_inj : Disjoint (span R s) (LinearMap.ker f)) :
LinearIndependent R (fun x => x : f '' s → M') := by
rw [← Subtype.range_coe (s := s)] at hf_inj
refine (hs.map hf_inj).to_subtype_range' ?_
simp [Set.range_comp f]
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
refine (hs.image_subtype ?_).union (ht.image_subtype ?_) ?_ <;> [simp; simp; skip]
-- Note: #8386 had to change `span_image` into `span_image _`
simp only [span_image _]
simp [disjoint_iff, prod_inf_prod]
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')) :=
(hv.map' (inl R M M') ker_inl).sum_type (hv'.map' (inr R M M') ker_inr) <| by
refine isCompl_range_inl_inr.disjoint.mono ?_ ?_ <;>
simp only [span_le, range_coe, range_comp_subset_range]
-- See, for example, Keith Conrad's note
-- <https://kconrad.math.uconn.edu/blurbs/galoistheory/linearchar.pdf>
/-- Dedekind's linear independence of characters -/
theorem linearIndependent_monoidHom (G : Type*) [Monoid G] (L : Type*) [CommRing L]
[NoZeroDivisors L] : LinearIndependent L (M := G → L) (fun f => f : (G →* L) → G → L) := by
-- Porting note: Some casts are required.
letI := Classical.decEq (G →* L)
letI : MulAction L L := DistribMulAction.toMulAction
-- We prove linear independence by showing that only the trivial linear combination vanishes.
exact linearIndependent_iff'.2
-- To do this, we use `Finset` induction,
-- Porting note: `False.elim` → `fun h => False.elim <| Finset.not_mem_empty _ h`
fun s =>
Finset.induction_on s
(fun g _hg i h => False.elim <| Finset.not_mem_empty _ h) fun a s has ih 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 ∈ s, (g i • (i : G → L)) = g i • (a : G → L) := fun i his =>
funext fun x : G =>
-- We prove these expressions are equal by showing
-- the differences of their values on each monoid element `x` is zero
eq_of_sub_eq_zero <|
ih (fun j => g j * j x - g j * a x)
(funext fun y : G => calc
-- After that, it's just a chase scene.
(∑ i ∈ s, ((g i * i x - g i * a x) • (i : G → L))) y =
∑ i ∈ s, (g i * i x - g i * a x) * i y :=
Finset.sum_apply ..
_ = ∑ i ∈ s, (g i * i x * i y - g i * a x * i y) :=
Finset.sum_congr rfl fun _ _ => sub_mul ..
_ = (∑ i ∈ s, g i * i x * i y) - ∑ i ∈ s, g i * a x * i y :=
Finset.sum_sub_distrib
_ =
(g a * a x * a y + ∑ i ∈ s, g i * i x * i y) -
(g a * a x * a y + ∑ i ∈ s, g i * a x * i y) := by
rw [add_sub_add_left_eq_sub]
_ =
(∑ i ∈ insert a s, g i * i x * i y) -
∑ i ∈ insert a s, g i * a x * i y := by
rw [Finset.sum_insert has, Finset.sum_insert has]
_ =
(∑ i ∈ insert a s, g i * i (x * y)) -
∑ i ∈ insert a s, a x * (g i * i y) :=
congr
(congr_arg Sub.sub
(Finset.sum_congr rfl fun i _ => by rw [i.map_mul, mul_assoc]))
(Finset.sum_congr rfl fun _ _ => by 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
rw [Finset.sum_apply, Finset.sum_apply, Finset.mul_sum]; rfl
_ = 0 - a x * 0 := by rw [hg]; rfl
_ = 0 := by rw [mul_zero, sub_zero]
)
i his
-- 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 : G →* L, i ∈ s → ∃ y, i y ≠ a y := fun i his =>
Classical.by_contradiction fun h =>
have hia : i = a := MonoidHom.ext fun y =>
Classical.by_contradiction fun hy => h ⟨y, hy⟩
has <| hia ▸ his
-- From these two facts we deduce that `g` actually vanishes on `s`,
have h3 : ∀ i ∈ s, g i = 0 := fun i his =>
let ⟨y, hy⟩ := h2 i his
have h : g i • i y = g i • a y := congr_fun (h1 i his) y
Or.resolve_right (mul_eq_zero.1 <| by rw [mul_sub, sub_eq_zero]; exact h)
(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_eq_single a]
· intro i his hia
rw [Finset.mem_insert] at his
rw [h3 i (his.resolve_left hia), zero_smul]
· intro haas
exfalso
apply haas
exact Finset.mem_insert_self a s
_ = 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`.
(Finset.forall_mem_insert ..).2 ⟨h4, h3⟩
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) := by
apply (linearIndependent_algHom_toLinearMap K M L).restrict_scalars
simp_rw [Algebra.smul_def, mul_one]
exact NoZeroSMulDivisors.algebraMap_injective K L
theorem le_of_span_le_span [Nontrivial R] {s t u : Set M} (hl : LinearIndependent R ((↑) : u → M))
(hsu : s ⊆ u) (htu : t ⊆ u) (hst : span R s ≤ span R t) : s ⊆ t := by
have :=
eq_of_linearIndependent_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 Module
section Nontrivial
variable [Ring R] [Nontrivial R] [AddCommGroup M] [AddCommGroup M']
variable [Module R M] [NoZeroSMulDivisors R M] [Module R M']
variable {v : ι → M} {s t : Set M} {x y z : M}
theorem linearIndependent_unique_iff (v : ι → M) [Unique ι] :
LinearIndependent R v ↔ v default ≠ 0 := by
simp only [linearIndependent_iff, Finsupp.total_unique, smul_eq_zero]
refine ⟨fun h hv => ?_, fun hv l hl => Finsupp.unique_ext <| hl.resolve_right hv⟩
have := h (Finsupp.single default 1) (Or.inr hv)
exact one_ne_zero (Finsupp.single_eq_zero.1 this)
alias ⟨_, linearIndependent_unique⟩ := linearIndependent_unique_iff
theorem linearIndependent_singleton {x : M} (hx : x ≠ 0) :
LinearIndependent R (fun x => x : ({x} : Set M) → M) :=
linearIndependent_unique ((↑) : ({x} : Set M) → M) hx
end Nontrivial
/-!
### 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] [AddCommGroup V']
variable [Module K V] [Module K V']
variable {v : ι → V} {s t : Set V} {x y z : 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
simp [a0, smul_add, smul_smul]
theorem linearIndependent_iff_not_mem_span :
LinearIndependent K v ↔ ∀ i, v i ∉ span K (v '' (univ \ {i})) := by
apply linearIndependent_iff_not_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))
protected theorem LinearIndependent.insert (hs : LinearIndependent K (fun b => b : s → V))
(hx : x ∉ span K s) : LinearIndependent K (fun b => b : ↥(insert x s) → V) := by
rw [← union_singleton]
have x0 : x ≠ 0 := mt (by rintro rfl; apply zero_mem (span K s)) hx
apply hs.union (linearIndependent_singleton x0)
rwa [disjoint_span_singleton' x0]
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 linearIndependent_insert' {ι} {s : Set ι} {a : ι} {f : ι → V} (has : a ∉ s) :
(LinearIndependent K fun x : ↥(insert a s) => f x) ↔
(LinearIndependent K fun x : s => f x) ∧ f a ∉ Submodule.span K (f '' s) := by
classical
rw [← linearIndependent_equiv ((Equiv.optionEquivSumPUnit _).trans (Equiv.Set.insert has).symm),
linearIndependent_option]
-- Porting note: `simp [(· ∘ ·), range_comp f]` → `simp [(· ∘ ·)]; erw [range_comp f ..]; simp`
-- https://github.com/leanprover-community/mathlib4/issues/5164
simp only [(· ∘ ·)]
erw [range_comp f ((↑) : s → ι)]
simp
theorem linearIndependent_insert (hxs : x ∉ s) :
(LinearIndependent K fun b : ↥(insert x s) => (b : V)) ↔
(LinearIndependent K fun b : s => (b : V)) ∧ x ∉ Submodule.span K s :=
(linearIndependent_insert' (f := id) hxs).trans <| by simp
theorem linearIndependent_pair {x y : V} (hx : x ≠ 0) (hy : ∀ a : K, a • x ≠ y) :
LinearIndependent K ((↑) : ({x, y} : Set V) → V) :=
pair_comm y x ▸ (linearIndependent_singleton hx).insert <|
mt mem_span_singleton.1 (not_exists.2 hy)
/-- 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 [LinearIndependent.pair_iff]
constructor
· intro H a ha
have := (H a (-1) (by simpa [← sub_eq_add_neg, sub_eq_zero])).2
simp only [neg_eq_zero, one_ne_zero] at this
· intro H s t hst
by_cases ht : t = 0
· exact ⟨by simpa [ht, hx] using hst, ht⟩
apply_fun (t⁻¹ • ·) at hst
simp only [smul_add, smul_smul, inv_mul_cancel ht, one_smul, smul_zero] at hst
cases H (-(t⁻¹ * s)) (by rwa [neg_smul, neg_eq_iff_eq_neg, eq_neg_iff_add_eq_zero])
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]
-- Porting note: `convert Iff.rfl; ...` → `exact Iff.rfl`
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
-- Porting note: `rw` → `erw`
-- https://github.com/leanprover-community/mathlib4/issues/5164
-- Here Lean can not see that `fun i ↦ Fin.cons x v (↑(finRotate (n + 1)) i)`
-- matches with `?f ∘ ↑(finRotate (n + 1))`.
erw [Fin.snoc_eq_cons_rotate, 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_linearIndependent_extension (hs : LinearIndependent K ((↑) : s → V)) (hst : s ⊆ t) :
∃ b ⊆ t, s ⊆ b ∧ t ⊆ span K b ∧ LinearIndependent K ((↑) : b → V) := by
-- Porting note: The placeholder should be solved before `rcases`.
have := by
refine zorn_subset_nonempty { b | b ⊆ t ∧ LinearIndependent K ((↑) : b → V) } ?_ _ ⟨hst, hs⟩
· refine fun c hc cc _c0 => ⟨⋃₀ c, ⟨?_, ?_⟩, fun x => ?_⟩
· exact sUnion_subset fun x xc => (hc xc).1
· exact linearIndependent_sUnion_of_directed cc.directedOn fun x xc => (hc xc).2
· exact subset_sUnion_of_mem
rcases this with
⟨b, ⟨bt, bi⟩, sb, h⟩
refine ⟨b, bt, sb, fun x xt => ?_, bi⟩
by_contra hn
apply hn
rw [← h _ ⟨insert_subset_iff.2 ⟨xt, bt⟩, bi.insert hn⟩ (subset_insert _ _)]
exact subset_span (mem_insert _ _)
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_linearIndependent_extension (linearIndependent_empty K V) (Set.empty_subset t)
exact ⟨b, hb₁, (span_eq_of_le _ hb₂ (Submodule.span_mono hb₁)).symm, hb₃⟩
variable {K t}
/-- `LinearIndependent.extend` adds vectors to a linear independent set `s ⊆ t` until it spans
all elements of `t`. -/
noncomputable def LinearIndependent.extend (hs : LinearIndependent K (fun x => x : s → V))
(hst : s ⊆ t) : Set V :=
Classical.choose (exists_linearIndependent_extension hs hst)
theorem LinearIndependent.extend_subset (hs : LinearIndependent K (fun x => x : s → V))
(hst : s ⊆ t) : hs.extend hst ⊆ t :=
let ⟨hbt, _hsb, _htb, _hli⟩ := Classical.choose_spec (exists_linearIndependent_extension hs hst)
hbt
theorem LinearIndependent.subset_extend (hs : LinearIndependent K (fun x => x : s → V))
(hst : s ⊆ t) : s ⊆ hs.extend hst :=
let ⟨_hbt, hsb, _htb, _hli⟩ := Classical.choose_spec (exists_linearIndependent_extension hs hst)
hsb
theorem LinearIndependent.subset_span_extend (hs : LinearIndependent K (fun x => x : s → V))
(hst : s ⊆ t) : t ⊆ span K (hs.extend hst) :=
let ⟨_hbt, _hsb, htb, _hli⟩ := Classical.choose_spec (exists_linearIndependent_extension hs hst)
htb
theorem LinearIndependent.linearIndependent_extend (hs : LinearIndependent K (fun x => x : s → V))
(hst : s ⊆ t) : LinearIndependent K ((↑) : hs.extend hst → V) :=
let ⟨_hbt, _hsb, _htb, hli⟩ := Classical.choose_spec (exists_linearIndependent_extension hs hst)
hli
-- TODO(Mario): rewrite?
theorem exists_of_linearIndependent_of_finite_span {t : Finset V}
(hs : LinearIndependent K (fun x => x : s → V)) (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_linearIndependent_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: `-inter_subset_left, -subset_inter_iff` required.
Subset.trans
(by simp [inter_subset_inter, Subset.refl, -inter_subset_left, -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
-- Porting note: Too many theorems to be excluded, so
-- `simp only` is shorter.
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'
-- Porting note: `by exact` is required to prevent timeout.
have hb₁ : b₁ ∈ span K (insert b₂ ↑(s' ∪ t)) := by
exact 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
-- Porting note: `hb₂t'` → `Finset.card_insert_of_not_mem hb₂t'`
⟨u, Subset.trans hust <| union_subset_union (Subset.refl _) (by simp [subset_insert]), hsu,
by simp [eq, Finset.card_insert_of_not_mem 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 (config := { contextual := true }) [Set.ext_iff]) (by rwa [eq]))
intro u h
exact
⟨u, Subset.trans h.1 (by simp (config := { contextual := true }) [subset_def, and_imp, or_imp]),
h.2.1, by simp only [h.2.2, eq]⟩
theorem exists_finite_card_le_of_finite_of_linearIndependent_of_span (ht : t.Finite)
(hs : LinearIndependent K (fun x => x : s → V)) (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_linearIndependent_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
|
LinearAlgebra\LinearPMap.lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Moritz Doll
-/
import Mathlib.LinearAlgebra.Prod
import Mathlib.Algebra.Module.Basic
/-!
# Partially defined linear maps
A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`.
We define a `SemilatticeInf` with `OrderBot` instance on this, and define three operations:
* `mkSpanSingleton` defines a partial linear map defined on the span of a singleton.
* `sup` takes two partial linear maps `f`, `g` that agree on the intersection of their
domains, and returns the unique partial linear map on `f.domain ⊔ g.domain` that
extends both `f` and `g`.
* `sSup` takes a `DirectedOn (· ≤ ·)` set of partial linear maps, and returns the unique
partial linear map on the `sSup` of their domains that extends all these maps.
Moreover, we define
* `LinearPMap.graph` is the graph of the partial linear map viewed as a submodule of `E × F`.
Partially defined maps are currently used in `Mathlib` to prove Hahn-Banach theorem
and its variations. Namely, `LinearPMap.sSup` implies that every chain of `LinearPMap`s
is bounded above.
They are also the basis for the theory of unbounded operators.
-/
universe u v w
/-- A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. -/
structure LinearPMap (R : Type u) [Ring R] (E : Type v) [AddCommGroup E] [Module R E] (F : Type w)
[AddCommGroup F] [Module R F] where
domain : Submodule R E
toFun : domain →ₗ[R] F
@[inherit_doc] notation:25 E " →ₗ.[" R:25 "] " F:0 => LinearPMap R E F
variable {R : Type*} [Ring R] {E : Type*} [AddCommGroup E] [Module R E] {F : Type*}
[AddCommGroup F] [Module R F] {G : Type*} [AddCommGroup G] [Module R G]
namespace LinearPMap
open Submodule
-- Porting note: A new definition underlying a coercion `↑`.
@[coe]
def toFun' (f : E →ₗ.[R] F) : f.domain → F := f.toFun
instance : CoeFun (E →ₗ.[R] F) fun f : E →ₗ.[R] F => f.domain → F :=
⟨toFun'⟩
@[simp]
theorem toFun_eq_coe (f : E →ₗ.[R] F) (x : f.domain) : f.toFun x = f x :=
rfl
@[ext (iff := false)]
theorem ext {f g : E →ₗ.[R] F} (h : f.domain = g.domain)
(h' : ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y) : f = g := by
rcases f with ⟨f_dom, f⟩
rcases g with ⟨g_dom, g⟩
obtain rfl : f_dom = g_dom := h
obtain rfl : f = g := LinearMap.ext fun x => h' rfl
rfl
@[simp]
theorem map_zero (f : E →ₗ.[R] F) : f 0 = 0 :=
f.toFun.map_zero
theorem ext_iff {f g : E →ₗ.[R] F} :
f = g ↔
∃ _domain_eq : f.domain = g.domain,
∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y :=
⟨fun EQ =>
EQ ▸
⟨rfl, fun x y h => by
congr
exact mod_cast h⟩,
fun ⟨deq, feq⟩ => ext deq feq⟩
theorem ext' {s : Submodule R E} {f g : s →ₗ[R] F} (h : f = g) : mk s f = mk s g :=
h ▸ rfl
theorem map_add (f : E →ₗ.[R] F) (x y : f.domain) : f (x + y) = f x + f y :=
f.toFun.map_add x y
theorem map_neg (f : E →ₗ.[R] F) (x : f.domain) : f (-x) = -f x :=
f.toFun.map_neg x
theorem map_sub (f : E →ₗ.[R] F) (x y : f.domain) : f (x - y) = f x - f y :=
f.toFun.map_sub x y
theorem map_smul (f : E →ₗ.[R] F) (c : R) (x : f.domain) : f (c • x) = c • f x :=
f.toFun.map_smul c x
@[simp]
theorem mk_apply (p : Submodule R E) (f : p →ₗ[R] F) (x : p) : mk p f x = f x :=
rfl
/-- The unique `LinearPMap` on `R ∙ x` that sends `x` to `y`. This version works for modules
over rings, and requires a proof of `∀ c, c • x = 0 → c • y = 0`. -/
noncomputable def mkSpanSingleton' (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) :
E →ₗ.[R] F where
domain := R ∙ x
toFun :=
have H : ∀ c₁ c₂ : R, c₁ • x = c₂ • x → c₁ • y = c₂ • y := by
intro c₁ c₂ h
rw [← sub_eq_zero, ← sub_smul] at h ⊢
exact H _ h
{ toFun := fun z => Classical.choose (mem_span_singleton.1 z.prop) • y
-- Porting note(#12129): additional beta reduction needed
-- Porting note: Were `Classical.choose_spec (mem_span_singleton.1 _)`.
map_add' := fun y z => by
beta_reduce
rw [← add_smul]
apply H
simp only [add_smul, sub_smul,
fun w : R ∙ x => Classical.choose_spec (mem_span_singleton.1 w.prop)]
apply coe_add
map_smul' := fun c z => by
beta_reduce
rw [smul_smul]
apply H
simp only [mul_smul,
fun w : R ∙ x => Classical.choose_spec (mem_span_singleton.1 w.prop)]
apply coe_smul }
@[simp]
theorem domain_mkSpanSingleton (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) :
(mkSpanSingleton' x y H).domain = R ∙ x :=
rfl
@[simp]
theorem mkSpanSingleton'_apply (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (c : R) (h) :
mkSpanSingleton' x y H ⟨c • x, h⟩ = c • y := by
dsimp [mkSpanSingleton']
rw [← sub_eq_zero, ← sub_smul]
apply H
simp only [sub_smul, one_smul, sub_eq_zero]
apply Classical.choose_spec (mem_span_singleton.1 h)
@[simp]
theorem mkSpanSingleton'_apply_self (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (h) :
mkSpanSingleton' x y H ⟨x, h⟩ = y := by
-- Porting note: A placeholder should be specified before `convert`.
have := by refine mkSpanSingleton'_apply x y H 1 ?_; rwa [one_smul]
convert this <;> rw [one_smul]
/-- The unique `LinearPMap` on `span R {x}` that sends a non-zero vector `x` to `y`.
This version works for modules over division rings. -/
noncomputable abbrev mkSpanSingleton {K E F : Type*} [DivisionRing K] [AddCommGroup E] [Module K E]
[AddCommGroup F] [Module K F] (x : E) (y : F) (hx : x ≠ 0) : E →ₗ.[K] F :=
mkSpanSingleton' x y fun c hc =>
(smul_eq_zero.1 hc).elim (fun hc => by rw [hc, zero_smul]) fun hx' => absurd hx' hx
theorem mkSpanSingleton_apply (K : Type*) {E F : Type*} [DivisionRing K] [AddCommGroup E]
[Module K E] [AddCommGroup F] [Module K F] {x : E} (hx : x ≠ 0) (y : F) :
mkSpanSingleton x y hx ⟨x, (Submodule.mem_span_singleton_self x : x ∈ Submodule.span K {x})⟩ =
y :=
LinearPMap.mkSpanSingleton'_apply_self _ _ _ _
/-- Projection to the first coordinate as a `LinearPMap` -/
protected def fst (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] E where
domain := p.prod p'
toFun := (LinearMap.fst R E F).comp (p.prod p').subtype
@[simp]
theorem fst_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') :
LinearPMap.fst p p' x = (x : E × F).1 :=
rfl
/-- Projection to the second coordinate as a `LinearPMap` -/
protected def snd (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] F where
domain := p.prod p'
toFun := (LinearMap.snd R E F).comp (p.prod p').subtype
@[simp]
theorem snd_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') :
LinearPMap.snd p p' x = (x : E × F).2 :=
rfl
instance le : LE (E →ₗ.[R] F) :=
⟨fun f g => f.domain ≤ g.domain ∧ ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y⟩
theorem apply_comp_inclusion {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) :
T x = S (Submodule.inclusion h.1 x) :=
h.2 rfl
theorem exists_of_le {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) :
∃ y : S.domain, (x : E) = y ∧ T x = S y :=
⟨⟨x.1, h.1 x.2⟩, ⟨rfl, h.2 rfl⟩⟩
theorem eq_of_le_of_domain_eq {f g : E →ₗ.[R] F} (hle : f ≤ g) (heq : f.domain = g.domain) :
f = g :=
ext heq hle.2
/-- Given two partial linear maps `f`, `g`, the set of points `x` such that
both `f` and `g` are defined at `x` and `f x = g x` form a submodule. -/
def eqLocus (f g : E →ₗ.[R] F) : Submodule R E where
carrier := { x | ∃ (hf : x ∈ f.domain) (hg : x ∈ g.domain), f ⟨x, hf⟩ = g ⟨x, hg⟩ }
zero_mem' := ⟨zero_mem _, zero_mem _, f.map_zero.trans g.map_zero.symm⟩
add_mem' := fun {x y} ⟨hfx, hgx, hx⟩ ⟨hfy, hgy, hy⟩ =>
⟨add_mem hfx hfy, add_mem hgx hgy, by
erw [f.map_add ⟨x, hfx⟩ ⟨y, hfy⟩, g.map_add ⟨x, hgx⟩ ⟨y, hgy⟩, hx, hy]⟩
-- Porting note: `by rintro` is required, or error of a free variable happens.
smul_mem' := by
rintro c x ⟨hfx, hgx, hx⟩
exact
⟨smul_mem _ c hfx, smul_mem _ c hgx,
by erw [f.map_smul c ⟨x, hfx⟩, g.map_smul c ⟨x, hgx⟩, hx]⟩
instance inf : Inf (E →ₗ.[R] F) :=
⟨fun f g => ⟨f.eqLocus g, f.toFun.comp <| inclusion fun _x hx => hx.fst⟩⟩
instance bot : Bot (E →ₗ.[R] F) :=
⟨⟨⊥, 0⟩⟩
instance inhabited : Inhabited (E →ₗ.[R] F) :=
⟨⊥⟩
instance semilatticeInf : SemilatticeInf (E →ₗ.[R] F) where
le := (· ≤ ·)
le_refl f := ⟨le_refl f.domain, fun x y h => Subtype.eq h ▸ rfl⟩
le_trans := fun f g h ⟨fg_le, fg_eq⟩ ⟨gh_le, gh_eq⟩ =>
⟨le_trans fg_le gh_le, fun x z hxz =>
have hxy : (x : E) = inclusion fg_le x := rfl
(fg_eq hxy).trans (gh_eq <| hxy.symm.trans hxz)⟩
le_antisymm f g fg gf := eq_of_le_of_domain_eq fg (le_antisymm fg.1 gf.1)
inf := (· ⊓ ·)
-- Porting note: `by rintro` is required, or error of a metavariable happens.
le_inf := by
rintro f g h ⟨fg_le, fg_eq⟩ ⟨fh_le, fh_eq⟩
exact ⟨fun x hx =>
⟨fg_le hx, fh_le hx, by
-- Porting note: `[exact ⟨x, hx⟩, rfl, rfl]` → `[skip, exact ⟨x, hx⟩, skip] <;> rfl`
convert (fg_eq _).symm.trans (fh_eq _) <;> [skip; exact ⟨x, hx⟩; skip] <;> rfl⟩,
fun x ⟨y, yg, hy⟩ h => by
apply fg_eq
exact h⟩
inf_le_left f g := ⟨fun x hx => hx.fst, fun x y h => congr_arg f <| Subtype.eq <| h⟩
inf_le_right f g :=
⟨fun x hx => hx.snd.fst, fun ⟨x, xf, xg, hx⟩ y h => hx.trans <| congr_arg g <| Subtype.eq <| h⟩
instance orderBot : OrderBot (E →ₗ.[R] F) where
bot := ⊥
bot_le f :=
⟨bot_le, fun x y h => by
have hx : x = 0 := Subtype.eq ((mem_bot R).1 x.2)
have hy : y = 0 := Subtype.eq (h.symm.trans (congr_arg _ hx))
rw [hx, hy, map_zero, map_zero]⟩
theorem le_of_eqLocus_ge {f g : E →ₗ.[R] F} (H : f.domain ≤ f.eqLocus g) : f ≤ g :=
suffices f ≤ f ⊓ g from le_trans this inf_le_right
⟨H, fun _x _y hxy => ((inf_le_left : f ⊓ g ≤ f).2 hxy.symm).symm⟩
theorem domain_mono : StrictMono (@domain R _ E _ _ F _ _) := fun _f _g hlt =>
lt_of_le_of_ne hlt.1.1 fun heq => ne_of_lt hlt <| eq_of_le_of_domain_eq (le_of_lt hlt) heq
private theorem sup_aux (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) :
∃ fg : ↥(f.domain ⊔ g.domain) →ₗ[R] F,
∀ (x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)),
(x : E) + y = ↑z → fg z = f x + g y := by
choose x hx y hy hxy using fun z : ↥(f.domain ⊔ g.domain) => mem_sup.1 z.prop
set fg := fun z => f ⟨x z, hx z⟩ + g ⟨y z, hy z⟩
have fg_eq : ∀ (x' : f.domain) (y' : g.domain) (z' : ↥(f.domain ⊔ g.domain))
(_H : (x' : E) + y' = z'), fg z' = f x' + g y' := by
intro x' y' z' H
dsimp [fg]
rw [add_comm, ← sub_eq_sub_iff_add_eq_add, eq_comm, ← map_sub, ← map_sub]
apply h
simp only [← eq_sub_iff_add_eq] at hxy
simp only [AddSubgroupClass.coe_sub, coe_mk, coe_mk, hxy, ← sub_add, ← sub_sub, sub_self,
zero_sub, ← H]
apply neg_add_eq_sub
use { toFun := fg, map_add' := ?_, map_smul' := ?_ }, fg_eq
· rintro ⟨z₁, hz₁⟩ ⟨z₂, hz₂⟩
rw [← add_assoc, add_right_comm (f _), ← map_add, add_assoc, ← map_add]
apply fg_eq
simp only [coe_add, coe_mk, ← add_assoc]
rw [add_right_comm (x _), hxy, add_assoc, hxy, coe_mk, coe_mk]
· intro c z
rw [smul_add, ← map_smul, ← map_smul]
apply fg_eq
simp only [coe_smul, coe_mk, ← smul_add, hxy, RingHom.id_apply]
/-- Given two partial linear maps that agree on the intersection of their domains,
`f.sup g h` is the unique partial linear map on `f.domain ⊔ g.domain` that agrees
with `f` and `g`. -/
protected noncomputable def sup (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : E →ₗ.[R] F :=
⟨_, Classical.choose (sup_aux f g h)⟩
@[simp]
theorem domain_sup (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) :
(f.sup g h).domain = f.domain ⊔ g.domain :=
rfl
theorem sup_apply {f g : E →ₗ.[R] F} (H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y)
(x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)) (hz : (↑x : E) + ↑y = ↑z) :
f.sup g H z = f x + g y :=
Classical.choose_spec (sup_aux f g H) x y z hz
protected theorem left_le_sup (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : f ≤ f.sup g h := by
refine ⟨le_sup_left, fun z₁ z₂ hz => ?_⟩
rw [← add_zero (f _), ← g.map_zero]
refine (sup_apply h _ _ _ ?_).symm
simpa
protected theorem right_le_sup (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : g ≤ f.sup g h := by
refine ⟨le_sup_right, fun z₁ z₂ hz => ?_⟩
rw [← zero_add (g _), ← f.map_zero]
refine (sup_apply h _ _ _ ?_).symm
simpa
protected theorem sup_le {f g h : E →ₗ.[R] F}
(H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) (fh : f ≤ h) (gh : g ≤ h) :
f.sup g H ≤ h :=
have Hf : f ≤ f.sup g H ⊓ h := le_inf (f.left_le_sup g H) fh
have Hg : g ≤ f.sup g H ⊓ h := le_inf (f.right_le_sup g H) gh
le_of_eqLocus_ge <| sup_le Hf.1 Hg.1
/-- Hypothesis for `LinearPMap.sup` holds, if `f.domain` is disjoint with `g.domain`. -/
theorem sup_h_of_disjoint (f g : E →ₗ.[R] F) (h : Disjoint f.domain g.domain) (x : f.domain)
(y : g.domain) (hxy : (x : E) = y) : f x = g y := by
rw [disjoint_def] at h
have hy : y = 0 := Subtype.eq (h y (hxy ▸ x.2) y.2)
have hx : x = 0 := Subtype.eq (hxy.trans <| congr_arg _ hy)
simp [*]
/-! ### Algebraic operations -/
section Zero
instance instZero : Zero (E →ₗ.[R] F) := ⟨⊤, 0⟩
@[simp]
theorem zero_domain : (0 : E →ₗ.[R] F).domain = ⊤ := rfl
@[simp]
theorem zero_apply (x : (⊤ : Submodule R E)) : (0 : E →ₗ.[R] F) x = 0 := rfl
end Zero
section SMul
variable {M N : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass R M F]
variable [Monoid N] [DistribMulAction N F] [SMulCommClass R N F]
instance instSMul : SMul M (E →ₗ.[R] F) :=
⟨fun a f =>
{ domain := f.domain
toFun := a • f.toFun }⟩
@[simp]
theorem smul_domain (a : M) (f : E →ₗ.[R] F) : (a • f).domain = f.domain :=
rfl
theorem smul_apply (a : M) (f : E →ₗ.[R] F) (x : (a • f).domain) : (a • f) x = a • f x :=
rfl
@[simp]
theorem coe_smul (a : M) (f : E →ₗ.[R] F) : ⇑(a • f) = a • ⇑f :=
rfl
instance instSMulCommClass [SMulCommClass M N F] : SMulCommClass M N (E →ₗ.[R] F) :=
⟨fun a b f => ext' <| smul_comm a b f.toFun⟩
instance instIsScalarTower [SMul M N] [IsScalarTower M N F] : IsScalarTower M N (E →ₗ.[R] F) :=
⟨fun a b f => ext' <| smul_assoc a b f.toFun⟩
instance instMulAction : MulAction M (E →ₗ.[R] F) where
smul := (· • ·)
one_smul := fun ⟨_s, f⟩ => ext' <| one_smul M f
mul_smul a b f := ext' <| mul_smul a b f.toFun
end SMul
instance instNeg : Neg (E →ₗ.[R] F) :=
⟨fun f => ⟨f.domain, -f.toFun⟩⟩
@[simp]
theorem neg_domain (f : E →ₗ.[R] F) : (-f).domain = f.domain := rfl
@[simp]
theorem neg_apply (f : E →ₗ.[R] F) (x) : (-f) x = -f x :=
rfl
instance instInvolutiveNeg : InvolutiveNeg (E →ₗ.[R] F) :=
⟨fun f => by
ext x y hxy
· rfl
· simp only [neg_apply, neg_neg]
cases x
congr⟩
section Add
instance instAdd : Add (E →ₗ.[R] F) :=
⟨fun f g =>
{ domain := f.domain ⊓ g.domain
toFun := f.toFun.comp (inclusion (inf_le_left : f.domain ⊓ g.domain ≤ _))
+ g.toFun.comp (inclusion (inf_le_right : f.domain ⊓ g.domain ≤ _)) }⟩
theorem add_domain (f g : E →ₗ.[R] F) : (f + g).domain = f.domain ⊓ g.domain := rfl
theorem add_apply (f g : E →ₗ.[R] F) (x : (f.domain ⊓ g.domain : Submodule R E)) :
(f + g) x = f ⟨x, x.prop.1⟩ + g ⟨x, x.prop.2⟩ := rfl
instance instAddSemigroup : AddSemigroup (E →ₗ.[R] F) :=
⟨fun f g h => by
ext x y hxy
· simp only [add_domain, inf_assoc]
· simp only [add_apply, hxy, add_assoc]⟩
instance instAddZeroClass : AddZeroClass (E →ₗ.[R] F) :=
⟨fun f => by
ext x y hxy
· simp [add_domain]
· simp only [add_apply, hxy, zero_apply, zero_add],
fun f => by
ext x y hxy
· simp [add_domain]
· simp only [add_apply, hxy, zero_apply, add_zero]⟩
instance instAddMonoid : AddMonoid (E →ₗ.[R] F) where
zero_add f := by
simp
add_zero := by
simp
nsmul := nsmulRec
instance instAddCommMonoid : AddCommMonoid (E →ₗ.[R] F) :=
⟨fun f g => by
ext x y hxy
· simp only [add_domain, inf_comm]
· simp only [add_apply, hxy, add_comm]⟩
end Add
section VAdd
instance instVAdd : VAdd (E →ₗ[R] F) (E →ₗ.[R] F) :=
⟨fun f g =>
{ domain := g.domain
toFun := f.comp g.domain.subtype + g.toFun }⟩
@[simp]
theorem vadd_domain (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : (f +ᵥ g).domain = g.domain :=
rfl
theorem vadd_apply (f : E →ₗ[R] F) (g : E →ₗ.[R] F) (x : (f +ᵥ g).domain) :
(f +ᵥ g) x = f x + g x :=
rfl
@[simp]
theorem coe_vadd (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : ⇑(f +ᵥ g) = ⇑(f.comp g.domain.subtype) + ⇑g :=
rfl
instance instAddAction : AddAction (E →ₗ[R] F) (E →ₗ.[R] F) where
vadd := (· +ᵥ ·)
zero_vadd := fun ⟨_s, _f⟩ => ext' <| zero_add _
add_vadd := fun _f₁ _f₂ ⟨_s, _g⟩ => ext' <| LinearMap.ext fun _x => add_assoc _ _ _
end VAdd
section Sub
instance instSub : Sub (E →ₗ.[R] F) :=
⟨fun f g =>
{ domain := f.domain ⊓ g.domain
toFun := f.toFun.comp (inclusion (inf_le_left : f.domain ⊓ g.domain ≤ _))
- g.toFun.comp (inclusion (inf_le_right : f.domain ⊓ g.domain ≤ _)) }⟩
theorem sub_domain (f g : E →ₗ.[R] F) : (f - g).domain = f.domain ⊓ g.domain := rfl
theorem sub_apply (f g : E →ₗ.[R] F) (x : (f.domain ⊓ g.domain : Submodule R E)) :
(f - g) x = f ⟨x, x.prop.1⟩ - g ⟨x, x.prop.2⟩ := rfl
instance instSubtractionCommMonoid : SubtractionCommMonoid (E →ₗ.[R] F) where
add_comm := add_comm
sub_eq_add_neg f g := by
ext x y h
· rfl
simp [sub_apply, add_apply, neg_apply, ← sub_eq_add_neg, h]
neg_neg := neg_neg
neg_add_rev f g := by
ext x y h
· simp [add_domain, sub_domain, neg_domain, And.comm]
simp [sub_apply, add_apply, neg_apply, ← sub_eq_add_neg, h]
neg_eq_of_add f g h' := by
ext x y h
· have : (0 : E →ₗ.[R] F).domain = ⊤ := zero_domain
simp only [← h', add_domain, inf_eq_top_iff] at this
rw [neg_domain, this.1, this.2]
simp only [inf_coe, neg_domain, Eq.ndrec, Int.ofNat_eq_coe, neg_apply]
rw [ext_iff] at h'
rcases h' with ⟨hdom, h'⟩
rw [zero_domain] at hdom
simp only [inf_coe, neg_domain, Eq.ndrec, Int.ofNat_eq_coe, zero_domain, top_coe, zero_apply,
Subtype.forall, mem_top, forall_true_left, forall_eq'] at h'
specialize h' x.1 (by simp [hdom])
simp only [inf_coe, neg_domain, Eq.ndrec, Int.ofNat_eq_coe, add_apply, Subtype.coe_eta,
← neg_eq_iff_add_eq_zero] at h'
rw [h', h]
zsmul := zsmulRec
end Sub
section
variable {K : Type*} [DivisionRing K] [Module K E] [Module K F]
/-- Extend a `LinearPMap` to `f.domain ⊔ K ∙ x`. -/
noncomputable def supSpanSingleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) :
E →ₗ.[K] F :=
-- Porting note: `simpa [..]` → `simp [..]; exact ..`
f.sup (mkSpanSingleton x y fun h₀ => hx <| h₀.symm ▸ f.domain.zero_mem) <|
sup_h_of_disjoint _ _ <| by simp [disjoint_span_singleton]; exact fun h => False.elim <| hx h
@[simp]
theorem domain_supSpanSingleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) :
(f.supSpanSingleton x y hx).domain = f.domain ⊔ K ∙ x :=
rfl
@[simp]
theorem supSpanSingleton_apply_mk (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) (x' : E)
(hx' : x' ∈ f.domain) (c : K) :
f.supSpanSingleton x y hx
⟨x' + c • x, mem_sup.2 ⟨x', hx', _, mem_span_singleton.2 ⟨c, rfl⟩, rfl⟩⟩ =
f ⟨x', hx'⟩ + c • y := by
-- Porting note: `erw [..]; rfl; exact ..` → `erw [..]; exact ..; rfl`
-- That is, the order of the side goals generated by `erw` changed.
erw [sup_apply _ ⟨x', hx'⟩ ⟨c • x, _⟩, mkSpanSingleton'_apply]
· exact mem_span_singleton.2 ⟨c, rfl⟩
· rfl
end
private theorem sSup_aux (c : Set (E →ₗ.[R] F)) (hc : DirectedOn (· ≤ ·) c) :
∃ f : ↥(sSup (domain '' c)) →ₗ[R] F, (⟨_, f⟩ : E →ₗ.[R] F) ∈ upperBounds c := by
rcases c.eq_empty_or_nonempty with ceq | cne
· subst c
simp
have hdir : DirectedOn (· ≤ ·) (domain '' c) :=
directedOn_image.2 (hc.mono @(domain_mono.monotone))
have P : ∀ x : ↥(sSup (domain '' c)), { p : c // (x : E) ∈ p.val.domain } := by
rintro x
apply Classical.indefiniteDescription
have := (mem_sSup_of_directed (cne.image _) hdir).1 x.2
-- Porting note: + `← bex_def`
rwa [Set.exists_mem_image, ← bex_def, SetCoe.exists'] at this
set f : ↥(sSup (domain '' c)) → F := fun x => (P x).val.val ⟨x, (P x).property⟩
have f_eq : ∀ (p : c) (x : ↥(sSup (domain '' c))) (y : p.1.1) (_hxy : (x : E) = y),
f x = p.1 y := by
intro p x y hxy
rcases hc (P x).1.1 (P x).1.2 p.1 p.2 with ⟨q, _hqc, hxq, hpq⟩
-- Porting note: `refine' ..; exacts [inclusion hpq.1 y, hxy, rfl]`
-- → `refine' .. <;> [skip; exact inclusion hpq.1 y; rfl]; exact hxy`
convert (hxq.2 _).trans (hpq.2 _).symm <;> [skip; exact inclusion hpq.1 y; rfl]; exact hxy
use { toFun := f, map_add' := ?_, map_smul' := ?_ }, ?_
· intro x y
rcases hc (P x).1.1 (P x).1.2 (P y).1.1 (P y).1.2 with ⟨p, hpc, hpx, hpy⟩
set x' := inclusion hpx.1 ⟨x, (P x).2⟩
set y' := inclusion hpy.1 ⟨y, (P y).2⟩
rw [f_eq ⟨p, hpc⟩ x x' rfl, f_eq ⟨p, hpc⟩ y y' rfl, f_eq ⟨p, hpc⟩ (x + y) (x' + y') rfl,
map_add]
· intro c x
simp only [RingHom.id_apply]
rw [f_eq (P x).1 (c • x) (c • ⟨x, (P x).2⟩) rfl, ← map_smul]
· intro p hpc
refine ⟨le_sSup <| Set.mem_image_of_mem domain hpc, fun x y hxy => Eq.symm ?_⟩
exact f_eq ⟨p, hpc⟩ _ _ hxy.symm
protected noncomputable def sSup (c : Set (E →ₗ.[R] F)) (hc : DirectedOn (· ≤ ·) c) : E →ₗ.[R] F :=
⟨_, Classical.choose <| sSup_aux c hc⟩
protected theorem le_sSup {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {f : E →ₗ.[R] F}
(hf : f ∈ c) : f ≤ LinearPMap.sSup c hc :=
Classical.choose_spec (sSup_aux c hc) hf
protected theorem sSup_le {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {g : E →ₗ.[R] F}
(hg : ∀ f ∈ c, f ≤ g) : LinearPMap.sSup c hc ≤ g :=
le_of_eqLocus_ge <|
sSup_le fun _ ⟨f, hf, Eq⟩ =>
Eq ▸
have : f ≤ LinearPMap.sSup c hc ⊓ g := le_inf (LinearPMap.le_sSup _ hf) (hg f hf)
this.1
protected theorem sSup_apply {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {l : E →ₗ.[R] F}
(hl : l ∈ c) (x : l.domain) :
(LinearPMap.sSup c hc) ⟨x, (LinearPMap.le_sSup hc hl).1 x.2⟩ = l x := by
symm
apply (Classical.choose_spec (sSup_aux c hc) hl).2
rfl
end LinearPMap
namespace LinearMap
/-- Restrict a linear map to a submodule, reinterpreting the result as a `LinearPMap`. -/
def toPMap (f : E →ₗ[R] F) (p : Submodule R E) : E →ₗ.[R] F :=
⟨p, f.comp p.subtype⟩
@[simp]
theorem toPMap_apply (f : E →ₗ[R] F) (p : Submodule R E) (x : p) : f.toPMap p x = f x :=
rfl
@[simp]
theorem toPMap_domain (f : E →ₗ[R] F) (p : Submodule R E) : (f.toPMap p).domain = p :=
rfl
/-- Compose a linear map with a `LinearPMap` -/
def compPMap (g : F →ₗ[R] G) (f : E →ₗ.[R] F) : E →ₗ.[R] G where
domain := f.domain
toFun := g.comp f.toFun
@[simp]
theorem compPMap_apply (g : F →ₗ[R] G) (f : E →ₗ.[R] F) (x) : g.compPMap f x = g (f x) :=
rfl
end LinearMap
namespace LinearPMap
/-- Restrict codomain of a `LinearPMap` -/
def codRestrict (f : E →ₗ.[R] F) (p : Submodule R F) (H : ∀ x, f x ∈ p) : E →ₗ.[R] p where
domain := f.domain
toFun := f.toFun.codRestrict p H
/-- Compose two `LinearPMap`s -/
def comp (g : F →ₗ.[R] G) (f : E →ₗ.[R] F) (H : ∀ x : f.domain, f x ∈ g.domain) : E →ₗ.[R] G :=
g.toFun.compPMap <| f.codRestrict _ H
/-- `f.coprod g` is the partially defined linear map defined on `f.domain × g.domain`,
and sending `p` to `f p.1 + g p.2`. -/
def coprod (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) : E × F →ₗ.[R] G where
domain := f.domain.prod g.domain
toFun :=
-- Porting note: This is just
-- `(f.comp (LinearPMap.fst f.domain g.domain) fun x => x.2.1).toFun +`
-- ` (g.comp (LinearPMap.snd f.domain g.domain) fun x => x.2.2).toFun`,
HAdd.hAdd
(α := f.domain.prod g.domain →ₗ[R] G)
(β := f.domain.prod g.domain →ₗ[R] G)
(f.comp (LinearPMap.fst f.domain g.domain) fun x => x.2.1).toFun
(g.comp (LinearPMap.snd f.domain g.domain) fun x => x.2.2).toFun
@[simp]
theorem coprod_apply (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) (x) :
f.coprod g x = f ⟨(x : E × F).1, x.2.1⟩ + g ⟨(x : E × F).2, x.2.2⟩ :=
rfl
/-- Restrict a partially defined linear map to a submodule of `E` contained in `f.domain`. -/
def domRestrict (f : E →ₗ.[R] F) (S : Submodule R E) : E →ₗ.[R] F :=
⟨S ⊓ f.domain, f.toFun.comp (Submodule.inclusion (by simp))⟩
@[simp]
theorem domRestrict_domain (f : E →ₗ.[R] F) {S : Submodule R E} :
(f.domRestrict S).domain = S ⊓ f.domain :=
rfl
theorem domRestrict_apply {f : E →ₗ.[R] F} {S : Submodule R E} ⦃x : ↥(S ⊓ f.domain)⦄ ⦃y : f.domain⦄
(h : (x : E) = y) : f.domRestrict S x = f y := by
have : Submodule.inclusion (by simp) x = y := by
ext
simp [h]
rw [← this]
exact LinearPMap.mk_apply _ _ _
theorem domRestrict_le {f : E →ₗ.[R] F} {S : Submodule R E} : f.domRestrict S ≤ f :=
⟨by simp, fun x y hxy => domRestrict_apply hxy⟩
/-! ### Graph -/
section Graph
/-- The graph of a `LinearPMap` viewed as a submodule on `E × F`. -/
def graph (f : E →ₗ.[R] F) : Submodule R (E × F) :=
f.toFun.graph.map (f.domain.subtype.prodMap (LinearMap.id : F →ₗ[R] F))
theorem mem_graph_iff' (f : E →ₗ.[R] F) {x : E × F} :
x ∈ f.graph ↔ ∃ y : f.domain, (↑y, f y) = x := by simp [graph]
@[simp]
theorem mem_graph_iff (f : E →ₗ.[R] F) {x : E × F} :
x ∈ f.graph ↔ ∃ y : f.domain, (↑y : E) = x.1 ∧ f y = x.2 := by
cases x
simp_rw [mem_graph_iff', Prod.mk.inj_iff]
/-- The tuple `(x, f x)` is contained in the graph of `f`. -/
theorem mem_graph (f : E →ₗ.[R] F) (x : domain f) : ((x : E), f x) ∈ f.graph := by simp
theorem graph_map_fst_eq_domain (f : E →ₗ.[R] F) :
f.graph.map (LinearMap.fst R E F) = f.domain := by
ext x
simp only [Submodule.mem_map, mem_graph_iff, Subtype.exists, exists_and_left, exists_eq_left,
LinearMap.fst_apply, Prod.exists, exists_and_right, exists_eq_right]
constructor <;> intro h
· rcases h with ⟨x, hx, _⟩
exact hx
· use f ⟨x, h⟩
simp only [h, exists_const]
theorem graph_map_snd_eq_range (f : E →ₗ.[R] F) :
f.graph.map (LinearMap.snd R E F) = LinearMap.range f.toFun := by ext; simp
variable {M : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass R M F] (y : M)
/-- The graph of `z • f` as a pushforward. -/
theorem smul_graph (f : E →ₗ.[R] F) (z : M) :
(z • f).graph =
f.graph.map ((LinearMap.id : E →ₗ[R] E).prodMap (z • (LinearMap.id : F →ₗ[R] F))) := by
ext x; cases' x with x_fst x_snd
constructor <;> intro h
· rw [mem_graph_iff] at h
rcases h with ⟨y, hy, h⟩
rw [LinearPMap.smul_apply] at h
rw [Submodule.mem_map]
simp only [mem_graph_iff, LinearMap.prodMap_apply, LinearMap.id_coe, id,
LinearMap.smul_apply, Prod.mk.inj_iff, Prod.exists, exists_exists_and_eq_and]
use x_fst, y, hy
rw [Submodule.mem_map] at h
rcases h with ⟨x', hx', h⟩
cases x'
simp only [LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.smul_apply,
Prod.mk.inj_iff] at h
rw [mem_graph_iff] at hx' ⊢
rcases hx' with ⟨y, hy, hx'⟩
use y
rw [← h.1, ← h.2]
simp [hy, hx']
/-- The graph of `-f` as a pushforward. -/
theorem neg_graph (f : E →ₗ.[R] F) :
(-f).graph =
f.graph.map ((LinearMap.id : E →ₗ[R] E).prodMap (-(LinearMap.id : F →ₗ[R] F))) := by
ext x; cases' x with x_fst x_snd
constructor <;> intro h
· rw [mem_graph_iff] at h
rcases h with ⟨y, hy, h⟩
rw [LinearPMap.neg_apply] at h
rw [Submodule.mem_map]
simp only [mem_graph_iff, LinearMap.prodMap_apply, LinearMap.id_coe, id,
LinearMap.neg_apply, Prod.mk.inj_iff, Prod.exists, exists_exists_and_eq_and]
use x_fst, y, hy
rw [Submodule.mem_map] at h
rcases h with ⟨x', hx', h⟩
cases x'
simp only [LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.neg_apply,
Prod.mk.inj_iff] at h
rw [mem_graph_iff] at hx' ⊢
rcases hx' with ⟨y, hy, hx'⟩
use y
rw [← h.1, ← h.2]
simp [hy, hx']
theorem mem_graph_snd_inj (f : E →ₗ.[R] F) {x y : E} {x' y' : F} (hx : (x, x') ∈ f.graph)
(hy : (y, y') ∈ f.graph) (hxy : x = y) : x' = y' := by
rw [mem_graph_iff] at hx hy
rcases hx with ⟨x'', hx1, hx2⟩
rcases hy with ⟨y'', hy1, hy2⟩
simp only at hx1 hx2 hy1 hy2
rw [← hx1, ← hy1, SetLike.coe_eq_coe] at hxy
rw [← hx2, ← hy2, hxy]
theorem mem_graph_snd_inj' (f : E →ₗ.[R] F) {x y : E × F} (hx : x ∈ f.graph) (hy : y ∈ f.graph)
(hxy : x.1 = y.1) : x.2 = y.2 := by
cases x
cases y
exact f.mem_graph_snd_inj hx hy hxy
/-- The property that `f 0 = 0` in terms of the graph. -/
theorem graph_fst_eq_zero_snd (f : E →ₗ.[R] F) {x : E} {x' : F} (h : (x, x') ∈ f.graph)
(hx : x = 0) : x' = 0 :=
f.mem_graph_snd_inj h f.graph.zero_mem hx
theorem mem_domain_iff {f : E →ₗ.[R] F} {x : E} : x ∈ f.domain ↔ ∃ y : F, (x, y) ∈ f.graph := by
constructor <;> intro h
· use f ⟨x, h⟩
exact f.mem_graph ⟨x, h⟩
cases' h with y h
rw [mem_graph_iff] at h
cases' h with x' h
simp only at h
rw [← h.1]
simp
theorem mem_domain_of_mem_graph {f : E →ₗ.[R] F} {x : E} {y : F} (h : (x, y) ∈ f.graph) :
x ∈ f.domain := by
rw [mem_domain_iff]
exact ⟨y, h⟩
theorem image_iff {f : E →ₗ.[R] F} {x : E} {y : F} (hx : x ∈ f.domain) :
y = f ⟨x, hx⟩ ↔ (x, y) ∈ f.graph := by
rw [mem_graph_iff]
constructor <;> intro h
· use ⟨x, hx⟩
simp [h]
rcases h with ⟨⟨x', hx'⟩, ⟨h1, h2⟩⟩
simp only [Submodule.coe_mk] at h1 h2
simp only [← h2, h1]
theorem mem_range_iff {f : E →ₗ.[R] F} {y : F} : y ∈ Set.range f ↔ ∃ x : E, (x, y) ∈ f.graph := by
constructor <;> intro h
· rw [Set.mem_range] at h
rcases h with ⟨⟨x, hx⟩, h⟩
use x
rw [← h]
exact f.mem_graph ⟨x, hx⟩
cases' h with x h
rw [mem_graph_iff] at h
cases' h with x h
rw [Set.mem_range]
use x
simp only at h
rw [h.2]
theorem mem_domain_iff_of_eq_graph {f g : E →ₗ.[R] F} (h : f.graph = g.graph) {x : E} :
x ∈ f.domain ↔ x ∈ g.domain := by simp_rw [mem_domain_iff, h]
theorem le_of_le_graph {f g : E →ₗ.[R] F} (h : f.graph ≤ g.graph) : f ≤ g := by
constructor
· intro x hx
rw [mem_domain_iff] at hx ⊢
cases' hx with y hx
use y
exact h hx
rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy
rw [image_iff]
refine h ?_
simp only [Submodule.coe_mk] at hxy
rw [hxy] at hx
rw [← image_iff hx]
simp [hxy]
theorem le_graph_of_le {f g : E →ₗ.[R] F} (h : f ≤ g) : f.graph ≤ g.graph := by
intro x hx
rw [mem_graph_iff] at hx ⊢
cases' hx with y hx
use ⟨y, h.1 y.2⟩
simp only [hx, Submodule.coe_mk, eq_self_iff_true, true_and_iff]
convert hx.2 using 1
refine (h.2 ?_).symm
simp only [hx.1, Submodule.coe_mk]
theorem le_graph_iff {f g : E →ₗ.[R] F} : f.graph ≤ g.graph ↔ f ≤ g :=
⟨le_of_le_graph, le_graph_of_le⟩
theorem eq_of_eq_graph {f g : E →ₗ.[R] F} (h : f.graph = g.graph) : f = g := by
ext
· exact mem_domain_iff_of_eq_graph h
· apply (le_of_le_graph h.le).2
assumption
end Graph
end LinearPMap
namespace Submodule
section SubmoduleToLinearPMap
theorem existsUnique_from_graph {g : Submodule R (E × F)}
(hg : ∀ {x : E × F} (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) {a : E}
(ha : a ∈ g.map (LinearMap.fst R E F)) : ∃! b : F, (a, b) ∈ g := by
refine exists_unique_of_exists_of_unique ?_ ?_
· convert ha
simp
intro y₁ y₂ hy₁ hy₂
have hy : ((0 : E), y₁ - y₂) ∈ g := by
convert g.sub_mem hy₁ hy₂
exact (sub_self _).symm
exact sub_eq_zero.mp (hg hy (by simp))
/-- Auxiliary definition to unfold the existential quantifier. -/
noncomputable def valFromGraph {g : Submodule R (E × F)}
(hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) {a : E}
(ha : a ∈ g.map (LinearMap.fst R E F)) : F :=
(ExistsUnique.exists (existsUnique_from_graph @hg ha)).choose
theorem valFromGraph_mem {g : Submodule R (E × F)}
(hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) {a : E}
(ha : a ∈ g.map (LinearMap.fst R E F)) : (a, valFromGraph hg ha) ∈ g :=
(ExistsUnique.exists (existsUnique_from_graph @hg ha)).choose_spec
/-- Define a `LinearMap` from its graph.
Helper definition for `LinearPMap`. -/
noncomputable def toLinearPMapAux (g : Submodule R (E × F))
(hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) :
g.map (LinearMap.fst R E F) →ₗ[R] F where
toFun := fun x => valFromGraph hg x.2
map_add' := fun v w => by
have hadd := (g.map (LinearMap.fst R E F)).add_mem v.2 w.2
have hvw := valFromGraph_mem hg hadd
have hvw' := g.add_mem (valFromGraph_mem hg v.2) (valFromGraph_mem hg w.2)
rw [Prod.mk_add_mk] at hvw'
exact (existsUnique_from_graph @hg hadd).unique hvw hvw'
map_smul' := fun a v => by
have hsmul := (g.map (LinearMap.fst R E F)).smul_mem a v.2
have hav := valFromGraph_mem hg hsmul
have hav' := g.smul_mem a (valFromGraph_mem hg v.2)
rw [Prod.smul_mk] at hav'
exact (existsUnique_from_graph @hg hsmul).unique hav hav'
open scoped Classical in
/-- Define a `LinearPMap` from its graph.
In the case that the submodule is not a graph of a `LinearPMap` then the underlying linear map
is just the zero map. -/
noncomputable def toLinearPMap (g : Submodule R (E × F)) : E →ₗ.[R] F where
domain := g.map (LinearMap.fst R E F)
toFun := if hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0 then
g.toLinearPMapAux hg else 0
theorem toLinearPMap_domain (g : Submodule R (E × F)) :
g.toLinearPMap.domain = g.map (LinearMap.fst R E F) := rfl
theorem toLinearPMap_apply_aux {g : Submodule R (E × F)}
(hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0)
(x : g.map (LinearMap.fst R E F)) :
g.toLinearPMap x = valFromGraph hg x.2 := by
classical
change (if hg : _ then g.toLinearPMapAux hg else 0) x = _
rw [dif_pos]
· rfl
· exact hg
theorem mem_graph_toLinearPMap {g : Submodule R (E × F)}
(hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0)
(x : g.map (LinearMap.fst R E F)) : (x.val, g.toLinearPMap x) ∈ g := by
rw [toLinearPMap_apply_aux hg]
exact valFromGraph_mem hg x.2
@[simp]
theorem toLinearPMap_graph_eq (g : Submodule R (E × F))
(hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) :
g.toLinearPMap.graph = g := by
ext x
constructor <;> intro hx
· rw [LinearPMap.mem_graph_iff] at hx
rcases hx with ⟨y, hx1, hx2⟩
convert g.mem_graph_toLinearPMap hg y using 1
exact Prod.ext hx1.symm hx2.symm
rw [LinearPMap.mem_graph_iff]
cases' x with x_fst x_snd
have hx_fst : x_fst ∈ g.map (LinearMap.fst R E F) := by
simp only [mem_map, LinearMap.fst_apply, Prod.exists, exists_and_right, exists_eq_right]
exact ⟨x_snd, hx⟩
refine ⟨⟨x_fst, hx_fst⟩, Subtype.coe_mk x_fst hx_fst, ?_⟩
rw [toLinearPMap_apply_aux hg]
exact (existsUnique_from_graph @hg hx_fst).unique (valFromGraph_mem hg hx_fst) hx
theorem toLinearPMap_range (g : Submodule R (E × F))
(hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) :
LinearMap.range g.toLinearPMap.toFun = g.map (LinearMap.snd R E F) := by
rwa [← LinearPMap.graph_map_snd_eq_range, toLinearPMap_graph_eq]
end SubmoduleToLinearPMap
end Submodule
namespace LinearPMap
section inverse
/-- The inverse of a `LinearPMap`. -/
noncomputable def inverse (f : E →ₗ.[R] F) : F →ₗ.[R] E :=
(f.graph.map (LinearEquiv.prodComm R E F)).toLinearPMap
variable {f : E →ₗ.[R] F}
theorem inverse_domain : (inverse f).domain = LinearMap.range f.toFun := by
rw [inverse, Submodule.toLinearPMap_domain, ← graph_map_snd_eq_range,
← LinearEquiv.fst_comp_prodComm, Submodule.map_comp]
rfl
variable (hf : LinearMap.ker f.toFun = ⊥)
/-- The graph of the inverse generates a `LinearPMap`. -/
theorem mem_inverse_graph_snd_eq_zero (x : F × E)
(hv : x ∈ (graph f).map (LinearEquiv.prodComm R E F))
(hv' : x.fst = 0) : x.snd = 0 := by
simp only [Submodule.mem_map, mem_graph_iff, Subtype.exists, exists_and_left, exists_eq_left,
LinearEquiv.prodComm_apply, Prod.exists, Prod.swap_prod_mk] at hv
rcases hv with ⟨a, b, ⟨ha, h1⟩, ⟨h2, h3⟩⟩
simp only at hv' ⊢
rw [hv'] at h1
rw [LinearMap.ker_eq_bot'] at hf
specialize hf ⟨a, ha⟩ h1
simp only [Submodule.mk_eq_zero] at hf
exact hf
theorem inverse_graph : (inverse f).graph = f.graph.map (LinearEquiv.prodComm R E F) := by
rw [inverse, Submodule.toLinearPMap_graph_eq _ (mem_inverse_graph_snd_eq_zero hf)]
theorem inverse_range : LinearMap.range (inverse f).toFun = f.domain := by
rw [inverse, Submodule.toLinearPMap_range _ (mem_inverse_graph_snd_eq_zero hf),
← graph_map_fst_eq_domain, ← LinearEquiv.snd_comp_prodComm, Submodule.map_comp]
rfl
theorem mem_inverse_graph (x : f.domain) : (f x, (x : E)) ∈ (inverse f).graph := by
simp only [inverse_graph hf, Submodule.mem_map, mem_graph_iff, Subtype.exists, exists_and_left,
exists_eq_left, LinearEquiv.prodComm_apply, Prod.exists, Prod.swap_prod_mk, Prod.mk.injEq]
exact ⟨(x : E), f x, ⟨x.2, Eq.refl _⟩, Eq.refl _, Eq.refl _⟩
theorem inverse_apply_eq {y : (inverse f).domain} {x : f.domain} (hxy : f x = y) :
(inverse f) y = x := by
have := mem_inverse_graph hf x
simp only [mem_graph_iff, Subtype.exists, exists_and_left, exists_eq_left] at this
rcases this with ⟨hx, h⟩
rw [← h]
congr
simp only [hxy, Subtype.coe_eta]
end inverse
end LinearPMap
|
LinearAlgebra\Orientation.lean | /-
Copyright (c) 2021 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.LinearAlgebra.Ray
import Mathlib.LinearAlgebra.Determinant
/-!
# Orientations of modules
This file defines orientations of modules.
## Main definitions
* `Orientation` is a type synonym for `Module.Ray` for the case where the module is that of
alternating maps from a module to its underlying ring. An orientation may be associated with an
alternating map or with a basis.
* `Module.Oriented` is a type class for a choice of orientation of a module that is considered
the positive orientation.
## Implementation notes
`Orientation` is defined for an arbitrary index type, but the main intended use case is when
that index type is a `Fintype` and there exists a basis of the same cardinality.
## References
* https://en.wikipedia.org/wiki/Orientation_(vector_space)
-/
noncomputable section
section OrderedCommSemiring
variable (R : Type*) [StrictOrderedCommSemiring R]
variable (M : Type*) [AddCommMonoid M] [Module R M]
variable {N : Type*} [AddCommMonoid N] [Module R N]
variable (ι ι' : Type*)
/-- An orientation of a module, intended to be used when `ι` is a `Fintype` with the same
cardinality as a basis. -/
abbrev Orientation := Module.Ray R (M [⋀^ι]→ₗ[R] R)
/-- A type class fixing an orientation of a module. -/
class Module.Oriented where
/-- Fix a positive orientation. -/
positiveOrientation : Orientation R M ι
export Module.Oriented (positiveOrientation)
variable {R M}
/-- An equivalence between modules implies an equivalence between orientations. -/
def Orientation.map (e : M ≃ₗ[R] N) : Orientation R M ι ≃ Orientation R N ι :=
Module.Ray.map <| AlternatingMap.domLCongr R R ι R e
@[simp]
theorem Orientation.map_apply (e : M ≃ₗ[R] N) (v : M [⋀^ι]→ₗ[R] R) (hv : v ≠ 0) :
Orientation.map ι e (rayOfNeZero _ v hv) =
rayOfNeZero _ (v.compLinearMap e.symm) (mt (v.compLinearEquiv_eq_zero_iff e.symm).mp hv) :=
rfl
@[simp]
theorem Orientation.map_refl : (Orientation.map ι <| LinearEquiv.refl R M) = Equiv.refl _ := by
rw [Orientation.map, AlternatingMap.domLCongr_refl, Module.Ray.map_refl]
@[simp]
theorem Orientation.map_symm (e : M ≃ₗ[R] N) :
(Orientation.map ι e).symm = Orientation.map ι e.symm := rfl
section Reindex
variable (R M) {ι ι'}
/-- An equivalence between indices implies an equivalence between orientations. -/
def Orientation.reindex (e : ι ≃ ι') : Orientation R M ι ≃ Orientation R M ι' :=
Module.Ray.map <| AlternatingMap.domDomCongrₗ R e
@[simp]
theorem Orientation.reindex_apply (e : ι ≃ ι') (v : M [⋀^ι]→ₗ[R] R) (hv : v ≠ 0) :
Orientation.reindex R M e (rayOfNeZero _ v hv) =
rayOfNeZero _ (v.domDomCongr e) (mt (v.domDomCongr_eq_zero_iff e).mp hv) :=
rfl
@[simp]
theorem Orientation.reindex_refl : (Orientation.reindex R M <| Equiv.refl ι) = Equiv.refl _ := by
rw [Orientation.reindex, AlternatingMap.domDomCongrₗ_refl, Module.Ray.map_refl]
@[simp]
theorem Orientation.reindex_symm (e : ι ≃ ι') :
(Orientation.reindex R M e).symm = Orientation.reindex R M e.symm :=
rfl
end Reindex
/-- A module is canonically oriented with respect to an empty index type. -/
instance (priority := 100) IsEmpty.oriented [IsEmpty ι] : Module.Oriented R M ι where
positiveOrientation :=
rayOfNeZero R (AlternatingMap.constLinearEquivOfIsEmpty 1) <|
AlternatingMap.constLinearEquivOfIsEmpty.injective.ne (by exact one_ne_zero)
@[simp]
theorem Orientation.map_positiveOrientation_of_isEmpty [IsEmpty ι] (f : M ≃ₗ[R] N) :
Orientation.map ι f positiveOrientation = positiveOrientation := rfl
@[simp]
theorem Orientation.map_of_isEmpty [IsEmpty ι] (x : Orientation R M ι) (f : M ≃ₗ[R] M) :
Orientation.map ι f x = x := by
induction' x using Module.Ray.ind with g hg
rw [Orientation.map_apply]
congr
ext i
rw [AlternatingMap.compLinearMap_apply]
congr
simp only [LinearEquiv.coe_coe, eq_iff_true_of_subsingleton]
end OrderedCommSemiring
section OrderedCommRing
variable {R : Type*} [StrictOrderedCommRing R]
variable {M N : Type*} [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N]
@[simp]
protected theorem Orientation.map_neg {ι : Type*} (f : M ≃ₗ[R] N) (x : Orientation R M ι) :
Orientation.map ι f (-x) = -Orientation.map ι f x :=
Module.Ray.map_neg _ x
@[simp]
protected theorem Orientation.reindex_neg {ι ι' : Type*} (e : ι ≃ ι') (x : Orientation R M ι) :
Orientation.reindex R M e (-x) = -Orientation.reindex R M e x :=
Module.Ray.map_neg _ x
namespace Basis
variable {ι ι' : Type*}
/-- The value of `Orientation.map` when the index type has the cardinality of a basis, in terms
of `f.det`. -/
theorem map_orientation_eq_det_inv_smul [Finite ι] (e : Basis ι R M) (x : Orientation R M ι)
(f : M ≃ₗ[R] M) : Orientation.map ι f x = (LinearEquiv.det f)⁻¹ • x := by
cases nonempty_fintype ι
letI := Classical.decEq ι
induction' x using Module.Ray.ind with g hg
rw [Orientation.map_apply, smul_rayOfNeZero, ray_eq_iff, Units.smul_def,
(g.compLinearMap f.symm).eq_smul_basis_det e, g.eq_smul_basis_det e,
AlternatingMap.compLinearMap_apply, AlternatingMap.smul_apply,
show (fun i ↦ (LinearEquiv.symm f).toLinearMap (e i)) = (LinearEquiv.symm f).toLinearMap ∘ e
by rfl, Basis.det_comp, Basis.det_self, mul_one, smul_eq_mul, mul_comm, mul_smul,
LinearEquiv.coe_inv_det]
variable [Fintype ι] [DecidableEq ι] [Fintype ι'] [DecidableEq ι']
/-- The orientation given by a basis. -/
protected def orientation (e : Basis ι R M) : Orientation R M ι :=
rayOfNeZero R _ e.det_ne_zero
theorem orientation_map (e : Basis ι R M) (f : M ≃ₗ[R] N) :
(e.map f).orientation = Orientation.map ι f e.orientation := by
simp_rw [Basis.orientation, Orientation.map_apply, Basis.det_map']
theorem orientation_reindex (e : Basis ι R M) (eι : ι ≃ ι') :
(e.reindex eι).orientation = Orientation.reindex R M eι e.orientation := by
simp_rw [Basis.orientation, Orientation.reindex_apply, Basis.det_reindex']
/-- The orientation given by a basis derived using `units_smul`, in terms of the product of those
units. -/
theorem orientation_unitsSMul (e : Basis ι R M) (w : ι → Units R) :
(e.unitsSMul w).orientation = (∏ i, w i)⁻¹ • e.orientation := by
rw [Basis.orientation, Basis.orientation, smul_rayOfNeZero, ray_eq_iff,
e.det.eq_smul_basis_det (e.unitsSMul w), det_unitsSMul_self, Units.smul_def, smul_smul]
norm_cast
simp only [mul_left_inv, Units.val_one, one_smul]
exact SameRay.rfl
@[simp]
theorem orientation_isEmpty [IsEmpty ι] (b : Basis ι R M) :
b.orientation = positiveOrientation := by
rw [Basis.orientation]
congr
exact b.det_isEmpty
end Basis
end OrderedCommRing
section LinearOrderedCommRing
variable {R : Type*} [LinearOrderedCommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable {ι : Type*}
namespace Orientation
/-- A module `M` over a linearly ordered commutative ring has precisely two "orientations" with
respect to an empty index type. (Note that these are only orientations of `M` of in the conventional
mathematical sense if `M` is zero-dimensional.) -/
theorem eq_or_eq_neg_of_isEmpty [IsEmpty ι] (o : Orientation R M ι) :
o = positiveOrientation ∨ o = -positiveOrientation := by
induction' o using Module.Ray.ind with x hx
dsimp [positiveOrientation]
simp only [ray_eq_iff, sameRay_neg_swap]
rw [sameRay_or_sameRay_neg_iff_not_linearIndependent]
intro h
set f : (M [⋀^ι]→ₗ[R] R) ≃ₗ[R] R := AlternatingMap.constLinearEquivOfIsEmpty.symm
have H : LinearIndependent R ![f x, 1] := by
convert h.map' f.toLinearMap f.ker
ext i
fin_cases i <;> simp [f]
rw [linearIndependent_iff'] at H
simpa using H Finset.univ ![1, -f x] (by simp [Fin.sum_univ_succ]) 0 (by simp)
end Orientation
namespace Basis
variable [Fintype ι] [DecidableEq ι]
/-- The orientations given by two bases are equal if and only if the determinant of one basis
with respect to the other is positive. -/
theorem orientation_eq_iff_det_pos (e₁ e₂ : Basis ι R M) :
e₁.orientation = e₂.orientation ↔ 0 < e₁.det e₂ :=
calc
e₁.orientation = e₂.orientation ↔ SameRay R e₁.det e₂.det := ray_eq_iff _ _
_ ↔ SameRay R (e₁.det e₂ • e₂.det) e₂.det := by rw [← e₁.det.eq_smul_basis_det e₂]
_ ↔ 0 < e₁.det e₂ := sameRay_smul_left_iff_of_ne e₂.det_ne_zero (e₁.isUnit_det e₂).ne_zero
/-- Given a basis, any orientation equals the orientation given by that basis or its negation. -/
theorem orientation_eq_or_eq_neg (e : Basis ι R M) (x : Orientation R M ι) :
x = e.orientation ∨ x = -e.orientation := by
induction' x using Module.Ray.ind with x hx
rw [← x.map_basis_ne_zero_iff e] at hx
rwa [Basis.orientation, ray_eq_iff, neg_rayOfNeZero, ray_eq_iff, x.eq_smul_basis_det e,
sameRay_neg_smul_left_iff_of_ne e.det_ne_zero hx, sameRay_smul_left_iff_of_ne e.det_ne_zero hx,
lt_or_lt_iff_ne, ne_comm]
/-- Given a basis, an orientation equals the negation of that given by that basis if and only
if it does not equal that given by that basis. -/
theorem orientation_ne_iff_eq_neg (e : Basis ι R M) (x : Orientation R M ι) :
x ≠ e.orientation ↔ x = -e.orientation :=
⟨fun h => (e.orientation_eq_or_eq_neg x).resolve_left h, fun h =>
h.symm ▸ (Module.Ray.ne_neg_self e.orientation).symm⟩
/-- Composing a basis with a linear equiv gives the same orientation if and only if the
determinant is positive. -/
theorem orientation_comp_linearEquiv_eq_iff_det_pos (e : Basis ι R M) (f : M ≃ₗ[R] M) :
(e.map f).orientation = e.orientation ↔ 0 < LinearMap.det (f : M →ₗ[R] M) := by
rw [orientation_map, e.map_orientation_eq_det_inv_smul, units_inv_smul, units_smul_eq_self_iff,
LinearEquiv.coe_det]
/-- Composing a basis with a linear equiv gives the negation of that orientation if and only if
the determinant is negative. -/
theorem orientation_comp_linearEquiv_eq_neg_iff_det_neg (e : Basis ι R M) (f : M ≃ₗ[R] M) :
(e.map f).orientation = -e.orientation ↔ LinearMap.det (f : M →ₗ[R] M) < 0 := by
rw [orientation_map, e.map_orientation_eq_det_inv_smul, units_inv_smul, units_smul_eq_neg_iff,
LinearEquiv.coe_det]
/-- Negating a single basis vector (represented using `units_smul`) negates the corresponding
orientation. -/
@[simp]
theorem orientation_neg_single (e : Basis ι R M) (i : ι) :
(e.unitsSMul (Function.update 1 i (-1))).orientation = -e.orientation := by
rw [orientation_unitsSMul, Finset.prod_update_of_mem (Finset.mem_univ _)]
simp
/-- Given a basis and an orientation, return a basis giving that orientation: either the original
basis, or one constructed by negating a single (arbitrary) basis vector. -/
def adjustToOrientation [Nonempty ι] (e : Basis ι R M) (x : Orientation R M ι) :
Basis ι R M :=
haveI := Classical.decEq (Orientation R M ι)
if e.orientation = x then e else e.unitsSMul (Function.update 1 (Classical.arbitrary ι) (-1))
/-- `adjust_to_orientation` gives a basis with the required orientation. -/
@[simp]
theorem orientation_adjustToOrientation [Nonempty ι] (e : Basis ι R M)
(x : Orientation R M ι) : (e.adjustToOrientation x).orientation = x := by
rw [adjustToOrientation]
split_ifs with h
· exact h
· rw [orientation_neg_single, eq_comm, ← orientation_ne_iff_eq_neg, ne_comm]
exact h
/-- Every basis vector from `adjust_to_orientation` is either that from the original basis or its
negation. -/
theorem adjustToOrientation_apply_eq_or_eq_neg [Nonempty ι] (e : Basis ι R M)
(x : Orientation R M ι) (i : ι) :
e.adjustToOrientation x i = e i ∨ e.adjustToOrientation x i = -e i := by
rw [adjustToOrientation]
split_ifs with h
· simp
· by_cases hi : i = Classical.arbitrary ι <;> simp [unitsSMul_apply, hi]
theorem det_adjustToOrientation [Nonempty ι] (e : Basis ι R M)
(x : Orientation R M ι) :
(e.adjustToOrientation x).det = e.det ∨ (e.adjustToOrientation x).det = -e.det := by
dsimp [Basis.adjustToOrientation]
split_ifs
· left
rfl
· right
simp only [e.det_unitsSMul, ne_eq, Finset.mem_univ, Finset.prod_update_of_mem, not_true,
Pi.one_apply, Finset.prod_const_one, mul_one, inv_neg', inv_one, Units.val_neg, Units.val_one]
ext
simp
@[simp]
theorem abs_det_adjustToOrientation [Nonempty ι] (e : Basis ι R M)
(x : Orientation R M ι) (v : ι → M) : |(e.adjustToOrientation x).det v| = |e.det v| := by
cases' e.det_adjustToOrientation x with h h <;> simp [h]
end Basis
end LinearOrderedCommRing
section LinearOrderedField
variable {R : Type*} [LinearOrderedField R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable {ι : Type*}
namespace Orientation
variable [Fintype ι] [_i : FiniteDimensional R M]
open FiniteDimensional
/-- If the index type has cardinality equal to the finite dimension, any two orientations are
equal or negations. -/
theorem eq_or_eq_neg (x₁ x₂ : Orientation R M ι) (h : Fintype.card ι = finrank R M) :
x₁ = x₂ ∨ x₁ = -x₂ := by
have e := (finBasis R M).reindex (Fintype.equivFinOfCardEq h).symm
letI := Classical.decEq ι
-- Porting note: this needs to be made explicit for the simp below
have orientation_neg_neg :
∀ f : Basis ι R M, - -Basis.orientation f = Basis.orientation f := by
#adaptation_note
/-- `set_option maxSynthPendingDepth 2` required after https://github.com/leanprover/lean4/pull/4119 -/
set_option maxSynthPendingDepth 2 in simp
rcases e.orientation_eq_or_eq_neg x₁ with (h₁ | h₁) <;>
rcases e.orientation_eq_or_eq_neg x₂ with (h₂ | h₂) <;> simp [h₁, h₂, orientation_neg_neg]
/-- If the index type has cardinality equal to the finite dimension, an orientation equals the
negation of another orientation if and only if they are not equal. -/
theorem ne_iff_eq_neg (x₁ x₂ : Orientation R M ι) (h : Fintype.card ι = finrank R M) :
x₁ ≠ x₂ ↔ x₁ = -x₂ :=
⟨fun hn => (eq_or_eq_neg x₁ x₂ h).resolve_left hn, fun he =>
he.symm ▸ (Module.Ray.ne_neg_self x₂).symm⟩
/-- The value of `Orientation.map` when the index type has cardinality equal to the finite
dimension, in terms of `f.det`. -/
theorem map_eq_det_inv_smul (x : Orientation R M ι) (f : M ≃ₗ[R] M)
(h : Fintype.card ι = finrank R M) : Orientation.map ι f x = (LinearEquiv.det f)⁻¹ • x :=
haveI e := (finBasis R M).reindex (Fintype.equivFinOfCardEq h).symm
e.map_orientation_eq_det_inv_smul x f
/-- If the index type has cardinality equal to the finite dimension, composing an alternating
map with the same linear equiv on each argument gives the same orientation if and only if the
determinant is positive. -/
theorem map_eq_iff_det_pos (x : Orientation R M ι) (f : M ≃ₗ[R] M)
(h : Fintype.card ι = finrank R M) :
Orientation.map ι f x = x ↔ 0 < LinearMap.det (f : M →ₗ[R] M) := by
cases isEmpty_or_nonempty ι
· have H : finrank R M = 0 := h.symm.trans Fintype.card_eq_zero
simp [LinearMap.det_eq_one_of_finrank_eq_zero H]
rw [map_eq_det_inv_smul _ _ h, units_inv_smul, units_smul_eq_self_iff, LinearEquiv.coe_det]
/-- If the index type has cardinality equal to the finite dimension, composing an alternating
map with the same linear equiv on each argument gives the negation of that orientation if and
only if the determinant is negative. -/
theorem map_eq_neg_iff_det_neg (x : Orientation R M ι) (f : M ≃ₗ[R] M)
(h : Fintype.card ι = finrank R M) :
Orientation.map ι f x = -x ↔ LinearMap.det (f : M →ₗ[R] M) < 0 := by
cases isEmpty_or_nonempty ι
· have H : finrank R M = 0 := h.symm.trans Fintype.card_eq_zero
simp [LinearMap.det_eq_one_of_finrank_eq_zero H, Module.Ray.ne_neg_self x]
have H : 0 < finrank R M := by
rw [← h]
exact Fintype.card_pos
haveI : FiniteDimensional R M := of_finrank_pos H
rw [map_eq_det_inv_smul _ _ h, units_inv_smul, units_smul_eq_neg_iff, LinearEquiv.coe_det]
/-- If the index type has cardinality equal to the finite dimension, a basis with the given
orientation. -/
def someBasis [Nonempty ι] [DecidableEq ι] (x : Orientation R M ι)
(h : Fintype.card ι = finrank R M) : Basis ι R M :=
((finBasis R M).reindex (Fintype.equivFinOfCardEq h).symm).adjustToOrientation x
/-- `some_basis` gives a basis with the required orientation. -/
@[simp]
theorem someBasis_orientation [Nonempty ι] [DecidableEq ι] (x : Orientation R M ι)
(h : Fintype.card ι = finrank R M) : (x.someBasis h).orientation = x :=
Basis.orientation_adjustToOrientation _ _
end Orientation
end LinearOrderedField
|
LinearAlgebra\PerfectPairing.lean | /-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.LinearAlgebra.Dual
/-!
# Perfect pairings of modules
A perfect pairing of two (left) modules may be defined either as:
1. A bilinear map `M × N → R` such that the induced maps `M → Dual R N` and `N → Dual R M` are both
bijective. It follows from this that both `M` and `N` are reflexive modules.
2. A linear equivalence `N ≃ Dual R M` for which `M` is reflexive. (It then follows that `N` is
reflexive.)
In this file we provide a `PerfectPairing` definition corresponding to 1 above, together with logic
to connect 1 and 2.
## Main definitions
* `PerfectPairing`
* `PerfectPairing.flip`
* `PerfectPairing.toDualLeft`
* `PerfectPairing.toDualRight`
* `LinearEquiv.flip`
* `LinearEquiv.isReflexive_of_equiv_dual_of_isReflexive`
* `LinearEquiv.toPerfectPairing`
-/
open Function Module
variable (R M N : Type*) [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
/-- A perfect pairing of two (left) modules over a commutative ring. -/
structure PerfectPairing :=
toLin : M →ₗ[R] N →ₗ[R] R
bijectiveLeft : Bijective toLin
bijectiveRight : Bijective toLin.flip
attribute [nolint docBlame] PerfectPairing.toLin
variable {R M N}
namespace PerfectPairing
instance instFunLike : FunLike (PerfectPairing R M N) M (N →ₗ[R] R) where
coe f := f.toLin
coe_injective' x y h := by cases x; cases y; simpa using h
variable (p : PerfectPairing R M N)
/-- Given a perfect pairing between `M` and `N`, we may interchange the roles of `M` and `N`. -/
protected def flip : PerfectPairing R N M where
toLin := p.toLin.flip
bijectiveLeft := p.bijectiveRight
bijectiveRight := p.bijectiveLeft
@[simp] lemma flip_flip : p.flip.flip = p := rfl
/-- The linear equivalence from `M` to `Dual R N` induced by a perfect pairing. -/
noncomputable def toDualLeft : M ≃ₗ[R] Dual R N :=
LinearEquiv.ofBijective p.toLin p.bijectiveLeft
@[simp]
theorem toDualLeft_apply (a : M) : p.toDualLeft a = p a :=
rfl
@[simp]
theorem apply_toDualLeft_symm_apply (f : Dual R N) (x : N) : p (p.toDualLeft.symm f) x = f x := by
have h := LinearEquiv.apply_symm_apply p.toDualLeft f
rw [toDualLeft_apply] at h
exact congrFun (congrArg DFunLike.coe h) x
/-- The linear equivalence from `N` to `Dual R M` induced by a perfect pairing. -/
noncomputable def toDualRight : N ≃ₗ[R] Dual R M :=
toDualLeft p.flip
@[simp]
theorem toDualRight_apply (a : N) : p.toDualRight a = p.flip a :=
rfl
@[simp]
theorem apply_apply_toDualRight_symm (x : M) (f : Dual R M) :
(p x) (p.toDualRight.symm f) = f x := by
have h := LinearEquiv.apply_symm_apply p.toDualRight f
rw [toDualRight_apply] at h
exact congrFun (congrArg DFunLike.coe h) x
theorem toDualLeft_of_toDualRight_symm (x : M) (f : Dual R M) :
(p.toDualLeft x) (p.toDualRight.symm f) = f x := by
rw [@toDualLeft_apply]
exact apply_apply_toDualRight_symm p x f
theorem toDualRight_symm_toDualLeft (x : M) :
p.toDualRight.symm.dualMap (p.toDualLeft x) = Dual.eval R M x := by
ext f
simp only [LinearEquiv.dualMap_apply, Dual.eval_apply]
exact toDualLeft_of_toDualRight_symm p x f
theorem toDualRight_symm_comp_toDualLeft :
p.toDualRight.symm.dualMap ∘ₗ (p.toDualLeft : M →ₗ[R] Dual R N) = Dual.eval R M := by
ext1 x
exact p.toDualRight_symm_toDualLeft x
theorem bijective_toDualRight_symm_toDualLeft :
Bijective (fun x => p.toDualRight.symm.dualMap (p.toDualLeft x)) :=
Bijective.comp (LinearEquiv.bijective p.toDualRight.symm.dualMap)
(LinearEquiv.bijective p.toDualLeft)
theorem reflexive_left : IsReflexive R M where
bijective_dual_eval' := by
rw [← p.toDualRight_symm_comp_toDualLeft]
exact p.bijective_toDualRight_symm_toDualLeft
theorem reflexive_right : IsReflexive R N :=
p.flip.reflexive_left
end PerfectPairing
variable [IsReflexive R M]
/-- A reflexive module has a perfect pairing with its dual. -/
@[simps]
def IsReflexive.toPerfectPairingDual : PerfectPairing R (Dual R M) M where
toLin := LinearMap.id
bijectiveLeft := bijective_id
bijectiveRight := bijective_dual_eval R M
variable (e : N ≃ₗ[R] Dual R M)
namespace LinearEquiv
/-- For a reflexive module `M`, an equivalence `N ≃ₗ[R] Dual R M` naturally yields an equivalence
`M ≃ₗ[R] Dual R N`. Such equivalences are known as perfect pairings. -/
noncomputable def flip : M ≃ₗ[R] Dual R N :=
(evalEquiv R M).trans e.dualMap
@[simp] lemma coe_toLinearMap_flip : e.flip = (↑e : N →ₗ[R] Dual R M).flip := rfl
@[simp] lemma flip_apply (m : M) (n : N) : e.flip m n = e n m := rfl
lemma symm_flip : e.flip.symm = e.symm.dualMap.trans (evalEquiv R M).symm := rfl
lemma trans_dualMap_symm_flip : e.trans e.flip.symm.dualMap = Dual.eval R N := by
ext; simp [symm_flip]
/-- If `N` is in perfect pairing with `M`, then it is reflexive. -/
lemma isReflexive_of_equiv_dual_of_isReflexive : IsReflexive R N := by
constructor
rw [← trans_dualMap_symm_flip e]
exact LinearEquiv.bijective _
@[simp] lemma flip_flip (h : IsReflexive R N := isReflexive_of_equiv_dual_of_isReflexive e) :
e.flip.flip = e := by
ext; rfl
/-- If `M` is reflexive then a linear equivalence `N ≃ Dual R M` is a perfect pairing. -/
@[simps]
noncomputable def toPerfectPairing : PerfectPairing R N M where
toLin := e
bijectiveLeft := e.bijective
bijectiveRight := e.flip.bijective
end LinearEquiv
namespace Submodule
open LinearEquiv
@[simp]
lemma dualCoannihilator_map_linearEquiv_flip (p : Submodule R M) :
(p.map e.flip).dualCoannihilator = p.dualAnnihilator.map e.symm := by
ext; simp [LinearEquiv.symm_apply_eq, Submodule.mem_dualCoannihilator]
@[simp]
lemma map_dualAnnihilator_linearEquiv_flip_symm (p : Submodule R N) :
p.dualAnnihilator.map e.flip.symm = (p.map e).dualCoannihilator := by
have : IsReflexive R N := e.isReflexive_of_equiv_dual_of_isReflexive
rw [← dualCoannihilator_map_linearEquiv_flip, flip_flip]
@[simp]
lemma map_dualCoannihilator_linearEquiv_flip (p : Submodule R (Dual R M)) :
p.dualCoannihilator.map e.flip = (p.map e.symm).dualAnnihilator := by
have : IsReflexive R N := e.isReflexive_of_equiv_dual_of_isReflexive
suffices (p.map e.symm).dualAnnihilator.map e.flip.symm =
(p.dualCoannihilator.map e.flip).map e.flip.symm by
exact (Submodule.map_injective_of_injective e.flip.symm.injective this).symm
erw [← dualCoannihilator_map_linearEquiv_flip, flip_flip, ← map_comp, ← map_comp]
simp [-coe_toLinearMap_flip]
@[simp]
lemma dualAnnihilator_map_linearEquiv_flip_symm (p : Submodule R (Dual R N)) :
(p.map e.flip.symm).dualAnnihilator = p.dualCoannihilator.map e := by
have : IsReflexive R N := e.isReflexive_of_equiv_dual_of_isReflexive
rw [← map_dualCoannihilator_linearEquiv_flip, flip_flip]
end Submodule
|
LinearAlgebra\Pi.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Eric Wieser
-/
import Mathlib.Algebra.Group.Fin.Tuple
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.Module.Prod
import Mathlib.Algebra.Module.Submodule.Ker
import Mathlib.Algebra.Module.Equiv.Basic
import Mathlib.GroupTheory.GroupAction.BigOperators
import Mathlib.Logic.Equiv.Fin
/-!
# Pi types of modules
This file defines constructors for linear maps whose domains or codomains are pi types.
It contains theorems relating these to each other, as well as to `LinearMap.ker`.
## Main definitions
- pi types in the codomain:
- `LinearMap.pi`
- `LinearMap.single`
- pi types in the domain:
- `LinearMap.proj`
- `LinearMap.diag`
-/
universe u v w x y z u' v' w' x' y'
variable {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'}
variable {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x} {ι' : Type x'}
open Function Submodule
namespace LinearMap
universe i
variable [Semiring R] [AddCommMonoid M₂] [Module R M₂] [AddCommMonoid M₃] [Module R M₃]
{φ : ι → Type i} [(i : ι) → AddCommMonoid (φ i)] [(i : ι) → Module R (φ i)]
/-- `pi` construction for linear functions. From a family of linear functions it produces a linear
function into a family of modules. -/
def pi (f : (i : ι) → M₂ →ₗ[R] φ i) : M₂ →ₗ[R] (i : ι) → φ i :=
{ Pi.addHom fun i => (f i).toAddHom with
toFun := fun c i => f i c
map_smul' := fun _ _ => funext fun i => (f i).map_smul _ _ }
@[simp]
theorem pi_apply (f : (i : ι) → M₂ →ₗ[R] φ i) (c : M₂) (i : ι) : pi f c i = f i c :=
rfl
theorem ker_pi (f : (i : ι) → M₂ →ₗ[R] φ i) : ker (pi f) = ⨅ i : ι, ker (f i) := by
ext c; simp [funext_iff]
theorem pi_eq_zero (f : (i : ι) → M₂ →ₗ[R] φ i) : pi f = 0 ↔ ∀ i, f i = 0 := by
simp only [LinearMap.ext_iff, pi_apply, funext_iff]
exact ⟨fun h a b => h b a, fun h a b => h b a⟩
theorem pi_zero : pi (fun i => 0 : (i : ι) → M₂ →ₗ[R] φ i) = 0 := by ext; rfl
theorem pi_comp (f : (i : ι) → M₂ →ₗ[R] φ i) (g : M₃ →ₗ[R] M₂) :
(pi f).comp g = pi fun i => (f i).comp g :=
rfl
/-- The projections from a family of modules are linear maps.
Note: known here as `LinearMap.proj`, this construction is in other categories called `eval`, for
example `Pi.evalMonoidHom`, `Pi.evalRingHom`. -/
def proj (i : ι) : ((i : ι) → φ i) →ₗ[R] φ i where
toFun := Function.eval i
map_add' _ _ := rfl
map_smul' _ _ := rfl
@[simp]
theorem coe_proj (i : ι) : ⇑(proj i : ((i : ι) → φ i) →ₗ[R] φ i) = Function.eval i :=
rfl
theorem proj_apply (i : ι) (b : (i : ι) → φ i) : (proj i : ((i : ι) → φ i) →ₗ[R] φ i) b = b i :=
rfl
theorem proj_pi (f : (i : ι) → M₂ →ₗ[R] φ i) (i : ι) : (proj i).comp (pi f) = f i :=
ext fun _ => rfl
theorem iInf_ker_proj : (⨅ i, ker (proj i : ((i : ι) → φ i) →ₗ[R] φ i) :
Submodule R ((i : ι) → φ i)) = ⊥ :=
bot_unique <|
SetLike.le_def.2 fun a h => by
simp only [mem_iInf, mem_ker, proj_apply] at h
exact (mem_bot _).2 (funext fun i => h i)
instance CompatibleSMul.pi (R S M N ι : Type*) [Semiring S]
[AddCommMonoid M] [AddCommMonoid N] [SMul R M] [SMul R N] [Module S M] [Module S N]
[LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul M (ι → N) R S where
map_smul f r m := by ext i; apply ((LinearMap.proj i).comp f).map_smul_of_tower
/-- Linear map between the function spaces `I → M₂` and `I → M₃`, induced by a linear map `f`
between `M₂` and `M₃`. -/
@[simps]
protected def compLeft (f : M₂ →ₗ[R] M₃) (I : Type*) : (I → M₂) →ₗ[R] I → M₃ :=
{ f.toAddMonoidHom.compLeft I with
toFun := fun h => f ∘ h
map_smul' := fun c h => by
ext x
exact f.map_smul' c (h x) }
theorem apply_single [AddCommMonoid M] [Module R M] [DecidableEq ι] (f : (i : ι) → φ i →ₗ[R] M)
(i j : ι) (x : φ i) : f j (Pi.single i x j) = (Pi.single i (f i x) : ι → M) j :=
Pi.apply_single (fun i => f i) (fun i => (f i).map_zero) _ _ _
/-- The `LinearMap` version of `AddMonoidHom.single` and `Pi.single`. -/
def single [DecidableEq ι] (i : ι) : φ i →ₗ[R] (i : ι) → φ i :=
{ AddMonoidHom.single φ i with
toFun := Pi.single i
map_smul' := Pi.single_smul i }
@[simp]
theorem coe_single [DecidableEq ι] (i : ι) : ⇑(single i : φ i →ₗ[R] (i : ι) → φ i) = Pi.single i :=
rfl
variable (R φ)
/-- The linear equivalence between linear functions on a finite product of modules and
families of functions on these modules. See note [bundled maps over different rings]. -/
@[simps symm_apply]
def lsum (S) [AddCommMonoid M] [Module R M] [Fintype ι] [DecidableEq ι] [Semiring S] [Module S M]
[SMulCommClass R S M] : ((i : ι) → φ i →ₗ[R] M) ≃ₗ[S] ((i : ι) → φ i) →ₗ[R] M where
toFun f := ∑ i : ι, (f i).comp (proj i)
invFun f i := f.comp (single i)
map_add' f g := by simp only [Pi.add_apply, add_comp, Finset.sum_add_distrib]
map_smul' c f := by simp only [Pi.smul_apply, smul_comp, Finset.smul_sum, RingHom.id_apply]
left_inv f := by
ext i x
simp [apply_single]
right_inv f := by
ext x
suffices f (∑ j, Pi.single j (x j)) = f x by simpa [apply_single]
rw [Finset.univ_sum_single]
@[simp]
theorem lsum_apply (S) [AddCommMonoid M] [Module R M] [Fintype ι] [DecidableEq ι] [Semiring S]
[Module S M] [SMulCommClass R S M] (f : (i : ι) → φ i →ₗ[R] M) :
lsum R φ S f = ∑ i : ι, (f i).comp (proj i) := rfl
@[simp high]
theorem lsum_single {ι R : Type*} [Fintype ι] [DecidableEq ι] [CommRing R] {M : ι → Type*}
[(i : ι) → AddCommGroup (M i)] [(i : ι) → Module R (M i)] :
LinearMap.lsum R M R LinearMap.single = LinearMap.id :=
LinearMap.ext fun x => by simp [Finset.univ_sum_single]
variable {R φ}
section Ext
variable [Finite ι] [DecidableEq ι] [AddCommMonoid M] [Module R M] {f g : ((i : ι) → φ i) →ₗ[R] M}
theorem pi_ext (h : ∀ i x, f (Pi.single i x) = g (Pi.single i x)) : f = g :=
toAddMonoidHom_injective <| AddMonoidHom.functions_ext _ _ _ h
theorem pi_ext_iff : f = g ↔ ∀ i x, f (Pi.single i x) = g (Pi.single i x) :=
⟨fun h _ _ => h ▸ rfl, pi_ext⟩
/-- This is used as the ext lemma instead of `LinearMap.pi_ext` for reasons explained in
note [partially-applied ext lemmas]. -/
@[ext]
theorem pi_ext' (h : ∀ i, f.comp (single i) = g.comp (single i)) : f = g := by
refine pi_ext fun i x => ?_
convert LinearMap.congr_fun (h i) x
end Ext
section
variable (R φ)
/-- If `I` and `J` are disjoint index sets, the product of the kernels of the `J`th projections of
`φ` is linearly equivalent to the product over `I`. -/
def iInfKerProjEquiv {I J : Set ι} [DecidablePred fun i => i ∈ I] (hd : Disjoint I J)
(hu : Set.univ ⊆ I ∪ J) :
(⨅ i ∈ J, ker (proj i : ((i : ι) → φ i) →ₗ[R] φ i) :
Submodule R ((i : ι) → φ i)) ≃ₗ[R] (i : I) → φ i := by
refine
LinearEquiv.ofLinear (pi fun i => (proj (i : ι)).comp (Submodule.subtype _))
(codRestrict _ (pi fun i => if h : i ∈ I then proj (⟨i, h⟩ : I) else 0) ?_) ?_ ?_
· intro b
simp only [mem_iInf, mem_ker, funext_iff, proj_apply, pi_apply]
intro j hjJ
have : j ∉ I := fun hjI => hd.le_bot ⟨hjI, hjJ⟩
rw [dif_neg this, zero_apply]
· simp only [pi_comp, comp_assoc, subtype_comp_codRestrict, proj_pi, Subtype.coe_prop]
ext b ⟨j, hj⟩
simp only [dif_pos, Function.comp_apply, Function.eval_apply, LinearMap.codRestrict_apply,
LinearMap.coe_comp, LinearMap.coe_proj, LinearMap.pi_apply, Submodule.subtype_apply,
Subtype.coe_prop]
rfl
· ext1 ⟨b, hb⟩
apply Subtype.ext
ext j
have hb : ∀ i ∈ J, b i = 0 := by
simpa only [mem_iInf, mem_ker, proj_apply] using (mem_iInf _).1 hb
simp only [comp_apply, pi_apply, id_apply, proj_apply, subtype_apply, codRestrict_apply]
split_ifs with h
· rfl
· exact (hb _ <| (hu trivial).resolve_left h).symm
end
section
variable [DecidableEq ι]
/-- `diag i j` is the identity map if `i = j`. Otherwise it is the constant 0 map. -/
def diag (i j : ι) : φ i →ₗ[R] φ j :=
@Function.update ι (fun j => φ i →ₗ[R] φ j) _ 0 i id j
theorem update_apply (f : (i : ι) → M₂ →ₗ[R] φ i) (c : M₂) (i j : ι) (b : M₂ →ₗ[R] φ i) :
(update f i b j) c = update (fun i => f i c) i (b c) j := by
by_cases h : j = i
· rw [h, update_same, update_same]
· rw [update_noteq h, update_noteq h]
end
/-- A linear map `f` applied to `x : ι → R` can be computed using the image under `f` of elements
of the canonical basis. -/
theorem pi_apply_eq_sum_univ [Fintype ι] [DecidableEq ι] (f : (ι → R) →ₗ[R] M₂) (x : ι → R) :
f x = ∑ i, x i • f fun j => if i = j then 1 else 0 := by
conv_lhs => rw [pi_eq_sum_univ x, map_sum]
refine Finset.sum_congr rfl (fun _ _ => ?_)
rw [map_smul]
end LinearMap
namespace Submodule
variable [Semiring R] {φ : ι → Type*} [(i : ι) → AddCommMonoid (φ i)] [(i : ι) → Module R (φ i)]
open LinearMap
/-- A version of `Set.pi` for submodules. Given an index set `I` and a family of submodules
`p : (i : ι) → Submodule R (φ i)`, `pi I s` is the submodule of dependent functions
`f : (i : ι) → φ i` such that `f i` belongs to `p a` whenever `i ∈ I`. -/
def pi (I : Set ι) (p : (i : ι) → Submodule R (φ i)) : Submodule R ((i : ι) → φ i) where
carrier := Set.pi I fun i => p i
zero_mem' i _ := (p i).zero_mem
add_mem' {_ _} hx hy i hi := (p i).add_mem (hx i hi) (hy i hi)
smul_mem' c _ hx i hi := (p i).smul_mem c (hx i hi)
variable {I : Set ι} {p q : (i : ι) → Submodule R (φ i)} {x : (i : ι) → φ i}
@[simp]
theorem mem_pi : x ∈ pi I p ↔ ∀ i ∈ I, x i ∈ p i :=
Iff.rfl
@[simp, norm_cast]
theorem coe_pi : (pi I p : Set ((i : ι) → φ i)) = Set.pi I fun i => p i :=
rfl
@[simp]
theorem pi_empty (p : (i : ι) → Submodule R (φ i)) : pi ∅ p = ⊤ :=
SetLike.coe_injective <| Set.empty_pi _
@[simp]
theorem pi_top (s : Set ι) : (pi s fun i : ι => (⊤ : Submodule R (φ i))) = ⊤ :=
SetLike.coe_injective <| Set.pi_univ _
theorem pi_mono {s : Set ι} (h : ∀ i ∈ s, p i ≤ q i) : pi s p ≤ pi s q :=
Set.pi_mono h
theorem biInf_comap_proj :
⨅ i ∈ I, comap (proj i : ((i : ι) → φ i) →ₗ[R] φ i) (p i) = pi I p := by
ext x
simp
theorem iInf_comap_proj :
⨅ i, comap (proj i : ((i : ι) → φ i) →ₗ[R] φ i) (p i) = pi Set.univ p := by
ext x
simp
theorem iSup_map_single [DecidableEq ι] [Finite ι] :
⨆ i, map (LinearMap.single i : φ i →ₗ[R] (i : ι) → φ i) (p i) = pi Set.univ p := by
cases nonempty_fintype ι
refine (iSup_le fun i => ?_).antisymm ?_
· rintro _ ⟨x, hx : x ∈ p i, rfl⟩ j -
rcases em (j = i) with (rfl | hj) <;> simp [*]
· intro x hx
rw [← Finset.univ_sum_single x]
exact sum_mem_iSup fun i => mem_map_of_mem (hx i trivial)
theorem le_comap_single_pi [DecidableEq ι] (p : (i : ι) → Submodule R (φ i)) {i} :
p i ≤ Submodule.comap (LinearMap.single i : φ i →ₗ[R] _) (Submodule.pi Set.univ p) := by
intro x hx
rw [Submodule.mem_comap, Submodule.mem_pi]
rintro j -
by_cases h : j = i
· rwa [h, LinearMap.coe_single, Pi.single_eq_same]
· rw [LinearMap.coe_single, Pi.single_eq_of_ne h]
exact (p j).zero_mem
end Submodule
namespace LinearEquiv
variable [Semiring R] {φ ψ χ : ι → Type*}
variable [(i : ι) → AddCommMonoid (φ i)] [(i : ι) → Module R (φ i)]
variable [(i : ι) → AddCommMonoid (ψ i)] [(i : ι) → Module R (ψ i)]
variable [(i : ι) → AddCommMonoid (χ i)] [(i : ι) → Module R (χ i)]
/-- Combine a family of linear equivalences into a linear equivalence of `pi`-types.
This is `Equiv.piCongrRight` as a `LinearEquiv` -/
def piCongrRight (e : (i : ι) → φ i ≃ₗ[R] ψ i) : ((i : ι) → φ i) ≃ₗ[R] (i : ι) → ψ i :=
{ AddEquiv.piCongrRight fun j => (e j).toAddEquiv with
toFun := fun f i => e i (f i)
invFun := fun f i => (e i).symm (f i)
map_smul' := fun c f => by ext; simp }
@[simp]
theorem piCongrRight_apply (e : (i : ι) → φ i ≃ₗ[R] ψ i) (f i) :
piCongrRight e f i = e i (f i) := rfl
@[simp]
theorem piCongrRight_refl : (piCongrRight fun j => refl R (φ j)) = refl _ _ :=
rfl
@[simp]
theorem piCongrRight_symm (e : (i : ι) → φ i ≃ₗ[R] ψ i) :
(piCongrRight e).symm = piCongrRight fun i => (e i).symm :=
rfl
@[simp]
theorem piCongrRight_trans (e : (i : ι) → φ i ≃ₗ[R] ψ i) (f : (i : ι) → ψ i ≃ₗ[R] χ i) :
(piCongrRight e).trans (piCongrRight f) = piCongrRight fun i => (e i).trans (f i) :=
rfl
variable (R φ)
/-- Transport dependent functions through an equivalence of the base space.
This is `Equiv.piCongrLeft'` as a `LinearEquiv`. -/
@[simps (config := { simpRhs := true })]
def piCongrLeft' (e : ι ≃ ι') : ((i' : ι) → φ i') ≃ₗ[R] (i : ι') → φ <| e.symm i :=
{ Equiv.piCongrLeft' φ e with
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
/-- Transporting dependent functions through an equivalence of the base,
expressed as a "simplification".
This is `Equiv.piCongrLeft` as a `LinearEquiv` -/
def piCongrLeft (e : ι' ≃ ι) : ((i' : ι') → φ (e i')) ≃ₗ[R] (i : ι) → φ i :=
(piCongrLeft' R φ e.symm).symm
/-- `Equiv.piCurry` as a `LinearEquiv`. -/
def piCurry {ι : Type*} {κ : ι → Type*} (α : ∀ i, κ i → Type*)
[∀ i k, AddCommMonoid (α i k)] [∀ i k, Module R (α i k)] :
(Π i : Sigma κ, α i.1 i.2) ≃ₗ[R] Π i j, α i j where
__ := Equiv.piCurry α
map_add' _ _ := rfl
map_smul' _ _ := rfl
@[simp] theorem piCurry_apply {ι : Type*} {κ : ι → Type*} (α : ∀ i, κ i → Type*)
[∀ i k, AddCommMonoid (α i k)] [∀ i k, Module R (α i k)]
(f : ∀ x : Σ i, κ i, α x.1 x.2) :
piCurry R α f = Sigma.curry f :=
rfl
@[simp] theorem piCurry_symm_apply {ι : Type*} {κ : ι → Type*} (α : ∀ i, κ i → Type*)
[∀ i k, AddCommMonoid (α i k)] [∀ i k, Module R (α i k)]
(f : ∀ a b, α a b) :
(piCurry R α).symm f = Sigma.uncurry f :=
rfl
/-- This is `Equiv.piOptionEquivProd` as a `LinearEquiv` -/
def piOptionEquivProd {ι : Type*} {M : Option ι → Type*} [(i : Option ι) → AddCommGroup (M i)]
[(i : Option ι) → Module R (M i)] :
((i : Option ι) → M i) ≃ₗ[R] M none × ((i : ι) → M (some i)) :=
{ Equiv.piOptionEquivProd with
map_add' := by simp [Function.funext_iff]
map_smul' := by simp [Function.funext_iff] }
variable (ι M) (S : Type*) [Fintype ι] [DecidableEq ι] [Semiring S] [AddCommMonoid M]
[Module R M] [Module S M] [SMulCommClass R S M]
/-- Linear equivalence between linear functions `Rⁿ → M` and `Mⁿ`. The spaces `Rⁿ` and `Mⁿ`
are represented as `ι → R` and `ι → M`, respectively, where `ι` is a finite type.
This as an `S`-linear equivalence, under the assumption that `S` acts on `M` commuting with `R`.
When `R` is commutative, we can take this to be the usual action with `S = R`.
Otherwise, `S = ℕ` shows that the equivalence is additive.
See note [bundled maps over different rings]. -/
def piRing : ((ι → R) →ₗ[R] M) ≃ₗ[S] ι → M :=
(LinearMap.lsum R (fun _ : ι => R) S).symm.trans
(piCongrRight fun _ => LinearMap.ringLmapEquivSelf R S M)
variable {ι R M}
@[simp]
theorem piRing_apply (f : (ι → R) →ₗ[R] M) (i : ι) : piRing R M ι S f i = f (Pi.single i 1) :=
rfl
@[simp]
theorem piRing_symm_apply (f : ι → M) (g : ι → R) : (piRing R M ι S).symm f g = ∑ i, g i • f i := by
simp [piRing, LinearMap.lsum_apply]
-- TODO additive version?
/-- `Equiv.sumArrowEquivProdArrow` as a linear equivalence.
-/
def sumArrowLequivProdArrow (α β R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] :
(α ⊕ β → M) ≃ₗ[R] (α → M) × (β → M) :=
{ Equiv.sumArrowEquivProdArrow α β
M with
map_add' := by
intro f g
ext <;> rfl
map_smul' := by
intro r f
ext <;> rfl }
@[simp]
theorem sumArrowLequivProdArrow_apply_fst {α β} (f : α ⊕ β → M) (a : α) :
(sumArrowLequivProdArrow α β R M f).1 a = f (Sum.inl a) :=
rfl
@[simp]
theorem sumArrowLequivProdArrow_apply_snd {α β} (f : α ⊕ β → M) (b : β) :
(sumArrowLequivProdArrow α β R M f).2 b = f (Sum.inr b) :=
rfl
@[simp]
theorem sumArrowLequivProdArrow_symm_apply_inl {α β} (f : α → M) (g : β → M) (a : α) :
((sumArrowLequivProdArrow α β R M).symm (f, g)) (Sum.inl a) = f a :=
rfl
@[simp]
theorem sumArrowLequivProdArrow_symm_apply_inr {α β} (f : α → M) (g : β → M) (b : β) :
((sumArrowLequivProdArrow α β R M).symm (f, g)) (Sum.inr b) = g b :=
rfl
/-- If `ι` has a unique element, then `ι → M` is linearly equivalent to `M`. -/
@[simps (config := { simpRhs := true, fullyApplied := false }) symm_apply]
def funUnique (ι R M : Type*) [Unique ι] [Semiring R] [AddCommMonoid M] [Module R M] :
(ι → M) ≃ₗ[R] M :=
{ Equiv.funUnique ι M with
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
@[simp]
theorem funUnique_apply (ι R M : Type*) [Unique ι] [Semiring R] [AddCommMonoid M] [Module R M] :
(funUnique ι R M : (ι → M) → M) = eval default := rfl
variable (R M)
/-- Linear equivalence between dependent functions `(i : Fin 2) → M i` and `M 0 × M 1`. -/
@[simps (config := { simpRhs := true, fullyApplied := false }) symm_apply]
def piFinTwo (M : Fin 2 → Type v)
[(i : Fin 2) → AddCommMonoid (M i)] [(i : Fin 2) → Module R (M i)] :
((i : Fin 2) → M i) ≃ₗ[R] M 0 × M 1 :=
{ piFinTwoEquiv M with
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
@[simp]
theorem piFinTwo_apply (M : Fin 2 → Type v)
[(i : Fin 2) → AddCommMonoid (M i)] [(i : Fin 2) → Module R (M i)] :
(piFinTwo R M : ((i : Fin 2) → M i) → M 0 × M 1) = fun f => (f 0, f 1) := rfl
/-- Linear equivalence between vectors in `M² = Fin 2 → M` and `M × M`. -/
@[simps! (config := .asFn)]
def finTwoArrow : (Fin 2 → M) ≃ₗ[R] M × M :=
{ finTwoArrowEquiv M, piFinTwo R fun _ => M with }
end LinearEquiv
section Extend
variable (R) {η : Type x} [Semiring R] (s : ι → η)
/-- `Function.extend s f 0` as a bundled linear map. -/
@[simps]
noncomputable def Function.ExtendByZero.linearMap : (ι → R) →ₗ[R] η → R :=
{ Function.ExtendByZero.hom R s with
toFun := fun f => Function.extend s f 0
map_smul' := fun r f => by simpa using Function.extend_smul r s f 0 }
end Extend
/-! ### Bundled versions of `Matrix.vecCons` and `Matrix.vecEmpty`
The idea of these definitions is to be able to define a map as `x ↦ ![f₁ x, f₂ x, f₃ x]`, where
`f₁ f₂ f₃` are already linear maps, as `f₁.vecCons <| f₂.vecCons <| f₃.vecCons <| vecEmpty`.
While the same thing could be achieved using `LinearMap.pi ![f₁, f₂, f₃]`, this is not
definitionally equal to the result using `LinearMap.vecCons`, as `Fin.cases` and function
application do not commute definitionally.
Versions for when `f₁ f₂ f₃` are bilinear maps are also provided.
-/
section Fin
section Semiring
variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable [Module R M] [Module R M₂] [Module R M₃]
/-- The linear map defeq to `Matrix.vecEmpty` -/
def LinearMap.vecEmpty : M →ₗ[R] Fin 0 → M₃ where
toFun _ := Matrix.vecEmpty
map_add' _ _ := Subsingleton.elim _ _
map_smul' _ _ := Subsingleton.elim _ _
@[simp]
theorem LinearMap.vecEmpty_apply (m : M) : (LinearMap.vecEmpty : M →ₗ[R] Fin 0 → M₃) m = ![] :=
rfl
/-- A linear map into `Fin n.succ → M₃` can be built out of a map into `M₃` and a map into
`Fin n → M₃`. -/
def LinearMap.vecCons {n} (f : M →ₗ[R] M₂) (g : M →ₗ[R] Fin n → M₂) : M →ₗ[R] Fin n.succ → M₂ where
toFun m := Matrix.vecCons (f m) (g m)
map_add' x y := by
simp only []
rw [f.map_add, g.map_add, Matrix.cons_add_cons (f x)]
map_smul' c x := by
simp only []
rw [f.map_smul, g.map_smul, RingHom.id_apply, Matrix.smul_cons c (f x)]
@[simp]
theorem LinearMap.vecCons_apply {n} (f : M →ₗ[R] M₂) (g : M →ₗ[R] Fin n → M₂) (m : M) :
f.vecCons g m = Matrix.vecCons (f m) (g m) :=
rfl
end Semiring
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable [Module R M] [Module R M₂] [Module R M₃]
/-- The empty bilinear map defeq to `Matrix.vecEmpty` -/
@[simps]
def LinearMap.vecEmpty₂ : M →ₗ[R] M₂ →ₗ[R] Fin 0 → M₃ where
toFun _ := LinearMap.vecEmpty
map_add' _ _ := LinearMap.ext fun _ => Subsingleton.elim _ _
map_smul' _ _ := LinearMap.ext fun _ => Subsingleton.elim _ _
/-- A bilinear map into `Fin n.succ → M₃` can be built out of a map into `M₃` and a map into
`Fin n → M₃` -/
@[simps]
def LinearMap.vecCons₂ {n} (f : M →ₗ[R] M₂ →ₗ[R] M₃) (g : M →ₗ[R] M₂ →ₗ[R] Fin n → M₃) :
M →ₗ[R] M₂ →ₗ[R] Fin n.succ → M₃ where
toFun m := LinearMap.vecCons (f m) (g m)
map_add' x y :=
LinearMap.ext fun z => by
simp only [f.map_add, g.map_add, LinearMap.add_apply, LinearMap.vecCons_apply,
Matrix.cons_add_cons (f x z)]
map_smul' r x := LinearMap.ext fun z => by simp [Matrix.smul_cons r (f x z)]
end CommSemiring
end Fin
|
LinearAlgebra\PID.lean | /-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.LinearAlgebra.Trace
import Mathlib.LinearAlgebra.FreeModule.PID
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
/-!
# Linear maps of modules with coefficients in a principal ideal domain
Since a submodule of a free module over a PID is free, certain constructions which are often
developed only for vector spaces may be generalised to any module with coefficients in a PID.
This file is a location for such results and exists to avoid making large parts of the linear
algebra import hierarchy have to depend on the theory of PIDs.
## Main results:
* `LinearMap.trace_restrict_eq_of_forall_mem`
-/
namespace LinearMap
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
[Module.Finite R M] [Module.Free R M]
/-- If a linear endomorphism of a (finite, free) module `M` takes values in a submodule `p ⊆ M`,
then the trace of its restriction to `p` is equal to its trace on `M`. -/
lemma trace_restrict_eq_of_forall_mem [IsDomain R] [IsPrincipalIdealRing R]
(p : Submodule R M) (f : M →ₗ[R] M)
(hf : ∀ x, f x ∈ p) (hf' : ∀ x ∈ p, f x ∈ p := fun x _ ↦ hf x) :
trace R p (f.restrict hf') = trace R M f := by
let ι := Module.Free.ChooseBasisIndex R M
obtain ⟨n, snf : Basis.SmithNormalForm p ι n⟩ := p.smithNormalForm (Module.Free.chooseBasis R M)
rw [trace_eq_matrix_trace R snf.bM, trace_eq_matrix_trace R snf.bN]
set A : Matrix (Fin n) (Fin n) R := toMatrix snf.bN snf.bN (f.restrict hf')
set B : Matrix ι ι R := toMatrix snf.bM snf.bM f
have aux : ∀ i, B i i ≠ 0 → i ∈ Set.range snf.f := fun i hi ↦ by
contrapose! hi; exact snf.repr_eq_zero_of_nmem_range ⟨_, (hf _)⟩ hi
change ∑ i, A i i = ∑ i, B i i
rw [← Finset.sum_filter_of_ne (p := fun j ↦ j ∈ Set.range snf.f) (by simpa using aux)]
simp [A]
end LinearMap
|
LinearAlgebra\PiTensorProduct.lean | /-
Copyright (c) 2020 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis, Eric Wieser
-/
import Mathlib.GroupTheory.Congruence.Basic
import Mathlib.LinearAlgebra.Multilinear.TensorProduct
import Mathlib.Tactic.AdaptationNote
/-!
# Tensor product of an indexed family of modules over commutative semirings
We define the tensor product of an indexed family `s : ι → Type*` of modules over commutative
semirings. We denote this space by `⨂[R] i, s i` and define it as `FreeAddMonoid (R × Π i, s i)`
quotiented by the appropriate equivalence relation. The treatment follows very closely that of the
binary tensor product in `LinearAlgebra/TensorProduct.lean`.
## Main definitions
* `PiTensorProduct R s` with `R` a commutative semiring and `s : ι → Type*` is the tensor product
of all the `s i`'s. This is denoted by `⨂[R] i, s i`.
* `tprod R f` with `f : Π i, s i` is the tensor product of the vectors `f i` over all `i : ι`.
This is bundled as a multilinear map from `Π i, s i` to `⨂[R] i, s i`.
* `liftAddHom` constructs an `AddMonoidHom` from `(⨂[R] i, s i)` to some space `F` from a
function `φ : (R × Π i, s i) → F` with the appropriate properties.
* `lift φ` with `φ : MultilinearMap R s E` is the corresponding linear map
`(⨂[R] i, s i) →ₗ[R] E`. This is bundled as a linear equivalence.
* `PiTensorProduct.reindex e` re-indexes the components of `⨂[R] i : ι, M` along `e : ι ≃ ι₂`.
* `PiTensorProduct.tmulEquiv` equivalence between a `TensorProduct` of `PiTensorProduct`s and
a single `PiTensorProduct`.
## Notations
* `⨂[R] i, s i` is defined as localized notation in locale `TensorProduct`.
* `⨂ₜ[R] i, f i` with `f : ∀ i, s i` is defined globally as the tensor product of all the `f i`'s.
## Implementation notes
* We define it via `FreeAddMonoid (R × Π i, s i)` with the `R` representing a "hidden" tensor
factor, rather than `FreeAddMonoid (Π i, s i)` to ensure that, if `ι` is an empty type,
the space is isomorphic to the base ring `R`.
* We have not restricted the index type `ι` to be a `Fintype`, as nothing we do here strictly
requires it. However, problems may arise in the case where `ι` is infinite; use at your own
caution.
* Instead of requiring `DecidableEq ι` as an argument to `PiTensorProduct` itself, we include it
as an argument in the constructors of the relation. A decidability instance still has to come
from somewhere due to the use of `Function.update`, but this hides it from the downstream user.
See the implementation notes for `MultilinearMap` for an extended discussion of this choice.
## TODO
* Define tensor powers, symmetric subspace, etc.
* API for the various ways `ι` can be split into subsets; connect this with the binary
tensor product.
* Include connection with holors.
* Port more of the API from the binary tensor product over to this case.
## Tags
multilinear, tensor, tensor product
-/
suppress_compilation
open Function
section Semiring
variable {ι ι₂ ι₃ : Type*}
variable {R : Type*} [CommSemiring R]
variable {R₁ R₂ : Type*}
variable {s : ι → Type*} [∀ i, AddCommMonoid (s i)] [∀ i, Module R (s i)]
variable {M : Type*} [AddCommMonoid M] [Module R M]
variable {E : Type*} [AddCommMonoid E] [Module R E]
variable {F : Type*} [AddCommMonoid F]
namespace PiTensorProduct
variable (R) (s)
/-- The relation on `FreeAddMonoid (R × Π i, s i)` that generates a congruence whose quotient is
the tensor product. -/
inductive Eqv : FreeAddMonoid (R × Π i, s i) → FreeAddMonoid (R × Π i, s i) → Prop
| of_zero : ∀ (r : R) (f : Π i, s i) (i : ι) (_ : f i = 0), Eqv (FreeAddMonoid.of (r, f)) 0
| of_zero_scalar : ∀ f : Π i, s i, Eqv (FreeAddMonoid.of (0, f)) 0
| of_add : ∀ (_ : DecidableEq ι) (r : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i),
Eqv (FreeAddMonoid.of (r, update f i m₁) + FreeAddMonoid.of (r, update f i m₂))
(FreeAddMonoid.of (r, update f i (m₁ + m₂)))
| of_add_scalar : ∀ (r r' : R) (f : Π i, s i),
Eqv (FreeAddMonoid.of (r, f) + FreeAddMonoid.of (r', f)) (FreeAddMonoid.of (r + r', f))
| of_smul : ∀ (_ : DecidableEq ι) (r : R) (f : Π i, s i) (i : ι) (r' : R),
Eqv (FreeAddMonoid.of (r, update f i (r' • f i))) (FreeAddMonoid.of (r' * r, f))
| add_comm : ∀ x y, Eqv (x + y) (y + x)
end PiTensorProduct
variable (R) (s)
/-- `PiTensorProduct R s` with `R` a commutative semiring and `s : ι → Type*` is the tensor
product of all the `s i`'s. This is denoted by `⨂[R] i, s i`. -/
def PiTensorProduct : Type _ :=
(addConGen (PiTensorProduct.Eqv R s)).Quotient
variable {R}
unsuppress_compilation in
/-- This enables the notation `⨂[R] i : ι, s i` for the pi tensor product `PiTensorProduct`,
given an indexed family of types `s : ι → Type*`. -/
scoped[TensorProduct] notation3:100"⨂["R"] "(...)", "r:(scoped f => PiTensorProduct R f) => r
open TensorProduct
namespace PiTensorProduct
section Module
instance : AddCommMonoid (⨂[R] i, s i) :=
{ (addConGen (PiTensorProduct.Eqv R s)).addMonoid with
add_comm := fun x y ↦
AddCon.induction_on₂ x y fun _ _ ↦
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.add_comm _ _ }
instance : Inhabited (⨂[R] i, s i) := ⟨0⟩
variable (R) {s}
/-- `tprodCoeff R r f` with `r : R` and `f : Π i, s i` is the tensor product of the vectors `f i`
over all `i : ι`, multiplied by the coefficient `r`. Note that this is meant as an auxiliary
definition for this file alone, and that one should use `tprod` defined below for most purposes. -/
def tprodCoeff (r : R) (f : Π i, s i) : ⨂[R] i, s i :=
AddCon.mk' _ <| FreeAddMonoid.of (r, f)
variable {R}
theorem zero_tprodCoeff (f : Π i, s i) : tprodCoeff R 0 f = 0 :=
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_scalar _
theorem zero_tprodCoeff' (z : R) (f : Π i, s i) (i : ι) (hf : f i = 0) : tprodCoeff R z f = 0 :=
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero _ _ i hf
theorem add_tprodCoeff [DecidableEq ι] (z : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i) :
tprodCoeff R z (update f i m₁) + tprodCoeff R z (update f i m₂) =
tprodCoeff R z (update f i (m₁ + m₂)) :=
Quotient.sound' <| AddConGen.Rel.of _ _ (Eqv.of_add _ z f i m₁ m₂)
theorem add_tprodCoeff' (z₁ z₂ : R) (f : Π i, s i) :
tprodCoeff R z₁ f + tprodCoeff R z₂ f = tprodCoeff R (z₁ + z₂) f :=
Quotient.sound' <| AddConGen.Rel.of _ _ (Eqv.of_add_scalar z₁ z₂ f)
theorem smul_tprodCoeff_aux [DecidableEq ι] (z : R) (f : Π i, s i) (i : ι) (r : R) :
tprodCoeff R z (update f i (r • f i)) = tprodCoeff R (r * z) f :=
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_smul _ _ _ _ _
theorem smul_tprodCoeff [DecidableEq ι] (z : R) (f : Π i, s i) (i : ι) (r : R₁) [SMul R₁ R]
[IsScalarTower R₁ R R] [SMul R₁ (s i)] [IsScalarTower R₁ R (s i)] :
tprodCoeff R z (update f i (r • f i)) = tprodCoeff R (r • z) f := by
have h₁ : r • z = r • (1 : R) * z := by rw [smul_mul_assoc, one_mul]
have h₂ : r • f i = (r • (1 : R)) • f i := (smul_one_smul _ _ _).symm
rw [h₁, h₂]
exact smul_tprodCoeff_aux z f i _
/-- Construct an `AddMonoidHom` from `(⨂[R] i, s i)` to some space `F` from a function
`φ : (R × Π i, s i) → F` with the appropriate properties. -/
def liftAddHom (φ : (R × Π i, s i) → F)
(C0 : ∀ (r : R) (f : Π i, s i) (i : ι) (_ : f i = 0), φ (r, f) = 0)
(C0' : ∀ f : Π i, s i, φ (0, f) = 0)
(C_add : ∀ [DecidableEq ι] (r : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i),
φ (r, update f i m₁) + φ (r, update f i m₂) = φ (r, update f i (m₁ + m₂)))
(C_add_scalar : ∀ (r r' : R) (f : Π i, s i), φ (r, f) + φ (r', f) = φ (r + r', f))
(C_smul : ∀ [DecidableEq ι] (r : R) (f : Π i, s i) (i : ι) (r' : R),
φ (r, update f i (r' • f i)) = φ (r' * r, f)) :
(⨂[R] i, s i) →+ F :=
(addConGen (PiTensorProduct.Eqv R s)).lift (FreeAddMonoid.lift φ) <|
AddCon.addConGen_le fun x y hxy ↦
match hxy with
| Eqv.of_zero r' f i hf =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, C0 r' f i hf]
| Eqv.of_zero_scalar f =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, C0']
| Eqv.of_add inst z f i m₁ m₂ =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, @C_add inst]
| Eqv.of_add_scalar z₁ z₂ f =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, C_add_scalar]
| Eqv.of_smul inst z f i r' =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, @C_smul inst]
| Eqv.add_comm x y =>
(AddCon.ker_rel _).2 <| by simp_rw [AddMonoidHom.map_add, add_comm]
/-- Induct using `tprodCoeff` -/
@[elab_as_elim]
protected theorem induction_on' {motive : (⨂[R] i, s i) → Prop} (z : ⨂[R] i, s i)
(tprodCoeff : ∀ (r : R) (f : Π i, s i), motive (tprodCoeff R r f))
(add : ∀ x y, motive x → motive y → motive (x + y)) :
motive z := by
have C0 : motive 0 := by
have h₁ := tprodCoeff 0 0
rwa [zero_tprodCoeff] at h₁
refine AddCon.induction_on z fun x ↦ FreeAddMonoid.recOn x C0 ?_
simp_rw [AddCon.coe_add]
refine fun f y ih ↦ add _ _ ?_ ih
convert tprodCoeff f.1 f.2
section DistribMulAction
variable [Monoid R₁] [DistribMulAction R₁ R] [SMulCommClass R₁ R R]
variable [Monoid R₂] [DistribMulAction R₂ R] [SMulCommClass R₂ R R]
-- Most of the time we want the instance below this one, which is easier for typeclass resolution
-- to find.
instance hasSMul' : SMul R₁ (⨂[R] i, s i) :=
⟨fun r ↦
liftAddHom (fun f : R × Π i, s i ↦ tprodCoeff R (r • f.1) f.2)
(fun r' f i hf ↦ by simp_rw [zero_tprodCoeff' _ f i hf])
(fun f ↦ by simp [zero_tprodCoeff]) (fun r' f i m₁ m₂ ↦ by simp [add_tprodCoeff])
(fun r' r'' f ↦ by simp [add_tprodCoeff', mul_add]) fun z f i r' ↦ by
simp [smul_tprodCoeff, mul_smul_comm]⟩
instance : SMul R (⨂[R] i, s i) :=
PiTensorProduct.hasSMul'
theorem smul_tprodCoeff' (r : R₁) (z : R) (f : Π i, s i) :
r • tprodCoeff R z f = tprodCoeff R (r • z) f := rfl
protected theorem smul_add (r : R₁) (x y : ⨂[R] i, s i) : r • (x + y) = r • x + r • y :=
AddMonoidHom.map_add _ _ _
instance distribMulAction' : DistribMulAction R₁ (⨂[R] i, s i) where
smul := (· • ·)
smul_add r x y := AddMonoidHom.map_add _ _ _
mul_smul r r' x :=
PiTensorProduct.induction_on' x (fun {r'' f} ↦ by simp [smul_tprodCoeff', smul_smul])
fun {x y} ihx ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihx, ihy]
one_smul x :=
PiTensorProduct.induction_on' x (fun {r f} ↦ by rw [smul_tprodCoeff', one_smul])
fun {z y} ihz ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihz, ihy]
smul_zero r := AddMonoidHom.map_zero _
instance smulCommClass' [SMulCommClass R₁ R₂ R] : SMulCommClass R₁ R₂ (⨂[R] i, s i) :=
⟨fun {r' r''} x ↦
PiTensorProduct.induction_on' x (fun {xr xf} ↦ by simp only [smul_tprodCoeff', smul_comm])
fun {z y} ihz ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihz, ihy]⟩
instance isScalarTower' [SMul R₁ R₂] [IsScalarTower R₁ R₂ R] :
IsScalarTower R₁ R₂ (⨂[R] i, s i) :=
⟨fun {r' r''} x ↦
PiTensorProduct.induction_on' x (fun {xr xf} ↦ by simp only [smul_tprodCoeff', smul_assoc])
fun {z y} ihz ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihz, ihy]⟩
end DistribMulAction
-- Most of the time we want the instance below this one, which is easier for typeclass resolution
-- to find.
instance module' [Semiring R₁] [Module R₁ R] [SMulCommClass R₁ R R] : Module R₁ (⨂[R] i, s i) :=
{ PiTensorProduct.distribMulAction' with
add_smul := fun r r' x ↦
PiTensorProduct.induction_on' x
(fun {r f} ↦ by simp_rw [smul_tprodCoeff', add_smul, add_tprodCoeff'])
fun {x y} ihx ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihx, ihy, add_add_add_comm]
zero_smul := fun x ↦
PiTensorProduct.induction_on' x
(fun {r f} ↦ by simp_rw [smul_tprodCoeff', zero_smul, zero_tprodCoeff])
fun {x y} ihx ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihx, ihy, add_zero] }
-- shortcut instances
instance : Module R (⨂[R] i, s i) :=
PiTensorProduct.module'
instance : SMulCommClass R R (⨂[R] i, s i) :=
PiTensorProduct.smulCommClass'
instance : IsScalarTower R R (⨂[R] i, s i) :=
PiTensorProduct.isScalarTower'
variable (R)
/-- The canonical `MultilinearMap R s (⨂[R] i, s i)`.
`tprod R fun i => f i` has notation `⨂ₜ[R] i, f i`. -/
def tprod : MultilinearMap R s (⨂[R] i, s i) where
toFun := tprodCoeff R 1
map_add' {_ f} i x y := (add_tprodCoeff (1 : R) f i x y).symm
map_smul' {_ f} i r x := by
rw [smul_tprodCoeff', ← smul_tprodCoeff (1 : R) _ i, update_idem, update_same]
variable {R}
unsuppress_compilation in
@[inherit_doc tprod]
notation3:100 "⨂ₜ["R"] "(...)", "r:(scoped f => tprod R f) => r
theorem tprod_eq_tprodCoeff_one :
⇑(tprod R : MultilinearMap R s (⨂[R] i, s i)) = tprodCoeff R 1 := rfl
@[simp]
theorem tprodCoeff_eq_smul_tprod (z : R) (f : Π i, s i) : tprodCoeff R z f = z • tprod R f := by
have : z = z • (1 : R) := by simp only [mul_one, Algebra.id.smul_eq_mul]
conv_lhs => rw [this]
rfl
/-- The image of an element `p` of `FreeAddMonoid (R × Π i, s i)` in the `PiTensorProduct` is
equal to the sum of `a • ⨂ₜ[R] i, m i` over all the entries `(a, m)` of `p`.
-/
lemma _root_.FreeAddMonoid.toPiTensorProduct (p : FreeAddMonoid (R × Π i, s i)) :
AddCon.toQuotient (c := addConGen (PiTensorProduct.Eqv R s)) p =
List.sum (List.map (fun x ↦ x.1 • ⨂ₜ[R] i, x.2 i) p) := by
match p with
| [] => rw [List.map_nil, List.sum_nil]; rfl
| x :: ps => rw [List.map_cons, List.sum_cons, ← List.singleton_append, ← toPiTensorProduct ps,
← tprodCoeff_eq_smul_tprod]; rfl
/-- The set of lifts of an element `x` of `⨂[R] i, s i` in `FreeAddMonoid (R × Π i, s i)`. -/
def lifts (x : ⨂[R] i, s i) : Set (FreeAddMonoid (R × Π i, s i)) :=
{p | AddCon.toQuotient (c := addConGen (PiTensorProduct.Eqv R s)) p = x}
/-- An element `p` of `FreeAddMonoid (R × Π i, s i)` lifts an element `x` of `⨂[R] i, s i`
if and only if `x` is equal to to the sum of `a • ⨂ₜ[R] i, m i` over all the entries
`(a, m)` of `p`.
-/
lemma mem_lifts_iff (x : ⨂[R] i, s i) (p : FreeAddMonoid (R × Π i, s i)) :
p ∈ lifts x ↔ List.sum (List.map (fun x ↦ x.1 • ⨂ₜ[R] i, x.2 i) p) = x := by
simp only [lifts, Set.mem_setOf_eq, FreeAddMonoid.toPiTensorProduct]
/-- Every element of `⨂[R] i, s i` has a lift in `FreeAddMonoid (R × Π i, s i)`.
-/
lemma nonempty_lifts (x : ⨂[R] i, s i) : Set.Nonempty (lifts x) := by
existsi @Quotient.out _ (addConGen (PiTensorProduct.Eqv R s)).toSetoid x
simp only [lifts, Set.mem_setOf_eq]
rw [← AddCon.quot_mk_eq_coe]
erw [Quot.out_eq]
/-- The empty list lifts the element `0` of `⨂[R] i, s i`.
-/
lemma lifts_zero : 0 ∈ lifts (0 : ⨂[R] i, s i) := by
rw [mem_lifts_iff]; erw [List.map_nil]; rw [List.sum_nil]
/-- If elements `p,q` of `FreeAddMonoid (R × Π i, s i)` lift elements `x,y` of `⨂[R] i, s i`
respectively, then `p + q` lifts `x + y`.
-/
lemma lifts_add {x y : ⨂[R] i, s i} {p q : FreeAddMonoid (R × Π i, s i)}
(hp : p ∈ lifts x) (hq : q ∈ lifts y) : p + q ∈ lifts (x + y) := by
simp only [lifts, Set.mem_setOf_eq, AddCon.coe_add]
rw [hp, hq]
/-- If an element `p` of `FreeAddMonoid (R × Π i, s i)` lifts an element `x` of `⨂[R] i, s i`,
and if `a` is an element of `R`, then the list obtained by multiplying the first entry of each
element of `p` by `a` lifts `a • x`.
-/
lemma lifts_smul {x : ⨂[R] i, s i} {p : FreeAddMonoid (R × Π i, s i)} (h : p ∈ lifts x) (a : R) :
List.map (fun (y : R × Π i, s i) ↦ (a * y.1, y.2)) p ∈ lifts (a • x) := by
rw [mem_lifts_iff] at h ⊢
rw [← List.comp_map, ← h, List.smul_sum, ← List.comp_map]
congr 2
ext _
simp only [comp_apply, smul_smul]
/-- Induct using scaled versions of `PiTensorProduct.tprod`. -/
@[elab_as_elim]
protected theorem induction_on {motive : (⨂[R] i, s i) → Prop} (z : ⨂[R] i, s i)
(smul_tprod : ∀ (r : R) (f : Π i, s i), motive (r • tprod R f))
(add : ∀ x y, motive x → motive y → motive (x + y)) :
motive z := by
simp_rw [← tprodCoeff_eq_smul_tprod] at smul_tprod
exact PiTensorProduct.induction_on' z smul_tprod add
@[ext]
theorem ext {φ₁ φ₂ : (⨂[R] i, s i) →ₗ[R] E}
(H : φ₁.compMultilinearMap (tprod R) = φ₂.compMultilinearMap (tprod R)) : φ₁ = φ₂ := by
refine LinearMap.ext ?_
refine fun z ↦
PiTensorProduct.induction_on' z ?_ fun {x y} hx hy ↦ by rw [φ₁.map_add, φ₂.map_add, hx, hy]
· intro r f
rw [tprodCoeff_eq_smul_tprod, φ₁.map_smul, φ₂.map_smul]
apply congr_arg
exact MultilinearMap.congr_fun H f
/-- The pure tensors (i.e. the elements of the image of `PiTensorProduct.tprod`) span
the tensor product. -/
theorem span_tprod_eq_top :
Submodule.span R (Set.range (tprod R)) = (⊤ : Submodule R (⨂[R] i, s i)) :=
Submodule.eq_top_iff'.mpr fun t ↦ t.induction_on
(fun _ _ ↦ Submodule.smul_mem _ _
(Submodule.subset_span (by simp only [Set.mem_range, exists_apply_eq_apply])))
(fun _ _ hx hy ↦ Submodule.add_mem _ hx hy)
end Module
section Multilinear
open MultilinearMap
variable {s}
section lift
/-- Auxiliary function to constructing a linear map `(⨂[R] i, s i) → E` given a
`MultilinearMap R s E` with the property that its composition with the canonical
`MultilinearMap R s (⨂[R] i, s i)` is the given multilinear map. -/
def liftAux (φ : MultilinearMap R s E) : (⨂[R] i, s i) →+ E :=
liftAddHom (fun p : R × Π i, s i ↦ p.1 • φ p.2)
(fun z f i hf ↦ by simp_rw [map_coord_zero φ i hf, smul_zero])
(fun f ↦ by simp_rw [zero_smul])
(fun z f i m₁ m₂ ↦ by simp_rw [← smul_add, φ.map_add])
(fun z₁ z₂ f ↦ by rw [← add_smul])
fun z f i r ↦ by simp [φ.map_smul, smul_smul, mul_comm]
theorem liftAux_tprod (φ : MultilinearMap R s E) (f : Π i, s i) : liftAux φ (tprod R f) = φ f := by
simp only [liftAux, liftAddHom, tprod_eq_tprodCoeff_one, tprodCoeff, AddCon.coe_mk']
-- The end of this proof was very different before leanprover/lean4#2644:
-- rw [FreeAddMonoid.of, FreeAddMonoid.ofList, Equiv.refl_apply, AddCon.lift_coe]
-- dsimp [FreeAddMonoid.lift, FreeAddMonoid.sumAux]
-- show _ • _ = _
-- rw [one_smul]
erw [AddCon.lift_coe]
erw [FreeAddMonoid.of]
dsimp [FreeAddMonoid.ofList]
rw [← one_smul R (φ f)]
erw [Equiv.refl_apply]
convert one_smul R (φ f)
simp
theorem liftAux_tprodCoeff (φ : MultilinearMap R s E) (z : R) (f : Π i, s i) :
liftAux φ (tprodCoeff R z f) = z • φ f := rfl
theorem liftAux.smul {φ : MultilinearMap R s E} (r : R) (x : ⨂[R] i, s i) :
liftAux φ (r • x) = r • liftAux φ x := by
refine PiTensorProduct.induction_on' x ?_ ?_
· intro z f
rw [smul_tprodCoeff' r z f, liftAux_tprodCoeff, liftAux_tprodCoeff, smul_assoc]
· intro z y ihz ihy
rw [smul_add, (liftAux φ).map_add, ihz, ihy, (liftAux φ).map_add, smul_add]
/-- Constructing a linear map `(⨂[R] i, s i) → E` given a `MultilinearMap R s E` with the
property that its composition with the canonical `MultilinearMap R s E` is
the given multilinear map `φ`. -/
def lift : MultilinearMap R s E ≃ₗ[R] (⨂[R] i, s i) →ₗ[R] E where
toFun φ := { liftAux φ with map_smul' := liftAux.smul }
invFun φ' := φ'.compMultilinearMap (tprod R)
left_inv φ := by
ext
simp [liftAux_tprod, LinearMap.compMultilinearMap]
right_inv φ := by
ext
simp [liftAux_tprod]
map_add' φ₁ φ₂ := by
ext
simp [liftAux_tprod]
map_smul' r φ₂ := by
ext
simp [liftAux_tprod]
variable {φ : MultilinearMap R s E}
@[simp]
theorem lift.tprod (f : Π i, s i) : lift φ (tprod R f) = φ f :=
liftAux_tprod φ f
theorem lift.unique' {φ' : (⨂[R] i, s i) →ₗ[R] E}
(H : φ'.compMultilinearMap (PiTensorProduct.tprod R) = φ) : φ' = lift φ :=
ext <| H.symm ▸ (lift.symm_apply_apply φ).symm
theorem lift.unique {φ' : (⨂[R] i, s i) →ₗ[R] E} (H : ∀ f, φ' (PiTensorProduct.tprod R f) = φ f) :
φ' = lift φ :=
lift.unique' (MultilinearMap.ext H)
@[simp]
theorem lift_symm (φ' : (⨂[R] i, s i) →ₗ[R] E) : lift.symm φ' = φ'.compMultilinearMap (tprod R) :=
rfl
@[simp]
theorem lift_tprod : lift (tprod R : MultilinearMap R s _) = LinearMap.id :=
Eq.symm <| lift.unique' rfl
end lift
section map
variable {t t' : ι → Type*}
variable [∀ i, AddCommMonoid (t i)] [∀ i, Module R (t i)]
variable [∀ i, AddCommMonoid (t' i)] [∀ i, Module R (t' i)]
variable (g : Π i, t i →ₗ[R] t' i) (f : Π i, s i →ₗ[R] t i)
/--
Let `sᵢ` and `tᵢ` be two families of `R`-modules.
Let `f` be a family of `R`-linear maps between `sᵢ` and `tᵢ`, i.e. `f : Πᵢ sᵢ → tᵢ`,
then there is an induced map `⨂ᵢ sᵢ → ⨂ᵢ tᵢ` by `⨂ aᵢ ↦ ⨂ fᵢ aᵢ`.
This is `TensorProduct.map` for an arbitrary family of modules.
-/
def map : (⨂[R] i, s i) →ₗ[R] ⨂[R] i, t i :=
lift <| (tprod R).compLinearMap f
@[simp] lemma map_tprod (x : Π i, s i) :
map f (tprod R x) = tprod R fun i ↦ f i (x i) :=
lift.tprod _
-- No lemmas about associativity, because we don't have associativity of `PiTensorProduct` yet.
theorem map_range_eq_span_tprod :
LinearMap.range (map f) =
Submodule.span R {t | ∃ (m : Π i, s i), tprod R (fun i ↦ f i (m i)) = t} := by
rw [← Submodule.map_top, ← span_tprod_eq_top, Submodule.map_span, ← Set.range_comp]
apply congrArg; ext x
simp only [Set.mem_range, comp_apply, map_tprod, Set.mem_setOf_eq]
/-- Given submodules `p i ⊆ s i`, this is the natural map: `⨂[R] i, p i → ⨂[R] i, s i`.
This is `TensorProduct.mapIncl` for an arbitrary family of modules.
-/
@[simp]
def mapIncl (p : Π i, Submodule R (s i)) : (⨂[R] i, p i) →ₗ[R] ⨂[R] i, s i :=
map fun (i : ι) ↦ (p i).subtype
theorem map_comp : map (fun (i : ι) ↦ g i ∘ₗ f i) = map g ∘ₗ map f := by
ext
simp only [LinearMap.compMultilinearMap_apply, map_tprod, LinearMap.coe_comp, Function.comp_apply]
theorem lift_comp_map (h : MultilinearMap R t E) :
lift h ∘ₗ map f = lift (h.compLinearMap f) := by
ext
simp only [LinearMap.compMultilinearMap_apply, LinearMap.coe_comp, Function.comp_apply,
map_tprod, lift.tprod, MultilinearMap.compLinearMap_apply]
attribute [local ext high] ext
@[simp]
theorem map_id : map (fun i ↦ (LinearMap.id : s i →ₗ[R] s i)) = .id := by
ext
simp only [LinearMap.compMultilinearMap_apply, map_tprod, LinearMap.id_coe, id_eq]
@[simp]
theorem map_one : map (fun (i : ι) ↦ (1 : s i →ₗ[R] s i)) = 1 :=
map_id
theorem map_mul (f₁ f₂ : Π i, s i →ₗ[R] s i) :
map (fun i ↦ f₁ i * f₂ i) = map f₁ * map f₂ :=
map_comp f₁ f₂
/-- Upgrading `PiTensorProduct.map` to a `MonoidHom` when `s = t`. -/
@[simps]
def mapMonoidHom : (Π i, s i →ₗ[R] s i) →* ((⨂[R] i, s i) →ₗ[R] ⨂[R] i, s i) where
toFun := map
map_one' := map_one
map_mul' := map_mul
@[simp]
protected theorem map_pow (f : Π i, s i →ₗ[R] s i) (n : ℕ) :
map (f ^ n) = map f ^ n := MonoidHom.map_pow mapMonoidHom _ _
open Function in
private theorem map_add_smul_aux [DecidableEq ι] (i : ι) (x : Π i, s i) (u : s i →ₗ[R] t i) :
(fun j ↦ update f i u j (x j)) = update (fun j ↦ (f j) (x j)) i (u (x i)) := by
ext j
exact apply_update (fun i F => F (x i)) f i u j
open Function in
protected theorem map_add [DecidableEq ι] (i : ι) (u v : s i →ₗ[R] t i) :
map (update f i (u + v)) = map (update f i u) + map (update f i v) := by
ext x
simp only [LinearMap.compMultilinearMap_apply, map_tprod, map_add_smul_aux, LinearMap.add_apply,
MultilinearMap.map_add]
open Function in
protected theorem map_smul [DecidableEq ι] (i : ι) (c : R) (u : s i →ₗ[R] t i) :
map (update f i (c • u)) = c • map (update f i u) := by
ext x
simp only [LinearMap.compMultilinearMap_apply, map_tprod, map_add_smul_aux, LinearMap.smul_apply,
MultilinearMap.map_smul]
variable (R s t)
/-- The tensor of a family of linear maps from `sᵢ` to `tᵢ`, as a multilinear map of
the family.
-/
@[simps]
noncomputable def mapMultilinear :
MultilinearMap R (fun (i : ι) ↦ s i →ₗ[R] t i) ((⨂[R] i, s i) →ₗ[R] ⨂[R] i, t i) where
toFun := map
map_smul' _ _ _ _ := PiTensorProduct.map_smul _ _ _ _
map_add' _ _ _ _ := PiTensorProduct.map_add _ _ _ _
variable {R s t}
/--
Let `sᵢ` and `tᵢ` be families of `R`-modules.
Then there is an `R`-linear map between `⨂ᵢ Hom(sᵢ, tᵢ)` and `Hom(⨂ᵢ sᵢ, ⨂ tᵢ)` defined by
`⨂ᵢ fᵢ ↦ ⨂ᵢ aᵢ ↦ ⨂ᵢ fᵢ aᵢ`.
This is `TensorProduct.homTensorHomMap` for an arbitrary family of modules.
Note that `PiTensorProduct.piTensorHomMap (tprod R f)` is equal to `PiTensorProduct.map f`.
-/
def piTensorHomMap : (⨂[R] i, s i →ₗ[R] t i) →ₗ[R] (⨂[R] i, s i) →ₗ[R] ⨂[R] i, t i :=
lift.toLinearMap ∘ₗ lift (MultilinearMap.piLinearMap <| tprod R)
@[simp] lemma piTensorHomMap_tprod_tprod (f : Π i, s i →ₗ[R] t i) (x : Π i, s i) :
piTensorHomMap (tprod R f) (tprod R x) = tprod R fun i ↦ f i (x i) := by
simp [piTensorHomMap]
lemma piTensorHomMap_tprod_eq_map (f : Π i, s i →ₗ[R] t i) :
piTensorHomMap (tprod R f) = map f := by
ext; simp
/-- If `s i` and `t i` are linearly equivalent for every `i` in `ι`, then `⨂[R] i, s i` and
`⨂[R] i, t i` are linearly equivalent.
This is the n-ary version of `TensorProduct.congr`
-/
noncomputable def congr (f : Π i, s i ≃ₗ[R] t i) :
(⨂[R] i, s i) ≃ₗ[R] ⨂[R] i, t i :=
.ofLinear
(map (fun i ↦ f i))
(map (fun i ↦ (f i).symm))
(by ext; simp)
(by ext; simp)
@[simp]
theorem congr_tprod (f : Π i, s i ≃ₗ[R] t i) (m : Π i, s i) :
congr f (tprod R m) = tprod R (fun (i : ι) ↦ (f i) (m i)) := by
simp only [congr, LinearEquiv.ofLinear_apply, map_tprod, LinearEquiv.coe_coe]
@[simp]
theorem congr_symm_tprod (f : Π i, s i ≃ₗ[R] t i) (p : Π i, t i) :
(congr f).symm (tprod R p) = tprod R (fun (i : ι) ↦ (f i).symm (p i)) := by
simp only [congr, LinearEquiv.ofLinear_symm_apply, map_tprod, LinearEquiv.coe_coe]
/--
Let `sᵢ`, `tᵢ` and `t'ᵢ` be families of `R`-modules, then `f : Πᵢ sᵢ → tᵢ → t'ᵢ` induces an
element of `Hom(⨂ᵢ sᵢ, Hom(⨂ tᵢ, ⨂ᵢ t'ᵢ))` defined by `⨂ᵢ aᵢ ↦ ⨂ᵢ bᵢ ↦ ⨂ᵢ fᵢ aᵢ bᵢ`.
This is `PiTensorProduct.map` for two arbitrary families of modules.
This is `TensorProduct.map₂` for families of modules.
-/
def map₂ (f : Π i, s i →ₗ[R] t i →ₗ[R] t' i) :
(⨂[R] i, s i) →ₗ[R] (⨂[R] i, t i) →ₗ[R] ⨂[R] i, t' i :=
lift <| LinearMap.compMultilinearMap piTensorHomMap <| (tprod R).compLinearMap f
lemma map₂_tprod_tprod (f : Π i, s i →ₗ[R] t i →ₗ[R] t' i) (x : Π i, s i) (y : Π i, t i) :
map₂ f (tprod R x) (tprod R y) = tprod R fun i ↦ f i (x i) (y i) := by
simp [map₂]
/--
Let `sᵢ`, `tᵢ` and `t'ᵢ` be families of `R`-modules.
Then there is a function from `⨂ᵢ Hom(sᵢ, Hom(tᵢ, t'ᵢ))` to `Hom(⨂ᵢ sᵢ, Hom(⨂ tᵢ, ⨂ᵢ t'ᵢ))`
defined by `⨂ᵢ fᵢ ↦ ⨂ᵢ aᵢ ↦ ⨂ᵢ bᵢ ↦ ⨂ᵢ fᵢ aᵢ bᵢ`. -/
def piTensorHomMapFun₂ : (⨂[R] i, s i →ₗ[R] t i →ₗ[R] t' i) →
(⨂[R] i, s i) →ₗ[R] (⨂[R] i, t i) →ₗ[R] (⨂[R] i, t' i) :=
fun φ => lift <| LinearMap.compMultilinearMap piTensorHomMap <|
(lift <| MultilinearMap.piLinearMap <| tprod R) φ
theorem piTensorHomMapFun₂_add (φ ψ : ⨂[R] i, s i →ₗ[R] t i →ₗ[R] t' i) :
piTensorHomMapFun₂ (φ + ψ) = piTensorHomMapFun₂ φ + piTensorHomMapFun₂ ψ := by
dsimp [piTensorHomMapFun₂]; ext; simp only [map_add, LinearMap.compMultilinearMap_apply,
lift.tprod, add_apply, LinearMap.add_apply]
theorem piTensorHomMapFun₂_smul (r : R) (φ : ⨂[R] i, s i →ₗ[R] t i →ₗ[R] t' i) :
piTensorHomMapFun₂ (r • φ) = r • piTensorHomMapFun₂ φ := by
dsimp [piTensorHomMapFun₂]; ext; simp only [map_smul, LinearMap.compMultilinearMap_apply,
lift.tprod, smul_apply, LinearMap.smul_apply]
/--
Let `sᵢ`, `tᵢ` and `t'ᵢ` be families of `R`-modules.
Then there is an linear map from `⨂ᵢ Hom(sᵢ, Hom(tᵢ, t'ᵢ))` to `Hom(⨂ᵢ sᵢ, Hom(⨂ tᵢ, ⨂ᵢ t'ᵢ))`
defined by `⨂ᵢ fᵢ ↦ ⨂ᵢ aᵢ ↦ ⨂ᵢ bᵢ ↦ ⨂ᵢ fᵢ aᵢ bᵢ`.
This is `TensorProduct.homTensorHomMap` for two arbitrary families of modules.
-/
def piTensorHomMap₂ : (⨂[R] i, s i →ₗ[R] t i →ₗ[R] t' i) →ₗ[R]
(⨂[R] i, s i) →ₗ[R] (⨂[R] i, t i) →ₗ[R] (⨂[R] i, t' i) where
toFun := piTensorHomMapFun₂
map_add' x y := piTensorHomMapFun₂_add x y
map_smul' x y := piTensorHomMapFun₂_smul x y
@[simp] lemma piTensorHomMap₂_tprod_tprod_tprod
(f : ∀ i, s i →ₗ[R] t i →ₗ[R] t' i) (a : ∀ i, s i) (b : ∀ i, t i) :
piTensorHomMap₂ (tprod R f) (tprod R a) (tprod R b) = tprod R (fun i ↦ f i (a i) (b i)) := by
simp [piTensorHomMapFun₂, piTensorHomMap₂]
end map
section
variable (R M)
variable (s) in
/-- Re-index the components of the tensor power by `e`. -/
def reindex (e : ι ≃ ι₂) : (⨂[R] i : ι, s i) ≃ₗ[R] ⨂[R] i : ι₂, s (e.symm i) :=
let f := domDomCongrLinearEquiv' R R s (⨂[R] (i : ι₂), s (e.symm i)) e
let g := domDomCongrLinearEquiv' R R s (⨂[R] (i : ι), s i) e
#adaptation_note /-- v4.7.0-rc1
An alternative to the last two proofs would be `aesop (simp_config := {zetaDelta := true})`
or a wrapper macro to that effect. -/
LinearEquiv.ofLinear (lift <| f.symm <| tprod R) (lift <| g <| tprod R)
(by aesop (add norm simp [f, g]))
(by aesop (add norm simp [f, g]))
end
@[simp]
theorem reindex_tprod (e : ι ≃ ι₂) (f : Π i, s i) :
reindex R s e (tprod R f) = tprod R fun i ↦ f (e.symm i) := by
dsimp [reindex]
exact liftAux_tprod _ f
@[simp]
theorem reindex_comp_tprod (e : ι ≃ ι₂) :
(reindex R s e).compMultilinearMap (tprod R) =
(domDomCongrLinearEquiv' R R s _ e).symm (tprod R) :=
MultilinearMap.ext <| reindex_tprod e
theorem lift_comp_reindex (e : ι ≃ ι₂) (φ : MultilinearMap R (fun i ↦ s (e.symm i)) E) :
lift φ ∘ₗ (reindex R s e) = lift ((domDomCongrLinearEquiv' R R s _ e).symm φ) := by
ext; simp [reindex]
@[simp]
theorem lift_comp_reindex_symm (e : ι ≃ ι₂) (φ : MultilinearMap R s E) :
lift φ ∘ₗ (reindex R s e).symm = lift (domDomCongrLinearEquiv' R R s _ e φ) := by
ext; simp [reindex]
theorem lift_reindex
(e : ι ≃ ι₂) (φ : MultilinearMap R (fun i ↦ s (e.symm i)) E) (x : ⨂[R] i, s i) :
lift φ (reindex R s e x) = lift ((domDomCongrLinearEquiv' R R s _ e).symm φ) x :=
LinearMap.congr_fun (lift_comp_reindex e φ) x
@[simp]
theorem lift_reindex_symm
(e : ι ≃ ι₂) (φ : MultilinearMap R s E) (x : ⨂[R] i, s (e.symm i)) :
lift φ (reindex R s e |>.symm x) = lift (domDomCongrLinearEquiv' R R s _ e φ) x :=
LinearMap.congr_fun (lift_comp_reindex_symm e φ) x
@[simp]
theorem reindex_trans (e : ι ≃ ι₂) (e' : ι₂ ≃ ι₃) :
(reindex R s e).trans (reindex R _ e') = reindex R s (e.trans e') := by
apply LinearEquiv.toLinearMap_injective
ext f
simp only [LinearEquiv.trans_apply, LinearEquiv.coe_coe, reindex_tprod,
LinearMap.coe_compMultilinearMap, Function.comp_apply, MultilinearMap.domDomCongr_apply,
reindex_comp_tprod]
congr
theorem reindex_reindex (e : ι ≃ ι₂) (e' : ι₂ ≃ ι₃) (x : ⨂[R] i, s i) :
reindex R _ e' (reindex R s e x) = reindex R s (e.trans e') x :=
LinearEquiv.congr_fun (reindex_trans e e' : _ = reindex R s (e.trans e')) x
/-- This lemma is impractical to state in the dependent case. -/
@[simp]
theorem reindex_symm (e : ι ≃ ι₂) :
(reindex R (fun _ ↦ M) e).symm = reindex R (fun _ ↦ M) e.symm := by
ext x
simp only [reindex, domDomCongrLinearEquiv', LinearEquiv.coe_symm_mk, LinearEquiv.coe_mk,
LinearEquiv.ofLinear_symm_apply, Equiv.symm_symm_apply, LinearEquiv.ofLinear_apply,
Equiv.piCongrLeft'_symm]
@[simp]
theorem reindex_refl : reindex R s (Equiv.refl ι) = LinearEquiv.refl R _ := by
apply LinearEquiv.toLinearMap_injective
ext
simp only [Equiv.refl_symm, Equiv.refl_apply, reindex, domDomCongrLinearEquiv',
LinearEquiv.coe_symm_mk, LinearMap.compMultilinearMap_apply, LinearEquiv.coe_coe,
LinearEquiv.refl_toLinearMap, LinearMap.id_coe, id_eq]
erw [lift.tprod]
congr
variable {t : ι → Type*}
variable [∀ i, AddCommMonoid (t i)] [∀ i, Module R (t i)]
/-- Re-indexing the components of the tensor product by an equivalence `e` is compatible
with `PiTensorProduct.map`. -/
theorem map_comp_reindex_eq (f : Π i, s i →ₗ[R] t i) (e : ι ≃ ι₂) :
map (fun i ↦ f (e.symm i)) ∘ₗ reindex R s e = reindex R t e ∘ₗ map f := by
ext m
simp only [LinearMap.compMultilinearMap_apply, LinearMap.coe_comp, LinearEquiv.coe_coe,
LinearMap.comp_apply, reindex_tprod, map_tprod]
theorem map_reindex (f : Π i, s i →ₗ[R] t i) (e : ι ≃ ι₂) (x : ⨂[R] i, s i) :
map (fun i ↦ f (e.symm i)) (reindex R s e x) = reindex R t e (map f x) :=
DFunLike.congr_fun (map_comp_reindex_eq _ _) _
theorem map_comp_reindex_symm (f : Π i, s i →ₗ[R] t i) (e : ι ≃ ι₂) :
map f ∘ₗ (reindex R s e).symm = (reindex R t e).symm ∘ₗ map (fun i => f (e.symm i)) := by
ext m
apply LinearEquiv.injective (reindex R t e)
simp only [LinearMap.compMultilinearMap_apply, LinearMap.coe_comp, LinearEquiv.coe_coe,
comp_apply, ← map_reindex, LinearEquiv.apply_symm_apply, map_tprod]
theorem map_reindex_symm (f : Π i, s i →ₗ[R] t i) (e : ι ≃ ι₂) (x : ⨂[R] i, s (e.symm i)) :
map f ((reindex R s e).symm x) = (reindex R t e).symm (map (fun i ↦ f (e.symm i)) x) :=
DFunLike.congr_fun (map_comp_reindex_symm _ _) _
variable (ι)
attribute [local simp] eq_iff_true_of_subsingleton in
/-- The tensor product over an empty index type `ι` is isomorphic to the base ring. -/
@[simps symm_apply]
def isEmptyEquiv [IsEmpty ι] : (⨂[R] i : ι, s i) ≃ₗ[R] R where
toFun := lift (constOfIsEmpty R _ 1)
invFun r := r • tprod R (@isEmptyElim _ _ _)
left_inv x := by
refine x.induction_on ?_ ?_
· intro x y
-- Note: #8386 had to change `map_smulₛₗ` into `map_smulₛₗ _`
simp only [map_smulₛₗ _, RingHom.id_apply, lift.tprod, constOfIsEmpty_apply, const_apply,
smul_eq_mul, mul_one]
congr
aesop
· simp only
intro x y hx hy
rw [map_add, add_smul, hx, hy]
right_inv t := by simp
map_add' := LinearMap.map_add _
map_smul' := fun r x => by
simp only
exact LinearMap.map_smul _ r x
@[simp]
theorem isEmptyEquiv_apply_tprod [IsEmpty ι] (f : Π i, s i) :
isEmptyEquiv ι (tprod R f) = 1 :=
lift.tprod _
variable {ι}
/--
Tensor product of `M` over a singleton set is equivalent to `M`
-/
@[simps symm_apply]
def subsingletonEquiv [Subsingleton ι] (i₀ : ι) : (⨂[R] _ : ι, M) ≃ₗ[R] M where
toFun := lift (MultilinearMap.ofSubsingleton R M M i₀ .id)
invFun m := tprod R fun _ ↦ m
left_inv x := by
dsimp only
have : ∀ (f : ι → M) (z : M), (fun _ : ι ↦ z) = update f i₀ z := fun f z ↦ by
ext i
rw [Subsingleton.elim i i₀, Function.update_same]
refine x.induction_on ?_ ?_
· intro r f
simp only [LinearMap.map_smul, LinearMap.id_apply, lift.tprod, ofSubsingleton_apply_apply,
this f, MultilinearMap.map_smul, update_eq_self]
· intro x y hx hy
rw [LinearMap.map_add, this 0 (_ + _), MultilinearMap.map_add, ← this 0 (lift _ _), hx,
← this 0 (lift _ _), hy]
right_inv t := by simp only [ofSubsingleton_apply_apply, LinearMap.id_apply, lift.tprod]
map_add' := LinearMap.map_add _
map_smul' := fun r x => by
simp only
exact LinearMap.map_smul _ r x
@[simp]
theorem subsingletonEquiv_apply_tprod [Subsingleton ι] (i : ι) (f : ι → M) :
subsingletonEquiv i (tprod R f) = f i :=
lift.tprod _
section Tmul
/-- Collapse a `TensorProduct` of `PiTensorProduct`s. -/
private def tmul : ((⨂[R] _ : ι, M) ⊗[R] ⨂[R] _ : ι₂, M) →ₗ[R] ⨂[R] _ : ι ⊕ ι₂, M :=
TensorProduct.lift
{ toFun := fun a ↦
PiTensorProduct.lift <|
PiTensorProduct.lift (MultilinearMap.currySumEquiv R _ _ M _ (tprod R)) a
map_add' := fun a b ↦ by simp only [LinearEquiv.map_add, LinearMap.map_add]
map_smul' := fun r a ↦ by
simp only [LinearEquiv.map_smul, LinearMap.map_smul, RingHom.id_apply] }
private theorem tmul_apply (a : ι → M) (b : ι₂ → M) :
tmul ((⨂ₜ[R] i, a i) ⊗ₜ[R] ⨂ₜ[R] i, b i) = ⨂ₜ[R] i, Sum.elim a b i := by
erw [TensorProduct.lift.tmul, PiTensorProduct.lift.tprod, PiTensorProduct.lift.tprod]
rfl
/-- Expand `PiTensorProduct` into a `TensorProduct` of two factors. -/
private def tmulSymm : (⨂[R] _ : ι ⊕ ι₂, M) →ₗ[R] (⨂[R] _ : ι, M) ⊗[R] ⨂[R] _ : ι₂, M :=
-- by using tactic mode, we avoid the need for a lot of `@`s and `_`s
PiTensorProduct.lift <| MultilinearMap.domCoprod (tprod R) (tprod R)
private theorem tmulSymm_apply (a : ι ⊕ ι₂ → M) :
tmulSymm (⨂ₜ[R] i, a i) = (⨂ₜ[R] i, a (Sum.inl i)) ⊗ₜ[R] ⨂ₜ[R] i, a (Sum.inr i) :=
PiTensorProduct.lift.tprod _
variable (R M)
attribute [local ext] TensorProduct.ext
/-- Equivalence between a `TensorProduct` of `PiTensorProduct`s and a single
`PiTensorProduct` indexed by a `Sum` type.
For simplicity, this is defined only for homogeneously- (rather than dependently-) typed components.
-/
def tmulEquiv : ((⨂[R] _ : ι, M) ⊗[R] ⨂[R] _ : ι₂, M) ≃ₗ[R] ⨂[R] _ : ι ⊕ ι₂, M :=
LinearEquiv.ofLinear tmul tmulSymm
(by
ext x
show tmul (tmulSymm (tprod R x)) = tprod R x -- Speed up the call to `simp`.
simp only [tmulSymm_apply, tmul_apply]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/5026):
-- was part of `simp only` above
erw [Sum.elim_comp_inl_inr])
(by
ext x y
show tmulSymm (tmul (tprod R x ⊗ₜ[R] tprod R y)) = tprod R x ⊗ₜ[R] tprod R y
simp only [tmul_apply, tmulSymm_apply, Sum.elim_inl, Sum.elim_inr])
@[simp]
theorem tmulEquiv_apply (a : ι → M) (b : ι₂ → M) :
tmulEquiv (ι := ι) (ι₂ := ι₂) R M ((⨂ₜ[R] i, a i) ⊗ₜ[R] ⨂ₜ[R] i, b i) =
⨂ₜ[R] i, Sum.elim a b i :=
tmul_apply a b
@[simp]
theorem tmulEquiv_symm_apply (a : ι ⊕ ι₂ → M) :
(tmulEquiv (ι := ι) (ι₂ := ι₂) R M).symm (⨂ₜ[R] i, a i) =
(⨂ₜ[R] i, a (Sum.inl i)) ⊗ₜ[R] ⨂ₜ[R] i, a (Sum.inr i) :=
tmulSymm_apply a
end Tmul
end Multilinear
end PiTensorProduct
end Semiring
section Ring
namespace PiTensorProduct
open PiTensorProduct
open TensorProduct
variable {ι : Type*} {R : Type*} [CommRing R]
variable {s : ι → Type*} [∀ i, AddCommGroup (s i)] [∀ i, Module R (s i)]
/- Unlike for the binary tensor product, we require `R` to be a `CommRing` here, otherwise
this is false in the case where `ι` is empty. -/
instance : AddCommGroup (⨂[R] i, s i) :=
Module.addCommMonoidToAddCommGroup R
end PiTensorProduct
end Ring
|
LinearAlgebra\Prod.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Eric Wieser
-/
import Mathlib.Algebra.Algebra.Prod
import Mathlib.LinearAlgebra.Span
import Mathlib.Order.PartialSups
/-! ### Products of modules
This file defines constructors for linear maps whose domains or codomains are products.
It contains theorems relating these to each other, as well as to `Submodule.prod`, `Submodule.map`,
`Submodule.comap`, `LinearMap.range`, and `LinearMap.ker`.
## Main definitions
- products in the domain:
- `LinearMap.fst`
- `LinearMap.snd`
- `LinearMap.coprod`
- `LinearMap.prod_ext`
- products in the codomain:
- `LinearMap.inl`
- `LinearMap.inr`
- `LinearMap.prod`
- products in both domain and codomain:
- `LinearMap.prodMap`
- `LinearEquiv.prodMap`
- `LinearEquiv.skewProd`
-/
universe u v w x y z u' v' w' y'
variable {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'}
variable {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x}
variable {M₅ M₆ : Type*}
section Prod
namespace LinearMap
variable (S : Type*) [Semiring R] [Semiring S]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄]
variable [AddCommMonoid M₅] [AddCommMonoid M₆]
variable [Module R M] [Module R M₂] [Module R M₃] [Module R M₄]
variable [Module R M₅] [Module R M₆]
variable (f : M →ₗ[R] M₂)
section
variable (R M M₂)
/-- The first projection of a product is a linear map. -/
def fst : M × M₂ →ₗ[R] M where
toFun := Prod.fst
map_add' _x _y := rfl
map_smul' _x _y := rfl
/-- The second projection of a product is a linear map. -/
def snd : M × M₂ →ₗ[R] M₂ where
toFun := Prod.snd
map_add' _x _y := rfl
map_smul' _x _y := rfl
end
@[simp]
theorem fst_apply (x : M × M₂) : fst R M M₂ x = x.1 :=
rfl
@[simp]
theorem snd_apply (x : M × M₂) : snd R M M₂ x = x.2 :=
rfl
theorem fst_surjective : Function.Surjective (fst R M M₂) := fun x => ⟨(x, 0), rfl⟩
theorem snd_surjective : Function.Surjective (snd R M M₂) := fun x => ⟨(0, x), rfl⟩
/-- The prod of two linear maps is a linear map. -/
@[simps]
def prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : M →ₗ[R] M₂ × M₃ where
toFun := Pi.prod f g
map_add' x y := by simp only [Pi.prod, Prod.mk_add_mk, map_add]
map_smul' c x := by simp only [Pi.prod, Prod.smul_mk, map_smul, RingHom.id_apply]
theorem coe_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ⇑(f.prod g) = Pi.prod f g :=
rfl
@[simp]
theorem fst_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (fst R M₂ M₃).comp (prod f g) = f := rfl
@[simp]
theorem snd_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (snd R M₂ M₃).comp (prod f g) = g := rfl
@[simp]
theorem pair_fst_snd : prod (fst R M M₂) (snd R M M₂) = LinearMap.id := rfl
theorem prod_comp (f : M₂ →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄)
(h : M →ₗ[R] M₂) : (f.prod g).comp h = (f.comp h).prod (g.comp h) :=
rfl
/-- Taking the product of two maps with the same domain is equivalent to taking the product of
their codomains.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/
@[simps]
def prodEquiv [Module S M₂] [Module S M₃] [SMulCommClass R S M₂] [SMulCommClass R S M₃] :
((M →ₗ[R] M₂) × (M →ₗ[R] M₃)) ≃ₗ[S] M →ₗ[R] M₂ × M₃ where
toFun f := f.1.prod f.2
invFun f := ((fst _ _ _).comp f, (snd _ _ _).comp f)
left_inv f := by ext <;> rfl
right_inv f := by ext <;> rfl
map_add' a b := rfl
map_smul' r a := rfl
section
variable (R M M₂)
/-- The left injection into a product is a linear map. -/
def inl : M →ₗ[R] M × M₂ :=
prod LinearMap.id 0
/-- The right injection into a product is a linear map. -/
def inr : M₂ →ₗ[R] M × M₂ :=
prod 0 LinearMap.id
theorem range_inl : range (inl R M M₂) = ker (snd R M M₂) := by
ext x
simp only [mem_ker, mem_range]
constructor
· rintro ⟨y, rfl⟩
rfl
· intro h
exact ⟨x.fst, Prod.ext rfl h.symm⟩
theorem ker_snd : ker (snd R M M₂) = range (inl R M M₂) :=
Eq.symm <| range_inl R M M₂
theorem range_inr : range (inr R M M₂) = ker (fst R M M₂) := by
ext x
simp only [mem_ker, mem_range]
constructor
· rintro ⟨y, rfl⟩
rfl
· intro h
exact ⟨x.snd, Prod.ext h.symm rfl⟩
theorem ker_fst : ker (fst R M M₂) = range (inr R M M₂) :=
Eq.symm <| range_inr R M M₂
@[simp] theorem fst_comp_inl : fst R M M₂ ∘ₗ inl R M M₂ = id := rfl
@[simp] theorem snd_comp_inl : snd R M M₂ ∘ₗ inl R M M₂ = 0 := rfl
@[simp] theorem fst_comp_inr : fst R M M₂ ∘ₗ inr R M M₂ = 0 := rfl
@[simp] theorem snd_comp_inr : snd R M M₂ ∘ₗ inr R M M₂ = id := rfl
end
@[simp]
theorem coe_inl : (inl R M M₂ : M → M × M₂) = fun x => (x, 0) :=
rfl
theorem inl_apply (x : M) : inl R M M₂ x = (x, 0) :=
rfl
@[simp]
theorem coe_inr : (inr R M M₂ : M₂ → M × M₂) = Prod.mk 0 :=
rfl
theorem inr_apply (x : M₂) : inr R M M₂ x = (0, x) :=
rfl
theorem inl_eq_prod : inl R M M₂ = prod LinearMap.id 0 :=
rfl
theorem inr_eq_prod : inr R M M₂ = prod 0 LinearMap.id :=
rfl
theorem inl_injective : Function.Injective (inl R M M₂) := fun _ => by simp
theorem inr_injective : Function.Injective (inr R M M₂) := fun _ => by simp
/-- The coprod function `x : M × M₂ ↦ f x.1 + g x.2` is a linear map. -/
def coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : M × M₂ →ₗ[R] M₃ :=
f.comp (fst _ _ _) + g.comp (snd _ _ _)
@[simp]
theorem coprod_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (x : M × M₂) :
coprod f g x = f x.1 + g x.2 :=
rfl
@[simp]
theorem coprod_inl (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (coprod f g).comp (inl R M M₂) = f := by
ext; simp only [map_zero, add_zero, coprod_apply, inl_apply, comp_apply]
@[simp]
theorem coprod_inr (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (coprod f g).comp (inr R M M₂) = g := by
ext; simp only [map_zero, coprod_apply, inr_apply, zero_add, comp_apply]
@[simp]
theorem coprod_inl_inr : coprod (inl R M M₂) (inr R M M₂) = LinearMap.id := by
ext <;>
simp only [Prod.mk_add_mk, add_zero, id_apply, coprod_apply, inl_apply, inr_apply, zero_add]
theorem coprod_zero_left (g : M₂ →ₗ[R] M₃) : (0 : M →ₗ[R] M₃).coprod g = g.comp (snd R M M₂) :=
zero_add _
theorem coprod_zero_right (f : M →ₗ[R] M₃) : f.coprod (0 : M₂ →ₗ[R] M₃) = f.comp (fst R M M₂) :=
add_zero _
theorem comp_coprod (f : M₃ →ₗ[R] M₄) (g₁ : M →ₗ[R] M₃) (g₂ : M₂ →ₗ[R] M₃) :
f.comp (g₁.coprod g₂) = (f.comp g₁).coprod (f.comp g₂) :=
ext fun x => f.map_add (g₁ x.1) (g₂ x.2)
theorem fst_eq_coprod : fst R M M₂ = coprod LinearMap.id 0 := by ext; simp
theorem snd_eq_coprod : snd R M M₂ = coprod 0 LinearMap.id := by ext; simp
@[simp]
theorem coprod_comp_prod (f : M₂ →ₗ[R] M₄) (g : M₃ →ₗ[R] M₄) (f' : M →ₗ[R] M₂) (g' : M →ₗ[R] M₃) :
(f.coprod g).comp (f'.prod g') = f.comp f' + g.comp g' :=
rfl
@[simp]
theorem coprod_map_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (S : Submodule R M)
(S' : Submodule R M₂) : (Submodule.prod S S').map (LinearMap.coprod f g) = S.map f ⊔ S'.map g :=
SetLike.coe_injective <| by
simp only [LinearMap.coprod_apply, Submodule.coe_sup, Submodule.map_coe]
rw [← Set.image2_add, Set.image2_image_left, Set.image2_image_right]
exact Set.image_prod fun m m₂ => f m + g m₂
/-- Taking the product of two maps with the same codomain is equivalent to taking the product of
their domains.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/
@[simps]
def coprodEquiv [Module S M₃] [SMulCommClass R S M₃] :
((M →ₗ[R] M₃) × (M₂ →ₗ[R] M₃)) ≃ₗ[S] M × M₂ →ₗ[R] M₃ where
toFun f := f.1.coprod f.2
invFun f := (f.comp (inl _ _ _), f.comp (inr _ _ _))
left_inv f := by simp only [coprod_inl, coprod_inr]
right_inv f := by simp only [← comp_coprod, comp_id, coprod_inl_inr]
map_add' a b := by
ext
simp only [Prod.snd_add, add_apply, coprod_apply, Prod.fst_add, add_add_add_comm]
map_smul' r a := by
dsimp
ext
simp only [smul_add, smul_apply, Prod.smul_snd, Prod.smul_fst, coprod_apply]
theorem prod_ext_iff {f g : M × M₂ →ₗ[R] M₃} :
f = g ↔ f.comp (inl _ _ _) = g.comp (inl _ _ _) ∧ f.comp (inr _ _ _) = g.comp (inr _ _ _) :=
(coprodEquiv ℕ).symm.injective.eq_iff.symm.trans Prod.ext_iff
/--
Split equality of linear maps from a product into linear maps over each component, to allow `ext`
to apply lemmas specific to `M →ₗ M₃` and `M₂ →ₗ M₃`.
See note [partially-applied ext lemmas]. -/
@[ext 1100]
theorem prod_ext {f g : M × M₂ →ₗ[R] M₃} (hl : f.comp (inl _ _ _) = g.comp (inl _ _ _))
(hr : f.comp (inr _ _ _) = g.comp (inr _ _ _)) : f = g :=
prod_ext_iff.2 ⟨hl, hr⟩
/-- `prod.map` of two linear maps. -/
def prodMap (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : M × M₂ →ₗ[R] M₃ × M₄ :=
(f.comp (fst R M M₂)).prod (g.comp (snd R M M₂))
theorem coe_prodMap (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : ⇑(f.prodMap g) = Prod.map f g :=
rfl
@[simp]
theorem prodMap_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (x) : f.prodMap g x = (f x.1, g x.2) :=
rfl
theorem prodMap_comap_prod (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) (S : Submodule R M₂)
(S' : Submodule R M₄) :
(Submodule.prod S S').comap (LinearMap.prodMap f g) = (S.comap f).prod (S'.comap g) :=
SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _
theorem ker_prodMap (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) :
ker (LinearMap.prodMap f g) = Submodule.prod (ker f) (ker g) := by
dsimp only [ker]
rw [← prodMap_comap_prod, Submodule.prod_bot]
@[simp]
theorem prodMap_id : (id : M →ₗ[R] M).prodMap (id : M₂ →ₗ[R] M₂) = id :=
rfl
@[simp]
theorem prodMap_one : (1 : M →ₗ[R] M).prodMap (1 : M₂ →ₗ[R] M₂) = 1 :=
rfl
theorem prodMap_comp (f₁₂ : M →ₗ[R] M₂) (f₂₃ : M₂ →ₗ[R] M₃) (g₁₂ : M₄ →ₗ[R] M₅)
(g₂₃ : M₅ →ₗ[R] M₆) :
f₂₃.prodMap g₂₃ ∘ₗ f₁₂.prodMap g₁₂ = (f₂₃ ∘ₗ f₁₂).prodMap (g₂₃ ∘ₗ g₁₂) :=
rfl
theorem prodMap_mul (f₁₂ : M →ₗ[R] M) (f₂₃ : M →ₗ[R] M) (g₁₂ : M₂ →ₗ[R] M₂) (g₂₃ : M₂ →ₗ[R] M₂) :
f₂₃.prodMap g₂₃ * f₁₂.prodMap g₁₂ = (f₂₃ * f₁₂).prodMap (g₂₃ * g₁₂) :=
rfl
theorem prodMap_add (f₁ : M →ₗ[R] M₃) (f₂ : M →ₗ[R] M₃) (g₁ : M₂ →ₗ[R] M₄) (g₂ : M₂ →ₗ[R] M₄) :
(f₁ + f₂).prodMap (g₁ + g₂) = f₁.prodMap g₁ + f₂.prodMap g₂ :=
rfl
@[simp]
theorem prodMap_zero : (0 : M →ₗ[R] M₂).prodMap (0 : M₃ →ₗ[R] M₄) = 0 :=
rfl
@[simp]
theorem prodMap_smul [Module S M₃] [Module S M₄] [SMulCommClass R S M₃] [SMulCommClass R S M₄]
(s : S) (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : prodMap (s • f) (s • g) = s • prodMap f g :=
rfl
variable (R M M₂ M₃ M₄)
/-- `LinearMap.prodMap` as a `LinearMap` -/
@[simps]
def prodMapLinear [Module S M₃] [Module S M₄] [SMulCommClass R S M₃] [SMulCommClass R S M₄] :
(M →ₗ[R] M₃) × (M₂ →ₗ[R] M₄) →ₗ[S] M × M₂ →ₗ[R] M₃ × M₄ where
toFun f := prodMap f.1 f.2
map_add' _ _ := rfl
map_smul' _ _ := rfl
/-- `LinearMap.prodMap` as a `RingHom` -/
@[simps]
def prodMapRingHom : (M →ₗ[R] M) × (M₂ →ₗ[R] M₂) →+* M × M₂ →ₗ[R] M × M₂ where
toFun f := prodMap f.1 f.2
map_one' := prodMap_one
map_zero' := rfl
map_add' _ _ := rfl
map_mul' _ _ := rfl
variable {R M M₂ M₃ M₄}
section map_mul
variable {A : Type*} [NonUnitalNonAssocSemiring A] [Module R A]
variable {B : Type*} [NonUnitalNonAssocSemiring B] [Module R B]
theorem inl_map_mul (a₁ a₂ : A) :
LinearMap.inl R A B (a₁ * a₂) = LinearMap.inl R A B a₁ * LinearMap.inl R A B a₂ :=
Prod.ext rfl (by simp)
theorem inr_map_mul (b₁ b₂ : B) :
LinearMap.inr R A B (b₁ * b₂) = LinearMap.inr R A B b₁ * LinearMap.inr R A B b₂ :=
Prod.ext (by simp) rfl
end map_mul
end LinearMap
end Prod
namespace LinearMap
variable (R M M₂)
variable [CommSemiring R]
variable [AddCommMonoid M] [AddCommMonoid M₂]
variable [Module R M] [Module R M₂]
/-- `LinearMap.prodMap` as an `AlgHom` -/
@[simps!]
def prodMapAlgHom : Module.End R M × Module.End R M₂ →ₐ[R] Module.End R (M × M₂) :=
{ prodMapRingHom R M M₂ with commutes' := fun _ => rfl }
end LinearMap
namespace LinearMap
open Submodule
variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄]
[Module R M] [Module R M₂] [Module R M₃] [Module R M₄]
theorem range_coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : range (f.coprod g) = range f ⊔ range g :=
Submodule.ext fun x => by simp [mem_sup]
theorem isCompl_range_inl_inr : IsCompl (range <| inl R M M₂) (range <| inr R M M₂) := by
constructor
· rw [disjoint_def]
rintro ⟨_, _⟩ ⟨x, hx⟩ ⟨y, hy⟩
simp only [Prod.ext_iff, inl_apply, inr_apply, mem_bot] at hx hy ⊢
exact ⟨hy.1.symm, hx.2.symm⟩
· rw [codisjoint_iff_le_sup]
rintro ⟨x, y⟩ -
simp only [mem_sup, mem_range, exists_prop]
refine ⟨(x, 0), ⟨x, rfl⟩, (0, y), ⟨y, rfl⟩, ?_⟩
simp
theorem sup_range_inl_inr : (range <| inl R M M₂) ⊔ (range <| inr R M M₂) = ⊤ :=
IsCompl.sup_eq_top isCompl_range_inl_inr
theorem disjoint_inl_inr : Disjoint (range <| inl R M M₂) (range <| inr R M M₂) := by
simp (config := { contextual := true }) [disjoint_def, @eq_comm M 0, @eq_comm M₂ 0]
theorem map_coprod_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (p : Submodule R M)
(q : Submodule R M₂) : map (coprod f g) (p.prod q) = map f p ⊔ map g q := by
refine le_antisymm ?_ (sup_le (map_le_iff_le_comap.2 ?_) (map_le_iff_le_comap.2 ?_))
· rw [SetLike.le_def]
rintro _ ⟨x, ⟨h₁, h₂⟩, rfl⟩
exact mem_sup.2 ⟨_, ⟨_, h₁, rfl⟩, _, ⟨_, h₂, rfl⟩, rfl⟩
· exact fun x hx => ⟨(x, 0), by simp [hx]⟩
· exact fun x hx => ⟨(0, x), by simp [hx]⟩
theorem comap_prod_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) (p : Submodule R M₂)
(q : Submodule R M₃) : comap (prod f g) (p.prod q) = comap f p ⊓ comap g q :=
Submodule.ext fun _x => Iff.rfl
theorem prod_eq_inf_comap (p : Submodule R M) (q : Submodule R M₂) :
p.prod q = p.comap (LinearMap.fst R M M₂) ⊓ q.comap (LinearMap.snd R M M₂) :=
Submodule.ext fun _x => Iff.rfl
theorem prod_eq_sup_map (p : Submodule R M) (q : Submodule R M₂) :
p.prod q = p.map (LinearMap.inl R M M₂) ⊔ q.map (LinearMap.inr R M M₂) := by
rw [← map_coprod_prod, coprod_inl_inr, map_id]
theorem span_inl_union_inr {s : Set M} {t : Set M₂} :
span R (inl R M M₂ '' s ∪ inr R M M₂ '' t) = (span R s).prod (span R t) := by
rw [span_union, prod_eq_sup_map, ← span_image, ← span_image]
@[simp]
theorem ker_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ker (prod f g) = ker f ⊓ ker g := by
rw [ker, ← prod_bot, comap_prod_prod]; rfl
theorem range_prod_le (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) :
range (prod f g) ≤ (range f).prod (range g) := by
simp only [SetLike.le_def, prod_apply, mem_range, SetLike.mem_coe, mem_prod, exists_imp]
rintro _ x rfl
exact ⟨⟨x, rfl⟩, ⟨x, rfl⟩⟩
theorem ker_prod_ker_le_ker_coprod {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] {M₃ : Type*}
[AddCommGroup M₃] [Module R M₃] (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) :
(ker f).prod (ker g) ≤ ker (f.coprod g) := by
rintro ⟨y, z⟩
simp (config := { contextual := true })
theorem ker_coprod_of_disjoint_range {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] {M₃ : Type*}
[AddCommGroup M₃] [Module R M₃] (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃)
(hd : Disjoint (range f) (range g)) : ker (f.coprod g) = (ker f).prod (ker g) := by
apply le_antisymm _ (ker_prod_ker_le_ker_coprod f g)
rintro ⟨y, z⟩ h
simp only [mem_ker, mem_prod, coprod_apply] at h ⊢
have : f y ∈ (range f) ⊓ (range g) := by
simp only [true_and_iff, mem_range, mem_inf, exists_apply_eq_apply]
use -z
rwa [eq_comm, map_neg, ← sub_eq_zero, sub_neg_eq_add]
rw [hd.eq_bot, mem_bot] at this
rw [this] at h
simpa [this] using h
end LinearMap
namespace Submodule
open LinearMap
variable [Semiring R]
variable [AddCommMonoid M] [AddCommMonoid M₂]
variable [Module R M] [Module R M₂]
theorem sup_eq_range (p q : Submodule R M) : p ⊔ q = range (p.subtype.coprod q.subtype) :=
Submodule.ext fun x => by simp [Submodule.mem_sup, SetLike.exists]
variable (p : Submodule R M) (q : Submodule R M₂)
@[simp]
theorem map_inl : p.map (inl R M M₂) = prod p ⊥ := by
ext ⟨x, y⟩
simp only [and_left_comm, eq_comm, mem_map, Prod.mk.inj_iff, inl_apply, mem_bot, exists_eq_left',
mem_prod]
@[simp]
theorem map_inr : q.map (inr R M M₂) = prod ⊥ q := by
ext ⟨x, y⟩; simp [and_left_comm, eq_comm, and_comm]
@[simp]
theorem comap_fst : p.comap (fst R M M₂) = prod p ⊤ := by ext ⟨x, y⟩; simp
@[simp]
theorem comap_snd : q.comap (snd R M M₂) = prod ⊤ q := by ext ⟨x, y⟩; simp
@[simp]
theorem prod_comap_inl : (prod p q).comap (inl R M M₂) = p := by ext; simp
@[simp]
theorem prod_comap_inr : (prod p q).comap (inr R M M₂) = q := by ext; simp
@[simp]
theorem prod_map_fst : (prod p q).map (fst R M M₂) = p := by
ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ q)]
@[simp]
theorem prod_map_snd : (prod p q).map (snd R M M₂) = q := by
ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ p)]
@[simp]
theorem ker_inl : ker (inl R M M₂) = ⊥ := by rw [ker, ← prod_bot, prod_comap_inl]
@[simp]
theorem ker_inr : ker (inr R M M₂) = ⊥ := by rw [ker, ← prod_bot, prod_comap_inr]
@[simp]
theorem range_fst : range (fst R M M₂) = ⊤ := by rw [range_eq_map, ← prod_top, prod_map_fst]
@[simp]
theorem range_snd : range (snd R M M₂) = ⊤ := by rw [range_eq_map, ← prod_top, prod_map_snd]
variable (R M M₂)
/-- `M` as a submodule of `M × N`. -/
def fst : Submodule R (M × M₂) :=
(⊥ : Submodule R M₂).comap (LinearMap.snd R M M₂)
/-- `M` as a submodule of `M × N` is isomorphic to `M`. -/
@[simps]
def fstEquiv : Submodule.fst R M M₂ ≃ₗ[R] M where
-- Porting note: proofs were `tidy` or `simp`
toFun x := x.1.1
invFun m := ⟨⟨m, 0⟩, by simp only [fst, comap_bot, mem_ker, snd_apply]⟩
map_add' := by simp only [AddSubmonoid.coe_add, coe_toAddSubmonoid, Prod.fst_add, Subtype.forall,
implies_true, Prod.forall, forall_const]
map_smul' := by simp only [SetLike.val_smul, Prod.smul_fst, RingHom.id_apply, Subtype.forall,
implies_true, Prod.forall, forall_const]
left_inv := by
rintro ⟨⟨x, y⟩, hy⟩
simp only [fst, comap_bot, mem_ker, snd_apply] at hy
simpa only [Subtype.mk.injEq, Prod.mk.injEq, true_and] using hy.symm
right_inv := by rintro x; rfl
theorem fst_map_fst : (Submodule.fst R M M₂).map (LinearMap.fst R M M₂) = ⊤ := by
-- Porting note (#10936): was `tidy`
rw [eq_top_iff]; rintro x -
simp only [fst, comap_bot, mem_map, mem_ker, snd_apply, fst_apply,
Prod.exists, exists_eq_left, exists_eq]
theorem fst_map_snd : (Submodule.fst R M M₂).map (LinearMap.snd R M M₂) = ⊥ := by
-- Porting note (#10936): was `tidy`
rw [eq_bot_iff]; intro x
simp only [fst, comap_bot, mem_map, mem_ker, snd_apply, eq_comm, Prod.exists, exists_eq_left,
exists_const, mem_bot, imp_self]
/-- `N` as a submodule of `M × N`. -/
def snd : Submodule R (M × M₂) :=
(⊥ : Submodule R M).comap (LinearMap.fst R M M₂)
/-- `N` as a submodule of `M × N` is isomorphic to `N`. -/
@[simps]
def sndEquiv : Submodule.snd R M M₂ ≃ₗ[R] M₂ where
-- Porting note: proofs were `tidy` or `simp`
toFun x := x.1.2
invFun n := ⟨⟨0, n⟩, by simp only [snd, comap_bot, mem_ker, fst_apply]⟩
map_add' := by simp only [AddSubmonoid.coe_add, coe_toAddSubmonoid, Prod.snd_add, Subtype.forall,
implies_true, Prod.forall, forall_const]
map_smul' := by simp only [SetLike.val_smul, Prod.smul_snd, RingHom.id_apply, Subtype.forall,
implies_true, Prod.forall, forall_const]
left_inv := by
rintro ⟨⟨x, y⟩, hx⟩
simp only [snd, comap_bot, mem_ker, fst_apply] at hx
simpa only [Subtype.mk.injEq, Prod.mk.injEq, and_true] using hx.symm
right_inv := by rintro x; rfl
theorem snd_map_fst : (Submodule.snd R M M₂).map (LinearMap.fst R M M₂) = ⊥ := by
-- Porting note (#10936): was `tidy`
rw [eq_bot_iff]; intro x
simp only [snd, comap_bot, mem_map, mem_ker, fst_apply, eq_comm, Prod.exists, exists_eq_left,
exists_const, mem_bot, imp_self]
theorem snd_map_snd : (Submodule.snd R M M₂).map (LinearMap.snd R M M₂) = ⊤ := by
-- Porting note (#10936): was `tidy`
rw [eq_top_iff]; rintro x -
simp only [snd, comap_bot, mem_map, mem_ker, snd_apply, fst_apply,
Prod.exists, exists_eq_right, exists_eq]
theorem fst_sup_snd : Submodule.fst R M M₂ ⊔ Submodule.snd R M M₂ = ⊤ := by
rw [eq_top_iff]
rintro ⟨m, n⟩ -
rw [show (m, n) = (m, 0) + (0, n) by simp]
apply Submodule.add_mem (Submodule.fst R M M₂ ⊔ Submodule.snd R M M₂)
· exact Submodule.mem_sup_left (Submodule.mem_comap.mpr (by simp))
· exact Submodule.mem_sup_right (Submodule.mem_comap.mpr (by simp))
theorem fst_inf_snd : Submodule.fst R M M₂ ⊓ Submodule.snd R M M₂ = ⊥ := by
-- Porting note (#10936): was `tidy`
rw [eq_bot_iff]; rintro ⟨x, y⟩
simp only [fst, comap_bot, snd, mem_inf, mem_ker, snd_apply, fst_apply, mem_bot,
Prod.mk_eq_zero, and_comm, imp_self]
theorem le_prod_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} {q : Submodule R (M × M₂)} :
q ≤ p₁.prod p₂ ↔ map (LinearMap.fst R M M₂) q ≤ p₁ ∧ map (LinearMap.snd R M M₂) q ≤ p₂ := by
constructor
· intro h
constructor
· rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩
exact (h hy1).1
· rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩
exact (h hy1).2
· rintro ⟨hH, hK⟩ ⟨x1, x2⟩ h
exact ⟨hH ⟨_, h, rfl⟩, hK ⟨_, h, rfl⟩⟩
theorem prod_le_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} {q : Submodule R (M × M₂)} :
p₁.prod p₂ ≤ q ↔ map (LinearMap.inl R M M₂) p₁ ≤ q ∧ map (LinearMap.inr R M M₂) p₂ ≤ q := by
constructor
· intro h
constructor
· rintro _ ⟨x, hx, rfl⟩
apply h
exact ⟨hx, zero_mem p₂⟩
· rintro _ ⟨x, hx, rfl⟩
apply h
exact ⟨zero_mem p₁, hx⟩
· rintro ⟨hH, hK⟩ ⟨x1, x2⟩ ⟨h1, h2⟩
have h1' : (LinearMap.inl R _ _) x1 ∈ q := by
apply hH
simpa using h1
have h2' : (LinearMap.inr R _ _) x2 ∈ q := by
apply hK
simpa using h2
simpa using add_mem h1' h2'
theorem prod_eq_bot_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} :
p₁.prod p₂ = ⊥ ↔ p₁ = ⊥ ∧ p₂ = ⊥ := by
simp only [eq_bot_iff, prod_le_iff, (gc_map_comap _).le_iff_le, comap_bot, ker_inl, ker_inr]
theorem prod_eq_top_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} :
p₁.prod p₂ = ⊤ ↔ p₁ = ⊤ ∧ p₂ = ⊤ := by
simp only [eq_top_iff, le_prod_iff, ← (gc_map_comap _).le_iff_le, map_top, range_fst, range_snd]
end Submodule
namespace LinearEquiv
/-- Product of modules is commutative up to linear isomorphism. -/
@[simps apply]
def prodComm (R M N : Type*) [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M]
[Module R N] : (M × N) ≃ₗ[R] N × M :=
{ AddEquiv.prodComm with
toFun := Prod.swap
map_smul' := fun _r ⟨_m, _n⟩ => rfl }
section prodComm
variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂]
theorem fst_comp_prodComm :
(LinearMap.fst R M₂ M).comp (prodComm R M M₂).toLinearMap = (LinearMap.snd R M M₂) := by
ext <;> simp
theorem snd_comp_prodComm :
(LinearMap.snd R M₂ M).comp (prodComm R M M₂).toLinearMap = (LinearMap.fst R M M₂) := by
ext <;> simp
end prodComm
section
variable (R M M₂ M₃ M₄)
variable [Semiring R]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄]
variable [Module R M] [Module R M₂] [Module R M₃] [Module R M₄]
/-- Four-way commutativity of `prod`. The name matches `mul_mul_mul_comm`. -/
@[simps apply]
def prodProdProdComm : ((M × M₂) × M₃ × M₄) ≃ₗ[R] (M × M₃) × M₂ × M₄ :=
{ AddEquiv.prodProdProdComm M M₂ M₃ M₄ with
toFun := fun mnmn => ((mnmn.1.1, mnmn.2.1), (mnmn.1.2, mnmn.2.2))
invFun := fun mmnn => ((mmnn.1.1, mmnn.2.1), (mmnn.1.2, mmnn.2.2))
map_smul' := fun _c _mnmn => rfl }
@[simp]
theorem prodProdProdComm_symm :
(prodProdProdComm R M M₂ M₃ M₄).symm = prodProdProdComm R M M₃ M₂ M₄ :=
rfl
@[simp]
theorem prodProdProdComm_toAddEquiv :
(prodProdProdComm R M M₂ M₃ M₄ : _ ≃+ _) = AddEquiv.prodProdProdComm M M₂ M₃ M₄ :=
rfl
end
section
variable [Semiring R]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄]
variable {module_M : Module R M} {module_M₂ : Module R M₂}
variable {module_M₃ : Module R M₃} {module_M₄ : Module R M₄}
variable (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄)
/-- Product of linear equivalences; the maps come from `Equiv.prodCongr`. -/
protected def prod : (M × M₃) ≃ₗ[R] M₂ × M₄ :=
{ e₁.toAddEquiv.prodCongr e₂.toAddEquiv with
map_smul' := fun c _x => Prod.ext (e₁.map_smulₛₗ c _) (e₂.map_smulₛₗ c _) }
theorem prod_symm : (e₁.prod e₂).symm = e₁.symm.prod e₂.symm :=
rfl
@[simp]
theorem prod_apply (p) : e₁.prod e₂ p = (e₁ p.1, e₂ p.2) :=
rfl
@[simp, norm_cast]
theorem coe_prod :
(e₁.prod e₂ : M × M₃ →ₗ[R] M₂ × M₄) = (e₁ : M →ₗ[R] M₂).prodMap (e₂ : M₃ →ₗ[R] M₄) :=
rfl
end
section
variable [Semiring R]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommGroup M₄]
variable {module_M : Module R M} {module_M₂ : Module R M₂}
variable {module_M₃ : Module R M₃} {module_M₄ : Module R M₄}
variable (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄)
/-- Equivalence given by a block lower diagonal matrix. `e₁` and `e₂` are diagonal square blocks,
and `f` is a rectangular block below the diagonal. -/
protected def skewProd (f : M →ₗ[R] M₄) : (M × M₃) ≃ₗ[R] M₂ × M₄ :=
{ ((e₁ : M →ₗ[R] M₂).comp (LinearMap.fst R M M₃)).prod
((e₂ : M₃ →ₗ[R] M₄).comp (LinearMap.snd R M M₃) +
f.comp (LinearMap.fst R M M₃)) with
invFun := fun p : M₂ × M₄ => (e₁.symm p.1, e₂.symm (p.2 - f (e₁.symm p.1)))
left_inv := fun p => by simp
right_inv := fun p => by simp }
@[simp]
theorem skewProd_apply (f : M →ₗ[R] M₄) (x) : e₁.skewProd e₂ f x = (e₁ x.1, e₂ x.2 + f x.1) :=
rfl
@[simp]
theorem skewProd_symm_apply (f : M →ₗ[R] M₄) (x) :
(e₁.skewProd e₂ f).symm x = (e₁.symm x.1, e₂.symm (x.2 - f (e₁.symm x.1))) :=
rfl
end
end LinearEquiv
namespace LinearMap
open Submodule
variable [Ring R]
variable [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃]
variable [Module R M] [Module R M₂] [Module R M₃]
/-- If the union of the kernels `ker f` and `ker g` spans the domain, then the range of
`Prod f g` is equal to the product of `range f` and `range g`. -/
theorem range_prod_eq {f : M →ₗ[R] M₂} {g : M →ₗ[R] M₃} (h : ker f ⊔ ker g = ⊤) :
range (prod f g) = (range f).prod (range g) := by
refine le_antisymm (f.range_prod_le g) ?_
simp only [SetLike.le_def, prod_apply, mem_range, SetLike.mem_coe, mem_prod, exists_imp, and_imp,
Prod.forall, Pi.prod]
rintro _ _ x rfl y rfl
-- Note: #8386 had to specify `(f := f)`
simp only [Prod.mk.inj_iff, ← sub_mem_ker_iff (f := f)]
have : y - x ∈ ker f ⊔ ker g := by simp only [h, mem_top]
rcases mem_sup.1 this with ⟨x', hx', y', hy', H⟩
refine ⟨x' + x, ?_, ?_⟩
· rwa [add_sub_cancel_right]
· simp [← eq_sub_iff_add_eq.1 H, map_add, add_left_inj, self_eq_add_right, mem_ker.mp hy']
end LinearMap
namespace LinearMap
/-!
## Tunnels and tailings
NOTE: The proof of strong rank condition for noetherian rings is changed.
`LinearMap.tunnel` and `LinearMap.tailing` are not used in mathlib anymore.
These are marked as deprecated with no replacements.
If you use them in external projects, please consider using other arguments instead.
Some preliminary work for establishing the strong rank condition for noetherian rings.
Given a morphism `f : M × N →ₗ[R] M` which is `i : Injective f`,
we can find an infinite decreasing `tunnel f i n` of copies of `M` inside `M`,
and sitting beside these, an infinite sequence of copies of `N`.
We picturesquely name these as `tailing f i n` for each individual copy of `N`,
and `tailings f i n` for the supremum of the first `n+1` copies:
they are the pieces left behind, sitting inside the tunnel.
By construction, each `tailing f i (n+1)` is disjoint from `tailings f i n`;
later, when we assume `M` is noetherian, this implies that `N` must be trivial,
and establishes the strong rank condition for any left-noetherian ring.
-/
noncomputable section Tunnel
-- (This doesn't work over a semiring: we need to use that `Submodule R M` is a modular lattice,
-- which requires cancellation.)
variable [Ring R]
variable {N : Type*} [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
open Function
set_option linter.deprecated false
/-- An auxiliary construction for `tunnel`.
The composition of `f`, followed by the isomorphism back to `K`,
followed by the inclusion of this submodule back into `M`. -/
@[deprecated (since := "2024-06-05")]
def tunnelAux (f : M × N →ₗ[R] M) (Kφ : ΣK : Submodule R M, K ≃ₗ[R] M) : M × N →ₗ[R] M :=
(Kφ.1.subtype.comp Kφ.2.symm.toLinearMap).comp f
@[deprecated (since := "2024-06-05")]
theorem tunnelAux_injective (f : M × N →ₗ[R] M) (i : Injective f)
(Kφ : ΣK : Submodule R M, K ≃ₗ[R] M) : Injective (tunnelAux f Kφ) :=
(Subtype.val_injective.comp Kφ.2.symm.injective).comp i
/-- Auxiliary definition for `tunnel`. -/
@[deprecated (since := "2024-06-05")]
def tunnel' (f : M × N →ₗ[R] M) (i : Injective f) : ℕ → ΣK : Submodule R M, K ≃ₗ[R] M
| 0 => ⟨⊤, LinearEquiv.ofTop ⊤ rfl⟩
| n + 1 =>
⟨(Submodule.fst R M N).map (tunnelAux f (tunnel' f i n)),
((Submodule.fst R M N).equivMapOfInjective _
(tunnelAux_injective f i (tunnel' f i n))).symm.trans (Submodule.fstEquiv R M N)⟩
/-- Give an injective map `f : M × N →ₗ[R] M` we can find a nested sequence of submodules
all isomorphic to `M`.
-/
@[deprecated (since := "2024-06-05")]
def tunnel (f : M × N →ₗ[R] M) (i : Injective f) : ℕ →o (Submodule R M)ᵒᵈ :=
-- Note: the hint `(α := _)` had to be added in #8386
⟨fun n => OrderDual.toDual (α := Submodule R M) (tunnel' f i n).1,
monotone_nat_of_le_succ fun n => by
dsimp [tunnel', tunnelAux]
rw [Submodule.map_comp, Submodule.map_comp]
apply Submodule.map_subtype_le⟩
/-- Give an injective map `f : M × N →ₗ[R] M` we can find a sequence of submodules
all isomorphic to `N`.
-/
@[deprecated (since := "2024-06-05")]
def tailing (f : M × N →ₗ[R] M) (i : Injective f) (n : ℕ) : Submodule R M :=
(Submodule.snd R M N).map (tunnelAux f (tunnel' f i n))
/-- Each `tailing f i n` is a copy of `N`. -/
@[deprecated (since := "2024-06-05")]
def tailingLinearEquiv (f : M × N →ₗ[R] M) (i : Injective f) (n : ℕ) : tailing f i n ≃ₗ[R] N :=
((Submodule.snd R M N).equivMapOfInjective _ (tunnelAux_injective f i (tunnel' f i n))).symm.trans
(Submodule.sndEquiv R M N)
@[deprecated (since := "2024-06-05")]
theorem tailing_le_tunnel (f : M × N →ₗ[R] M) (i : Injective f) (n : ℕ) :
tailing f i n ≤ OrderDual.ofDual (α := Submodule R M) (tunnel f i n) := by
dsimp [tailing, tunnelAux]
rw [Submodule.map_comp, Submodule.map_comp]
apply Submodule.map_subtype_le
@[deprecated (since := "2024-06-05")]
theorem tailing_disjoint_tunnel_succ (f : M × N →ₗ[R] M) (i : Injective f) (n : ℕ) :
Disjoint (tailing f i n) (OrderDual.ofDual (α := Submodule R M) <| tunnel f i (n + 1)) := by
rw [disjoint_iff]
dsimp [tailing, tunnel, tunnel']
erw [Submodule.map_inf_eq_map_inf_comap,
Submodule.comap_map_eq_of_injective (tunnelAux_injective _ i _), inf_comm,
Submodule.fst_inf_snd, Submodule.map_bot]
@[deprecated (since := "2024-06-05")]
theorem tailing_sup_tunnel_succ_le_tunnel (f : M × N →ₗ[R] M) (i : Injective f) (n : ℕ) :
tailing f i n ⊔ (OrderDual.ofDual (α := Submodule R M) $ tunnel f i (n + 1)) ≤
(OrderDual.ofDual (α := Submodule R M) <| tunnel f i n) := by
dsimp [tailing, tunnel, tunnel', tunnelAux]
erw [← Submodule.map_sup, sup_comm, Submodule.fst_sup_snd, Submodule.map_comp, Submodule.map_comp]
apply Submodule.map_subtype_le
/-- The supremum of all the copies of `N` found inside the tunnel. -/
@[deprecated (since := "2024-06-05")]
def tailings (f : M × N →ₗ[R] M) (i : Injective f) : ℕ → Submodule R M :=
partialSups (tailing f i)
@[simp, deprecated (since := "2024-06-05")]
theorem tailings_zero (f : M × N →ₗ[R] M) (i : Injective f) : tailings f i 0 = tailing f i 0 := by
simp [tailings]
@[simp, deprecated (since := "2024-06-05")]
theorem tailings_succ (f : M × N →ₗ[R] M) (i : Injective f) (n : ℕ) :
tailings f i (n + 1) = tailings f i n ⊔ tailing f i (n + 1) := by simp [tailings]
@[deprecated (since := "2024-06-05")]
theorem tailings_disjoint_tunnel (f : M × N →ₗ[R] M) (i : Injective f) (n : ℕ) :
Disjoint (tailings f i n) (OrderDual.ofDual (α := Submodule R M) <| tunnel f i (n + 1)) := by
induction' n with n ih
· simp only [tailings_zero]
apply tailing_disjoint_tunnel_succ
· simp only [tailings_succ]
refine Disjoint.disjoint_sup_left_of_disjoint_sup_right ?_ ?_
· apply tailing_disjoint_tunnel_succ
· apply Disjoint.mono_right _ ih
apply tailing_sup_tunnel_succ_le_tunnel
@[deprecated (since := "2024-06-05")]
theorem tailings_disjoint_tailing (f : M × N →ₗ[R] M) (i : Injective f) (n : ℕ) :
Disjoint (tailings f i n) (tailing f i (n + 1)) :=
Disjoint.mono_right (tailing_le_tunnel f i _) (tailings_disjoint_tunnel f i _)
end Tunnel
section Graph
variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommGroup M₃] [AddCommGroup M₄]
[Module R M] [Module R M₂] [Module R M₃] [Module R M₄] (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄)
/-- Graph of a linear map. -/
def graph : Submodule R (M × M₂) where
carrier := { p | p.2 = f p.1 }
add_mem' (ha : _ = _) (hb : _ = _) := by
change _ + _ = f (_ + _)
rw [map_add, ha, hb]
zero_mem' := Eq.symm (map_zero f)
smul_mem' c x (hx : _ = _) := by
change _ • _ = f (_ • _)
rw [map_smul, hx]
@[simp]
theorem mem_graph_iff (x : M × M₂) : x ∈ f.graph ↔ x.2 = f x.1 :=
Iff.rfl
theorem graph_eq_ker_coprod : g.graph = ker ((-g).coprod LinearMap.id) := by
ext x
change _ = _ ↔ -g x.1 + x.2 = _
rw [add_comm, add_neg_eq_zero]
theorem graph_eq_range_prod : f.graph = range (LinearMap.id.prod f) := by
ext x
exact ⟨fun hx => ⟨x.1, Prod.ext rfl hx.symm⟩, fun ⟨u, hu⟩ => hu ▸ rfl⟩
end Graph
end LinearMap
|
LinearAlgebra\Projection.lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.LinearAlgebra.Quotient
import Mathlib.LinearAlgebra.Prod
/-!
# Projection to a subspace
In this file we define
* `Submodule.linearProjOfIsCompl (p q : Submodule R E) (h : IsCompl p q)`:
the projection of a module `E` to a submodule `p` along its complement `q`;
it is the unique linear map `f : E → p` such that `f x = x` for `x ∈ p` and `f x = 0` for `x ∈ q`.
* `Submodule.isComplEquivProj p`: equivalence between submodules `q`
such that `IsCompl p q` and projections `f : E → p`, `∀ x ∈ p, f x = x`.
We also provide some lemmas justifying correctness of our definitions.
## Tags
projection, complement subspace
-/
noncomputable section Ring
variable {R : Type*} [Ring R] {E : Type*} [AddCommGroup E] [Module R E]
variable {F : Type*} [AddCommGroup F] [Module R F] {G : Type*} [AddCommGroup G] [Module R G]
variable (p q : Submodule R E)
variable {S : Type*} [Semiring S] {M : Type*} [AddCommMonoid M] [Module S M] (m : Submodule S M)
namespace LinearMap
variable {p}
open Submodule
theorem ker_id_sub_eq_of_proj {f : E →ₗ[R] p} (hf : ∀ x : p, f x = x) :
ker (id - p.subtype.comp f) = p := by
ext x
simp only [comp_apply, mem_ker, subtype_apply, sub_apply, id_apply, sub_eq_zero]
exact ⟨fun h => h.symm ▸ Submodule.coe_mem _, fun hx => by erw [hf ⟨x, hx⟩, Subtype.coe_mk]⟩
theorem range_eq_of_proj {f : E →ₗ[R] p} (hf : ∀ x : p, f x = x) : range f = ⊤ :=
range_eq_top.2 fun x => ⟨x, hf x⟩
theorem isCompl_of_proj {f : E →ₗ[R] p} (hf : ∀ x : p, f x = x) : IsCompl p (ker f) := by
constructor
· rw [disjoint_iff_inf_le]
rintro x ⟨hpx, hfx⟩
erw [SetLike.mem_coe, mem_ker, hf ⟨x, hpx⟩, mk_eq_zero] at hfx
simp only [hfx, SetLike.mem_coe, zero_mem]
· rw [codisjoint_iff_le_sup]
intro x _
rw [mem_sup']
refine ⟨f x, ⟨x - f x, ?_⟩, add_sub_cancel _ _⟩
rw [mem_ker, LinearMap.map_sub, hf, sub_self]
end LinearMap
namespace Submodule
open LinearMap
/-- If `q` is a complement of `p`, then `M/p ≃ q`. -/
def quotientEquivOfIsCompl (h : IsCompl p q) : (E ⧸ p) ≃ₗ[R] q :=
LinearEquiv.symm <|
LinearEquiv.ofBijective (p.mkQ.comp q.subtype)
⟨by rw [← ker_eq_bot, ker_comp, ker_mkQ, disjoint_iff_comap_eq_bot.1 h.symm.disjoint], by
rw [← range_eq_top, range_comp, range_subtype, map_mkQ_eq_top, h.sup_eq_top]⟩
@[simp]
theorem quotientEquivOfIsCompl_symm_apply (h : IsCompl p q) (x : q) :
-- Porting note: type ascriptions needed on the RHS
(quotientEquivOfIsCompl p q h).symm x = (Quotient.mk (x : E) : E ⧸ p) := rfl
@[simp]
theorem quotientEquivOfIsCompl_apply_mk_coe (h : IsCompl p q) (x : q) :
quotientEquivOfIsCompl p q h (Quotient.mk x) = x :=
(quotientEquivOfIsCompl p q h).apply_symm_apply x
@[simp]
theorem mk_quotientEquivOfIsCompl_apply (h : IsCompl p q) (x : E ⧸ p) :
(Quotient.mk (quotientEquivOfIsCompl p q h x) : E ⧸ p) = x :=
(quotientEquivOfIsCompl p q h).symm_apply_apply x
/-- If `q` is a complement of `p`, then `p × q` is isomorphic to `E`. It is the unique
linear map `f : E → p` such that `f x = x` for `x ∈ p` and `f x = 0` for `x ∈ q`. -/
def prodEquivOfIsCompl (h : IsCompl p q) : (p × q) ≃ₗ[R] E := by
apply LinearEquiv.ofBijective (p.subtype.coprod q.subtype)
constructor
· rw [← ker_eq_bot, ker_coprod_of_disjoint_range, ker_subtype, ker_subtype, prod_bot]
rw [range_subtype, range_subtype]
exact h.1
· rw [← range_eq_top, ← sup_eq_range, h.sup_eq_top]
@[simp]
theorem coe_prodEquivOfIsCompl (h : IsCompl p q) :
(prodEquivOfIsCompl p q h : p × q →ₗ[R] E) = p.subtype.coprod q.subtype := rfl
@[simp]
theorem coe_prodEquivOfIsCompl' (h : IsCompl p q) (x : p × q) :
prodEquivOfIsCompl p q h x = x.1 + x.2 := rfl
@[simp]
theorem prodEquivOfIsCompl_symm_apply_left (h : IsCompl p q) (x : p) :
(prodEquivOfIsCompl p q h).symm x = (x, 0) :=
(prodEquivOfIsCompl p q h).symm_apply_eq.2 <| by simp
@[simp]
theorem prodEquivOfIsCompl_symm_apply_right (h : IsCompl p q) (x : q) :
(prodEquivOfIsCompl p q h).symm x = (0, x) :=
(prodEquivOfIsCompl p q h).symm_apply_eq.2 <| by simp
@[simp]
theorem prodEquivOfIsCompl_symm_apply_fst_eq_zero (h : IsCompl p q) {x : E} :
((prodEquivOfIsCompl p q h).symm x).1 = 0 ↔ x ∈ q := by
conv_rhs => rw [← (prodEquivOfIsCompl p q h).apply_symm_apply x]
rw [coe_prodEquivOfIsCompl', Submodule.add_mem_iff_left _ (Submodule.coe_mem _),
mem_right_iff_eq_zero_of_disjoint h.disjoint]
@[simp]
theorem prodEquivOfIsCompl_symm_apply_snd_eq_zero (h : IsCompl p q) {x : E} :
((prodEquivOfIsCompl p q h).symm x).2 = 0 ↔ x ∈ p := by
conv_rhs => rw [← (prodEquivOfIsCompl p q h).apply_symm_apply x]
rw [coe_prodEquivOfIsCompl', Submodule.add_mem_iff_right _ (Submodule.coe_mem _),
mem_left_iff_eq_zero_of_disjoint h.disjoint]
@[simp]
theorem prodComm_trans_prodEquivOfIsCompl (h : IsCompl p q) :
LinearEquiv.prodComm R q p ≪≫ₗ prodEquivOfIsCompl p q h = prodEquivOfIsCompl q p h.symm :=
LinearEquiv.ext fun _ => add_comm _ _
/-- Projection to a submodule along its complement. -/
def linearProjOfIsCompl (h : IsCompl p q) : E →ₗ[R] p :=
LinearMap.fst R p q ∘ₗ ↑(prodEquivOfIsCompl p q h).symm
variable {p q}
@[simp]
theorem linearProjOfIsCompl_apply_left (h : IsCompl p q) (x : p) :
linearProjOfIsCompl p q h x = x := by simp [linearProjOfIsCompl]
@[simp]
theorem linearProjOfIsCompl_range (h : IsCompl p q) : range (linearProjOfIsCompl p q h) = ⊤ :=
range_eq_of_proj (linearProjOfIsCompl_apply_left h)
@[simp]
theorem linearProjOfIsCompl_apply_eq_zero_iff (h : IsCompl p q) {x : E} :
linearProjOfIsCompl p q h x = 0 ↔ x ∈ q := by simp [linearProjOfIsCompl]
theorem linearProjOfIsCompl_apply_right' (h : IsCompl p q) (x : E) (hx : x ∈ q) :
linearProjOfIsCompl p q h x = 0 :=
(linearProjOfIsCompl_apply_eq_zero_iff h).2 hx
@[simp]
theorem linearProjOfIsCompl_apply_right (h : IsCompl p q) (x : q) :
linearProjOfIsCompl p q h x = 0 :=
linearProjOfIsCompl_apply_right' h x x.2
@[simp]
theorem linearProjOfIsCompl_ker (h : IsCompl p q) : ker (linearProjOfIsCompl p q h) = q :=
ext fun _ => mem_ker.trans (linearProjOfIsCompl_apply_eq_zero_iff h)
theorem linearProjOfIsCompl_comp_subtype (h : IsCompl p q) :
(linearProjOfIsCompl p q h).comp p.subtype = LinearMap.id :=
LinearMap.ext <| linearProjOfIsCompl_apply_left h
theorem linearProjOfIsCompl_idempotent (h : IsCompl p q) (x : E) :
linearProjOfIsCompl p q h (linearProjOfIsCompl p q h x) = linearProjOfIsCompl p q h x :=
linearProjOfIsCompl_apply_left h _
theorem existsUnique_add_of_isCompl_prod (hc : IsCompl p q) (x : E) :
∃! u : p × q, (u.fst : E) + u.snd = x :=
(prodEquivOfIsCompl _ _ hc).toEquiv.bijective.existsUnique _
theorem existsUnique_add_of_isCompl (hc : IsCompl p q) (x : E) :
∃ (u : p) (v : q), (u : E) + v = x ∧ ∀ (r : p) (s : q), (r : E) + s = x → r = u ∧ s = v :=
let ⟨u, hu₁, hu₂⟩ := existsUnique_add_of_isCompl_prod hc x
⟨u.1, u.2, hu₁, fun r s hrs => Prod.eq_iff_fst_eq_snd_eq.1 (hu₂ ⟨r, s⟩ hrs)⟩
theorem linear_proj_add_linearProjOfIsCompl_eq_self (hpq : IsCompl p q) (x : E) :
(p.linearProjOfIsCompl q hpq x + q.linearProjOfIsCompl p hpq.symm x : E) = x := by
dsimp only [linearProjOfIsCompl]
rw [← prodComm_trans_prodEquivOfIsCompl _ _ hpq]
exact (prodEquivOfIsCompl _ _ hpq).apply_symm_apply x
end Submodule
namespace LinearMap
open Submodule
/-- Given linear maps `φ` and `ψ` from complement submodules, `LinearMap.ofIsCompl` is
the induced linear map over the entire module. -/
def ofIsCompl {p q : Submodule R E} (h : IsCompl p q) (φ : p →ₗ[R] F) (ψ : q →ₗ[R] F) : E →ₗ[R] F :=
LinearMap.coprod φ ψ ∘ₗ ↑(Submodule.prodEquivOfIsCompl _ _ h).symm
variable {p q}
@[simp]
theorem ofIsCompl_left_apply (h : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} (u : p) :
ofIsCompl h φ ψ (u : E) = φ u := by simp [ofIsCompl]
@[simp]
theorem ofIsCompl_right_apply (h : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} (v : q) :
ofIsCompl h φ ψ (v : E) = ψ v := by simp [ofIsCompl]
theorem ofIsCompl_eq (h : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} {χ : E →ₗ[R] F}
(hφ : ∀ u, φ u = χ u) (hψ : ∀ u, ψ u = χ u) : ofIsCompl h φ ψ = χ := by
ext x
obtain ⟨_, _, rfl, _⟩ := existsUnique_add_of_isCompl h x
simp [ofIsCompl, hφ, hψ]
theorem ofIsCompl_eq' (h : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} {χ : E →ₗ[R] F}
(hφ : φ = χ.comp p.subtype) (hψ : ψ = χ.comp q.subtype) : ofIsCompl h φ ψ = χ :=
ofIsCompl_eq h (fun _ => hφ.symm ▸ rfl) fun _ => hψ.symm ▸ rfl
@[simp]
theorem ofIsCompl_zero (h : IsCompl p q) : (ofIsCompl h 0 0 : E →ₗ[R] F) = 0 :=
ofIsCompl_eq _ (fun _ => rfl) fun _ => rfl
@[simp]
theorem ofIsCompl_add (h : IsCompl p q) {φ₁ φ₂ : p →ₗ[R] F} {ψ₁ ψ₂ : q →ₗ[R] F} :
ofIsCompl h (φ₁ + φ₂) (ψ₁ + ψ₂) = ofIsCompl h φ₁ ψ₁ + ofIsCompl h φ₂ ψ₂ :=
ofIsCompl_eq _ (by simp) (by simp)
@[simp]
theorem ofIsCompl_smul {R : Type*} [CommRing R] {E : Type*} [AddCommGroup E] [Module R E]
{F : Type*} [AddCommGroup F] [Module R F] {p q : Submodule R E} (h : IsCompl p q)
{φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} (c : R) : ofIsCompl h (c • φ) (c • ψ) = c • ofIsCompl h φ ψ :=
ofIsCompl_eq _ (by simp) (by simp)
section
variable {R₁ : Type*} [CommRing R₁] [Module R₁ E] [Module R₁ F]
/-- The linear map from `(p →ₗ[R₁] F) × (q →ₗ[R₁] F)` to `E →ₗ[R₁] F`. -/
def ofIsComplProd {p q : Submodule R₁ E} (h : IsCompl p q) :
(p →ₗ[R₁] F) × (q →ₗ[R₁] F) →ₗ[R₁] E →ₗ[R₁] F where
toFun φ := ofIsCompl h φ.1 φ.2
map_add' := by intro φ ψ; dsimp only; rw [Prod.snd_add, Prod.fst_add, ofIsCompl_add]
map_smul' := by intro c φ; simp [Prod.smul_snd, Prod.smul_fst, ofIsCompl_smul]
@[simp]
theorem ofIsComplProd_apply {p q : Submodule R₁ E} (h : IsCompl p q)
(φ : (p →ₗ[R₁] F) × (q →ₗ[R₁] F)) : ofIsComplProd h φ = ofIsCompl h φ.1 φ.2 :=
rfl
/-- The natural linear equivalence between `(p →ₗ[R₁] F) × (q →ₗ[R₁] F)` and `E →ₗ[R₁] F`. -/
def ofIsComplProdEquiv {p q : Submodule R₁ E} (h : IsCompl p q) :
((p →ₗ[R₁] F) × (q →ₗ[R₁] F)) ≃ₗ[R₁] E →ₗ[R₁] F :=
{ ofIsComplProd h with
invFun := fun φ => ⟨φ.domRestrict p, φ.domRestrict q⟩
left_inv := fun φ ↦ by
ext x
· exact ofIsCompl_left_apply h x
· exact ofIsCompl_right_apply h x
right_inv := fun φ ↦ by
ext x
obtain ⟨a, b, hab, _⟩ := existsUnique_add_of_isCompl h x
rw [← hab]; simp }
end
@[simp, nolint simpNF] -- Porting note: linter claims that LHS doesn't simplify, but it does
theorem linearProjOfIsCompl_of_proj (f : E →ₗ[R] p) (hf : ∀ x : p, f x = x) :
p.linearProjOfIsCompl (ker f) (isCompl_of_proj hf) = f := by
ext x
have : x ∈ p ⊔ (ker f) := by simp only [(isCompl_of_proj hf).sup_eq_top, mem_top]
rcases mem_sup'.1 this with ⟨x, y, rfl⟩
simp [hf]
/-- If `f : E →ₗ[R] F` and `g : E →ₗ[R] G` are two surjective linear maps and
their kernels are complement of each other, then `x ↦ (f x, g x)` defines
a linear equivalence `E ≃ₗ[R] F × G`. -/
def equivProdOfSurjectiveOfIsCompl (f : E →ₗ[R] F) (g : E →ₗ[R] G) (hf : range f = ⊤)
(hg : range g = ⊤) (hfg : IsCompl (ker f) (ker g)) : E ≃ₗ[R] F × G :=
LinearEquiv.ofBijective (f.prod g)
⟨by simp [← ker_eq_bot, hfg.inf_eq_bot], by
rw [← range_eq_top]
simp [range_prod_eq hfg.sup_eq_top, *]⟩
@[simp]
theorem coe_equivProdOfSurjectiveOfIsCompl {f : E →ₗ[R] F} {g : E →ₗ[R] G} (hf : range f = ⊤)
(hg : range g = ⊤) (hfg : IsCompl (ker f) (ker g)) :
(equivProdOfSurjectiveOfIsCompl f g hf hg hfg : E →ₗ[R] F × G) = f.prod g := rfl
@[simp]
theorem equivProdOfSurjectiveOfIsCompl_apply {f : E →ₗ[R] F} {g : E →ₗ[R] G} (hf : range f = ⊤)
(hg : range g = ⊤) (hfg : IsCompl (ker f) (ker g)) (x : E) :
equivProdOfSurjectiveOfIsCompl f g hf hg hfg x = (f x, g x) := rfl
end LinearMap
namespace Submodule
open LinearMap
/-- Equivalence between submodules `q` such that `IsCompl p q` and linear maps `f : E →ₗ[R] p`
such that `∀ x : p, f x = x`. -/
def isComplEquivProj : { q // IsCompl p q } ≃ { f : E →ₗ[R] p // ∀ x : p, f x = x } where
toFun q := ⟨linearProjOfIsCompl p q q.2, linearProjOfIsCompl_apply_left q.2⟩
invFun f := ⟨ker (f : E →ₗ[R] p), isCompl_of_proj f.2⟩
left_inv := fun ⟨q, hq⟩ => by simp only [linearProjOfIsCompl_ker, Subtype.coe_mk]
right_inv := fun ⟨f, hf⟩ => Subtype.eq <| f.linearProjOfIsCompl_of_proj hf
@[simp]
theorem coe_isComplEquivProj_apply (q : { q // IsCompl p q }) :
(p.isComplEquivProj q : E →ₗ[R] p) = linearProjOfIsCompl p q q.2 := rfl
@[simp]
theorem coe_isComplEquivProj_symm_apply (f : { f : E →ₗ[R] p // ∀ x : p, f x = x }) :
(p.isComplEquivProj.symm f : Submodule R E) = ker (f : E →ₗ[R] p) := rfl
/-- The idempotent endomorphisms of a module with range equal to a submodule are in 1-1
correspondence with linear maps to the submodule that restrict to the identity on the submodule. -/
@[simps] def isIdempotentElemEquiv :
{ f : Module.End R E // IsIdempotentElem f ∧ range f = p } ≃
{ f : E →ₗ[R] p // ∀ x : p, f x = x } where
toFun f := ⟨f.1.codRestrict _ fun x ↦ by simp_rw [← f.2.2]; exact mem_range_self f.1 x,
fun ⟨x, hx⟩ ↦ Subtype.ext <| by
obtain ⟨x, rfl⟩ := f.2.2.symm ▸ hx
exact DFunLike.congr_fun f.2.1 x⟩
invFun f := ⟨p.subtype ∘ₗ f.1, LinearMap.ext fun x ↦ by simp [f.2], le_antisymm
((range_comp_le_range _ _).trans_eq p.range_subtype)
fun x hx ↦ ⟨x, Subtype.ext_iff.1 <| f.2 ⟨x, hx⟩⟩⟩
left_inv _ := rfl
right_inv _ := rfl
end Submodule
namespace LinearMap
open Submodule
/--
A linear endomorphism of a module `E` is a projection onto a submodule `p` if it sends every element
of `E` to `p` and fixes every element of `p`.
The definition allow more generally any `FunLike` type and not just linear maps, so that it can be
used for example with `ContinuousLinearMap` or `Matrix`.
-/
structure IsProj {F : Type*} [FunLike F M M] (f : F) : Prop where
map_mem : ∀ x, f x ∈ m
map_id : ∀ x ∈ m, f x = x
theorem isProj_iff_idempotent (f : M →ₗ[S] M) : (∃ p : Submodule S M, IsProj p f) ↔ f ∘ₗ f = f := by
constructor
· intro h
obtain ⟨p, hp⟩ := h
ext x
rw [comp_apply]
exact hp.map_id (f x) (hp.map_mem x)
· intro h
use range f
constructor
· intro x
exact mem_range_self f x
· intro x hx
obtain ⟨y, hy⟩ := mem_range.1 hx
rw [← hy, ← comp_apply, h]
namespace IsProj
variable {p m}
/-- Restriction of the codomain of a projection of onto a subspace `p` to `p` instead of the whole
space.
-/
def codRestrict {f : M →ₗ[S] M} (h : IsProj m f) : M →ₗ[S] m :=
f.codRestrict m h.map_mem
@[simp]
theorem codRestrict_apply {f : M →ₗ[S] M} (h : IsProj m f) (x : M) : ↑(h.codRestrict x) = f x :=
f.codRestrict_apply m x
@[simp]
theorem codRestrict_apply_cod {f : M →ₗ[S] M} (h : IsProj m f) (x : m) : h.codRestrict x = x := by
ext
rw [codRestrict_apply]
exact h.map_id x x.2
theorem codRestrict_ker {f : M →ₗ[S] M} (h : IsProj m f) : ker h.codRestrict = ker f :=
f.ker_codRestrict m _
theorem isCompl {f : E →ₗ[R] E} (h : IsProj p f) : IsCompl p (ker f) := by
rw [← codRestrict_ker]
exact isCompl_of_proj h.codRestrict_apply_cod
theorem eq_conj_prod_map' {f : E →ₗ[R] E} (h : IsProj p f) :
f = (p.prodEquivOfIsCompl (ker f) h.isCompl).toLinearMap ∘ₗ
prodMap id 0 ∘ₗ (p.prodEquivOfIsCompl (ker f) h.isCompl).symm.toLinearMap := by
rw [← LinearMap.comp_assoc, LinearEquiv.eq_comp_toLinearMap_symm]
ext x
· simp only [coe_prodEquivOfIsCompl, comp_apply, coe_inl, coprod_apply, coeSubtype,
_root_.map_zero, add_zero, h.map_id x x.2, prodMap_apply, id_apply]
· simp only [coe_prodEquivOfIsCompl, comp_apply, coe_inr, coprod_apply, _root_.map_zero,
coeSubtype, zero_add, map_coe_ker, prodMap_apply, zero_apply, add_zero]
end IsProj
end LinearMap
end Ring
section CommRing
namespace LinearMap
variable {R : Type*} [CommRing R] {E : Type*} [AddCommGroup E] [Module R E] {p : Submodule R E}
theorem IsProj.eq_conj_prodMap {f : E →ₗ[R] E} (h : IsProj p f) :
f = (p.prodEquivOfIsCompl (ker f) h.isCompl).conj (prodMap id 0) := by
rw [LinearEquiv.conj_apply]
exact h.eq_conj_prod_map'
end LinearMap
end CommRing
|
LinearAlgebra\Quotient.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov
-/
import Mathlib.GroupTheory.QuotientGroup
import Mathlib.LinearAlgebra.Span
import Mathlib.Algebra.Module.Equiv.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.
-/
-- 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 LinearMap 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_r_def {x y : M} : @Setoid.r _ 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''
/- porting note: here and throughout elaboration is sped up *tremendously* (in some cases even
avoiding timeouts) by providing type ascriptions to `mk` (or `mk x`) and its variants. Lean 3
didn't need this help. -/
@[simp]
theorem mk'_eq_mk' {p : Submodule R M} (x : M) :
@Quotient.mk' _ (quotientRel p) x = (mk : M → M ⧸ p) x :=
rfl
@[simp]
theorem mk''_eq_mk {p : Submodule R M} (x : M) : (Quotient.mk'' x : M ⧸ p) = (mk : M → M ⧸ p) x :=
rfl
@[simp]
theorem quot_mk_eq_mk {p : Submodule R M} (x : M) : (Quot.mk _ x : M ⧸ p) = (mk : M → M ⧸ p) x :=
rfl
protected theorem eq' {x y : M} : (mk x : M ⧸ p) = (mk : M → M ⧸ p) y ↔ -x + y ∈ p :=
QuotientAddGroup.eq
protected theorem eq {x y : M} : (mk x : M ⧸ p) = (mk y : M ⧸ p) ↔ x - y ∈ p :=
(Submodule.Quotient.eq' p).trans (leftRel_apply.symm.trans p.quotientRel_r_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 : M ⧸ p) + (mk y : M ⧸ p) :=
rfl
@[simp]
theorem mk_neg : (mk (-x) : M ⧸ p) = -(mk x : M ⧸ p) :=
rfl
@[simp]
theorem mk_sub : (mk (x - y) : M ⧸ p) = (mk x : M ⧸ p) - (mk y : M ⧸ p) :=
rfl
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)⟩
-- Porting note: should this be marked as a `@[default_instance]`?
/-- 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*}
-- Performance of `Function.Surjective.mulAction` is worse since it has to unify data to apply
-- TODO: leanprover-community/mathlib4#7432
instance mulAction' [Monoid S] [SMul S R] [MulAction S M] [IsScalarTower S R M]
(P : Submodule R M) : MulAction S (M ⧸ P) :=
{ Function.Surjective.mulAction mk (surjective_quot_mk _) <| Submodule.Quotient.mk_smul P with
toSMul := instSMul' _ }
-- Porting note: should this be marked as a `@[default_instance]`?
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
-- Porting note: should this be marked as a `@[default_instance]`?
instance smulZeroClass (P : Submodule R M) : SMulZeroClass R (M ⧸ P) :=
Quotient.smulZeroClass' P
-- Performance of `Function.Surjective.distribSMul` is worse since it has to unify data to apply
-- TODO: leanprover-community/mathlib4#7432
instance distribSMul' [SMul S R] [DistribSMul S M] [IsScalarTower S R M] (P : Submodule R M) :
DistribSMul S (M ⧸ P) :=
{ Function.Surjective.distribSMul {toFun := mk, map_zero' := rfl, map_add' := fun _ _ => rfl}
(surjective_quot_mk _) (Submodule.Quotient.mk_smul P) with
toSMulZeroClass := smulZeroClass' _ }
-- Porting note: should this be marked as a `@[default_instance]`?
instance distribSMul (P : Submodule R M) : DistribSMul R (M ⧸ P) :=
Quotient.distribSMul' P
-- Performance of `Function.Surjective.distribMulAction` is worse since it has to unify data
-- TODO: leanprover-community/mathlib4#7432
instance distribMulAction' [Monoid S] [SMul S R] [DistribMulAction S M] [IsScalarTower S R M]
(P : Submodule R M) : DistribMulAction S (M ⧸ P) :=
{ Function.Surjective.distribMulAction {toFun := mk, map_zero' := rfl, map_add' := fun _ _ => rfl}
(surjective_quot_mk _) (Submodule.Quotient.mk_smul P) with
toMulAction := mulAction' _ }
-- Porting note: should this be marked as a `@[default_instance]`?
instance distribMulAction (P : Submodule R M) : DistribMulAction R (M ⧸ P) :=
Quotient.distribMulAction' P
-- Performance of `Function.Surjective.module` is worse since it has to unify data to apply
-- TODO: leanprover-community/mathlib4#7432
instance module' [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] (P : Submodule R M) :
Module S (M ⧸ P) :=
{ Function.Surjective.module _ {toFun := mk, map_zero' := by rfl, map_add' := fun _ _ => by rfl}
(surjective_quot_mk _) (Submodule.Quotient.mk_smul P) with
toDistribMulAction := distribMulAction' _ }
-- Porting note: should this be marked as a `@[default_instance]`?
instance module (P : Submodule R M) : Module R (M ⧸ P) :=
Quotient.module' P
variable (S)
/-- 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 => Quotient.inductionOn' 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 : M ⧸ P) = (mk x : M ⧸ P) :=
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 : M → M ⧸ P) x) = (mk : M → M ⧸ P) x :=
rfl
end Module
theorem mk_surjective : Function.Surjective (@mk _ _ _ _ _ p) := by
rintro ⟨x⟩
exact ⟨x, rfl⟩
theorem nontrivial_of_lt_top (h : p < ⊤) : Nontrivial (M ⧸ p) := by
obtain ⟨x, _, not_mem_s⟩ := SetLike.exists_of_lt h
refine ⟨⟨mk x, 0, ?_⟩⟩
simpa using not_mem_s
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 := Quotient.inductionOn' 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
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 _
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
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 => Quotient.inductionOn' 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 : M ⧸ p) :=
rfl
theorem mkQ_surjective (A : Submodule R M) : Function.Surjective A.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 1100] -- Porting note: 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 => Quotient.inductionOn' x <| (LinearMap.congr_fun h : _)
/-- 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
/-- 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
-- Porting note: ambiguity of `map_eq_top_iff` is no longer automatically resolved by preferring
-- the current namespace
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 : M ⧸ p) = (Quotient.mk (f x) : M₂ ⧸ q) :=
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 k ih
· simp [LinearMap.one_eq_id]
· simp only [LinearMap.iterate_succ]
-- Porting note: why does any of these `optParams` need to be applied? Why didn't `simp` handle
-- all of this for us?
convert mapQ_comp p p p f (f ^ k) h (p.le_comap_pow_of_le_comap h k)
(h.trans (comap_mono <| p.le_comap_pow_of_le_comap h k))
exact (ih _).symm
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
/-- 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 { p' : Submodule R M // p ≤ 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_val <| 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 [range_coe 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 x hx => hf ▸ Submodule.mem_map_of_mem hx with
toFun := P.mapQ Q (f : M →ₗ[R] N) fun x 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 => Quotient.inductionOn' x (by simp)
right_inv := fun x => Quotient.inductionOn' x (by simp) }
@[simp]
theorem Quotient.equiv_symm {R M N : Type*} [CommRing 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₂) : f.range.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 ↔ f.range.mkQ.comp g.ker.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 f.range.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 : M ⧸ p) = x :=
rfl
@[simp]
theorem quotEquivOfEqBot_symm_apply (hp : p = ⊥) (x : M) :
(p.quotEquivOfEqBot hp).symm x = (Quotient.mk x : M ⧸ p) :=
rfl
@[simp]
theorem coe_quotEquivOfEqBot_symm (hp : p = ⊥) :
((p.quotEquivOfEqBot hp).symm : M →ₗ[R] M ⧸ p) = p.mkQ :=
rfl
/-- 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 : M ⧸ p) =
(Submodule.Quotient.mk x : M ⧸ p') :=
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
|
LinearAlgebra\QuotientPi.lean | /-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Alex J. Best
-/
import Mathlib.LinearAlgebra.Pi
import Mathlib.LinearAlgebra.Quotient
/-!
# 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, _root_.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
-- Porting note (#11083): split up the definition to avoid timeouts. Still slow.
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) single fun _ => le_comap_single_pi p
theorem left_inv : Function.LeftInverse (invFun p) (toFun p) := fun x =>
Quotient.inductionOn' x fun x' => by
rw [Quotient.mk''_eq_mk x']
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 => Quotient.inductionOn' x fun x' => funext fun j => ?_)
rw [comp_apply, piQuotientLift_single, Quotient.mk''_eq_mk, 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
|
LinearAlgebra\Ray.lean | /-
Copyright (c) 2021 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Algebra.Group.Subgroup.Actions
import Mathlib.Algebra.Order.Module.Algebra
import Mathlib.LinearAlgebra.LinearIndependent
import Mathlib.Algebra.Ring.Subring.Units
/-!
# Rays in modules
This file defines rays in modules.
## Main definitions
* `SameRay`: two vectors belong to the same ray if they are proportional with a nonnegative
coefficient.
* `Module.Ray` is a type for the equivalence class of nonzero vectors in a module with some
common positive multiple.
-/
noncomputable section
section StrictOrderedCommSemiring
variable (R : Type*) [StrictOrderedCommSemiring R]
variable {M : Type*} [AddCommMonoid M] [Module R M]
variable {N : Type*} [AddCommMonoid N] [Module R N]
variable (ι : Type*) [DecidableEq ι]
/-- Two vectors are in the same ray if either one of them is zero or some positive multiples of them
are equal (in the typical case over a field, this means one of them is a nonnegative multiple of
the other). -/
def SameRay (v₁ v₂ : M) : Prop :=
v₁ = 0 ∨ v₂ = 0 ∨ ∃ r₁ r₂ : R, 0 < r₁ ∧ 0 < r₂ ∧ r₁ • v₁ = r₂ • v₂
variable {R}
namespace SameRay
variable {x y z : M}
@[simp]
theorem zero_left (y : M) : SameRay R 0 y :=
Or.inl rfl
@[simp]
theorem zero_right (x : M) : SameRay R x 0 :=
Or.inr <| Or.inl rfl
@[nontriviality]
theorem of_subsingleton [Subsingleton M] (x y : M) : SameRay R x y := by
rw [Subsingleton.elim x 0]
exact zero_left _
@[nontriviality]
theorem of_subsingleton' [Subsingleton R] (x y : M) : SameRay R x y :=
haveI := Module.subsingleton R M
of_subsingleton x y
/-- `SameRay` is reflexive. -/
@[refl]
theorem refl (x : M) : SameRay R x x := by
nontriviality R
exact Or.inr (Or.inr <| ⟨1, 1, zero_lt_one, zero_lt_one, rfl⟩)
protected theorem rfl : SameRay R x x :=
refl _
/-- `SameRay` is symmetric. -/
@[symm]
theorem symm (h : SameRay R x y) : SameRay R y x :=
(or_left_comm.1 h).imp_right <| Or.imp_right fun ⟨r₁, r₂, h₁, h₂, h⟩ => ⟨r₂, r₁, h₂, h₁, h.symm⟩
/-- If `x` and `y` are nonzero vectors on the same ray, then there exist positive numbers `r₁ r₂`
such that `r₁ • x = r₂ • y`. -/
theorem exists_pos (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) :
∃ r₁ r₂ : R, 0 < r₁ ∧ 0 < r₂ ∧ r₁ • x = r₂ • y :=
(h.resolve_left hx).resolve_left hy
theorem sameRay_comm : SameRay R x y ↔ SameRay R y x :=
⟨SameRay.symm, SameRay.symm⟩
/-- `SameRay` is transitive unless the vector in the middle is zero and both other vectors are
nonzero. -/
theorem trans (hxy : SameRay R x y) (hyz : SameRay R y z) (hy : y = 0 → x = 0 ∨ z = 0) :
SameRay R x z := by
rcases eq_or_ne x 0 with (rfl | hx); · exact zero_left z
rcases eq_or_ne z 0 with (rfl | hz); · exact zero_right x
rcases eq_or_ne y 0 with (rfl | hy)
· exact (hy rfl).elim (fun h => (hx h).elim) fun h => (hz h).elim
rcases hxy.exists_pos hx hy with ⟨r₁, r₂, hr₁, hr₂, h₁⟩
rcases hyz.exists_pos hy hz with ⟨r₃, r₄, hr₃, hr₄, h₂⟩
refine Or.inr (Or.inr <| ⟨r₃ * r₁, r₂ * r₄, mul_pos hr₃ hr₁, mul_pos hr₂ hr₄, ?_⟩)
rw [mul_smul, mul_smul, h₁, ← h₂, smul_comm]
variable {S : Type*} [OrderedCommSemiring S] [Algebra S R] [Module S M] [SMulPosMono S R]
[IsScalarTower S R M] {a : S}
/-- A vector is in the same ray as a nonnegative multiple of itself. -/
lemma sameRay_nonneg_smul_right (v : M) (h : 0 ≤ a) : SameRay R v (a • v) := by
obtain h | h := (algebraMap_nonneg R h).eq_or_gt
· rw [← algebraMap_smul R a v, h, zero_smul]
exact zero_right _
· refine Or.inr $ Or.inr ⟨algebraMap S R a, 1, h, by nontriviality R; exact zero_lt_one, ?_⟩
rw [algebraMap_smul, one_smul]
/-- A nonnegative multiple of a vector is in the same ray as that vector. -/
lemma sameRay_nonneg_smul_left (v : M) (ha : 0 ≤ a) : SameRay R (a • v) v :=
(sameRay_nonneg_smul_right v ha).symm
/-- A vector is in the same ray as a positive multiple of itself. -/
lemma sameRay_pos_smul_right (v : M) (ha : 0 < a) : SameRay R v (a • v) :=
sameRay_nonneg_smul_right v ha.le
/-- A positive multiple of a vector is in the same ray as that vector. -/
lemma sameRay_pos_smul_left (v : M) (ha : 0 < a) : SameRay R (a • v) v :=
sameRay_nonneg_smul_left v ha.le
/-- A vector is in the same ray as a nonnegative multiple of one it is in the same ray as. -/
lemma nonneg_smul_right (h : SameRay R x y) (ha : 0 ≤ a) : SameRay R x (a • y) :=
h.trans (sameRay_nonneg_smul_right y ha) fun hy => Or.inr <| by rw [hy, smul_zero]
/-- A nonnegative multiple of a vector is in the same ray as one it is in the same ray as. -/
lemma nonneg_smul_left (h : SameRay R x y) (ha : 0 ≤ a) : SameRay R (a • x) y :=
(h.symm.nonneg_smul_right ha).symm
/-- A vector is in the same ray as a positive multiple of one it is in the same ray as. -/
theorem pos_smul_right (h : SameRay R x y) (ha : 0 < a) : SameRay R x (a • y) :=
h.nonneg_smul_right ha.le
/-- A positive multiple of a vector is in the same ray as one it is in the same ray as. -/
theorem pos_smul_left (h : SameRay R x y) (hr : 0 < a) : SameRay R (a • x) y :=
h.nonneg_smul_left hr.le
/-- If two vectors are on the same ray then they remain so after applying a linear map. -/
theorem map (f : M →ₗ[R] N) (h : SameRay R x y) : SameRay R (f x) (f y) :=
(h.imp fun hx => by rw [hx, map_zero]) <|
Or.imp (fun hy => by rw [hy, map_zero]) fun ⟨r₁, r₂, hr₁, hr₂, h⟩ =>
⟨r₁, r₂, hr₁, hr₂, by rw [← f.map_smul, ← f.map_smul, h]⟩
/-- The images of two vectors under an injective linear map are on the same ray if and only if the
original vectors are on the same ray. -/
theorem _root_.Function.Injective.sameRay_map_iff
{F : Type*} [FunLike F M N] [LinearMapClass F R M N]
{f : F} (hf : Function.Injective f) :
SameRay R (f x) (f y) ↔ SameRay R x y := by
simp only [SameRay, map_zero, ← hf.eq_iff, map_smul]
/-- The images of two vectors under a linear equivalence are on the same ray if and only if the
original vectors are on the same ray. -/
@[simp]
theorem sameRay_map_iff (e : M ≃ₗ[R] N) : SameRay R (e x) (e y) ↔ SameRay R x y :=
Function.Injective.sameRay_map_iff (EquivLike.injective e)
/-- If two vectors are on the same ray then both scaled by the same action are also on the same
ray. -/
theorem smul {S : Type*} [Monoid S] [DistribMulAction S M] [SMulCommClass R S M]
(h : SameRay R x y) (s : S) : SameRay R (s • x) (s • y) :=
h.map (s • (LinearMap.id : M →ₗ[R] M))
/-- If `x` and `y` are on the same ray as `z`, then so is `x + y`. -/
theorem add_left (hx : SameRay R x z) (hy : SameRay R y z) : SameRay R (x + y) z := by
rcases eq_or_ne x 0 with (rfl | hx₀); · rwa [zero_add]
rcases eq_or_ne y 0 with (rfl | hy₀); · rwa [add_zero]
rcases eq_or_ne z 0 with (rfl | hz₀); · apply zero_right
rcases hx.exists_pos hx₀ hz₀ with ⟨rx, rz₁, hrx, hrz₁, Hx⟩
rcases hy.exists_pos hy₀ hz₀ with ⟨ry, rz₂, hry, hrz₂, Hy⟩
refine Or.inr (Or.inr ⟨rx * ry, ry * rz₁ + rx * rz₂, mul_pos hrx hry, ?_, ?_⟩)
· apply_rules [add_pos, mul_pos]
· simp only [mul_smul, smul_add, add_smul, ← Hx, ← Hy]
rw [smul_comm]
/-- If `y` and `z` are on the same ray as `x`, then so is `y + z`. -/
theorem add_right (hy : SameRay R x y) (hz : SameRay R x z) : SameRay R x (y + z) :=
(hy.symm.add_left hz.symm).symm
end SameRay
-- Porting note(#5171): removed has_nonempty_instance nolint, no such linter
set_option linter.unusedVariables false in
/-- Nonzero vectors, as used to define rays. This type depends on an unused argument `R` so that
`RayVector.Setoid` can be an instance. -/
@[nolint unusedArguments]
def RayVector (R M : Type*) [Zero M] :=
{ v : M // v ≠ 0 }
-- Porting note: Made Coe into CoeOut so it's not dangerous anymore
instance RayVector.coe [Zero M] : CoeOut (RayVector R M) M where
coe := Subtype.val
instance {R M : Type*} [Zero M] [Nontrivial M] : Nonempty (RayVector R M) :=
let ⟨x, hx⟩ := exists_ne (0 : M)
⟨⟨x, hx⟩⟩
variable (R M)
/-- The setoid of the `SameRay` relation for the subtype of nonzero vectors. -/
instance RayVector.Setoid : Setoid (RayVector R M) where
r x y := SameRay R (x : M) y
iseqv :=
⟨fun x => SameRay.refl _, fun h => h.symm, by
intros x y z hxy hyz
exact hxy.trans hyz fun hy => (y.2 hy).elim⟩
/-- A ray (equivalence class of nonzero vectors with common positive multiples) in a module. -/
-- Porting note(#5171): removed has_nonempty_instance nolint, no such linter
def Module.Ray :=
Quotient (RayVector.Setoid R M)
variable {R M}
/-- Equivalence of nonzero vectors, in terms of `SameRay`. -/
theorem equiv_iff_sameRay {v₁ v₂ : RayVector R M} : v₁ ≈ v₂ ↔ SameRay R (v₁ : M) v₂ :=
Iff.rfl
variable (R)
-- Porting note: Removed `protected` here, not in namespace
/-- The ray given by a nonzero vector. -/
def rayOfNeZero (v : M) (h : v ≠ 0) : Module.Ray R M :=
⟦⟨v, h⟩⟧
/-- An induction principle for `Module.Ray`, used as `induction x using Module.Ray.ind`. -/
theorem Module.Ray.ind {C : Module.Ray R M → Prop} (h : ∀ (v) (hv : v ≠ 0), C (rayOfNeZero R v hv))
(x : Module.Ray R M) : C x :=
Quotient.ind (Subtype.rec <| h) x
variable {R}
instance [Nontrivial M] : Nonempty (Module.Ray R M) :=
Nonempty.map Quotient.mk' inferInstance
/-- The rays given by two nonzero vectors are equal if and only if those vectors
satisfy `SameRay`. -/
theorem ray_eq_iff {v₁ v₂ : M} (hv₁ : v₁ ≠ 0) (hv₂ : v₂ ≠ 0) :
rayOfNeZero R _ hv₁ = rayOfNeZero R _ hv₂ ↔ SameRay R v₁ v₂ :=
Quotient.eq'
/-- The ray given by a positive multiple of a nonzero vector. -/
@[simp]
theorem ray_pos_smul {v : M} (h : v ≠ 0) {r : R} (hr : 0 < r) (hrv : r • v ≠ 0) :
rayOfNeZero R (r • v) hrv = rayOfNeZero R v h :=
(ray_eq_iff _ _).2 <| SameRay.sameRay_pos_smul_left v hr
/-- An equivalence between modules implies an equivalence between ray vectors. -/
def RayVector.mapLinearEquiv (e : M ≃ₗ[R] N) : RayVector R M ≃ RayVector R N :=
Equiv.subtypeEquiv e.toEquiv fun _ => e.map_ne_zero_iff.symm
/-- An equivalence between modules implies an equivalence between rays. -/
def Module.Ray.map (e : M ≃ₗ[R] N) : Module.Ray R M ≃ Module.Ray R N :=
Quotient.congr (RayVector.mapLinearEquiv e) fun _ _=> (SameRay.sameRay_map_iff _).symm
@[simp]
theorem Module.Ray.map_apply (e : M ≃ₗ[R] N) (v : M) (hv : v ≠ 0) :
Module.Ray.map e (rayOfNeZero _ v hv) = rayOfNeZero _ (e v) (e.map_ne_zero_iff.2 hv) :=
rfl
@[simp]
theorem Module.Ray.map_refl : (Module.Ray.map <| LinearEquiv.refl R M) = Equiv.refl _ :=
Equiv.ext <| Module.Ray.ind R fun _ _ => rfl
@[simp]
theorem Module.Ray.map_symm (e : M ≃ₗ[R] N) : (Module.Ray.map e).symm = Module.Ray.map e.symm :=
rfl
section Action
variable {G : Type*} [Group G] [DistribMulAction G M]
/-- Any invertible action preserves the non-zeroness of ray vectors. This is primarily of interest
when `G = Rˣ` -/
instance {R : Type*} : MulAction G (RayVector R M) where
smul r := Subtype.map (r • ·) fun _ => (smul_ne_zero_iff_ne _).2
mul_smul a b _ := Subtype.ext <| mul_smul a b _
one_smul _ := Subtype.ext <| one_smul _ _
variable [SMulCommClass R G M]
/-- Any invertible action preserves the non-zeroness of rays. This is primarily of interest when
`G = Rˣ` -/
instance : MulAction G (Module.Ray R M) where
smul r := Quotient.map (r • ·) fun _ _ h => h.smul _
mul_smul a b := Quotient.ind fun _ => congr_arg Quotient.mk' <| mul_smul a b _
one_smul := Quotient.ind fun _ => congr_arg Quotient.mk' <| one_smul _ _
/-- The action via `LinearEquiv.apply_distribMulAction` corresponds to `Module.Ray.map`. -/
@[simp]
theorem Module.Ray.linearEquiv_smul_eq_map (e : M ≃ₗ[R] M) (v : Module.Ray R M) :
e • v = Module.Ray.map e v :=
rfl
@[simp]
theorem smul_rayOfNeZero (g : G) (v : M) (hv) :
g • rayOfNeZero R v hv = rayOfNeZero R (g • v) ((smul_ne_zero_iff_ne _).2 hv) :=
rfl
end Action
namespace Module.Ray
-- Porting note: `(u.1 : R)` was `(u : R)`, CoeHead from R to Rˣ does not seem to work.
/-- Scaling by a positive unit is a no-op. -/
theorem units_smul_of_pos (u : Rˣ) (hu : 0 < (u.1 : R)) (v : Module.Ray R M) : u • v = v := by
induction v using Module.Ray.ind
rw [smul_rayOfNeZero, ray_eq_iff]
exact SameRay.sameRay_pos_smul_left _ hu
/-- An arbitrary `RayVector` giving a ray. -/
def someRayVector (x : Module.Ray R M) : RayVector R M :=
Quotient.out x
/-- The ray of `someRayVector`. -/
@[simp]
theorem someRayVector_ray (x : Module.Ray R M) : (⟦x.someRayVector⟧ : Module.Ray R M) = x :=
Quotient.out_eq _
/-- An arbitrary nonzero vector giving a ray. -/
def someVector (x : Module.Ray R M) : M :=
x.someRayVector
/-- `someVector` is nonzero. -/
@[simp]
theorem someVector_ne_zero (x : Module.Ray R M) : x.someVector ≠ 0 :=
x.someRayVector.property
/-- The ray of `someVector`. -/
@[simp]
theorem someVector_ray (x : Module.Ray R M) : rayOfNeZero R _ x.someVector_ne_zero = x :=
(congr_arg _ (Subtype.coe_eta _ _) : _).trans x.out_eq
end Module.Ray
end StrictOrderedCommSemiring
section StrictOrderedCommRing
variable {R : Type*} [StrictOrderedCommRing R]
variable {M N : Type*} [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] {x y : M}
/-- `SameRay.neg` as an `iff`. -/
@[simp]
theorem sameRay_neg_iff : SameRay R (-x) (-y) ↔ SameRay R x y := by
simp only [SameRay, neg_eq_zero, smul_neg, neg_inj]
alias ⟨SameRay.of_neg, SameRay.neg⟩ := sameRay_neg_iff
theorem sameRay_neg_swap : SameRay R (-x) y ↔ SameRay R x (-y) := by rw [← sameRay_neg_iff, neg_neg]
theorem eq_zero_of_sameRay_neg_smul_right [NoZeroSMulDivisors R M] {r : R} (hr : r < 0)
(h : SameRay R x (r • x)) : x = 0 := by
rcases h with (rfl | h₀ | ⟨r₁, r₂, hr₁, hr₂, h⟩)
· rfl
· simpa [hr.ne] using h₀
· rw [← sub_eq_zero, smul_smul, ← sub_smul, smul_eq_zero] at h
refine h.resolve_left (ne_of_gt <| sub_pos.2 ?_)
exact (mul_neg_of_pos_of_neg hr₂ hr).trans hr₁
/-- If a vector is in the same ray as its negation, that vector is zero. -/
theorem eq_zero_of_sameRay_self_neg [NoZeroSMulDivisors R M] (h : SameRay R x (-x)) : x = 0 := by
nontriviality M; haveI : Nontrivial R := Module.nontrivial R M
refine eq_zero_of_sameRay_neg_smul_right (neg_lt_zero.2 (zero_lt_one' R)) ?_
rwa [neg_one_smul]
namespace RayVector
/-- Negating a nonzero vector. -/
instance {R : Type*} : Neg (RayVector R M) :=
⟨fun v => ⟨-v, neg_ne_zero.2 v.prop⟩⟩
/-- Negating a nonzero vector commutes with coercion to the underlying module. -/
@[simp, norm_cast]
theorem coe_neg {R : Type*} (v : RayVector R M) : ↑(-v) = -(v : M) :=
rfl
/-- Negating a nonzero vector twice produces the original vector. -/
instance {R : Type*} : InvolutiveNeg (RayVector R M) where
neg := Neg.neg
neg_neg v := by rw [Subtype.ext_iff, coe_neg, coe_neg, neg_neg]
/-- If two nonzero vectors are equivalent, so are their negations. -/
@[simp]
theorem equiv_neg_iff {v₁ v₂ : RayVector R M} : -v₁ ≈ -v₂ ↔ v₁ ≈ v₂ :=
sameRay_neg_iff
end RayVector
variable (R)
/-- Negating a ray. -/
instance : Neg (Module.Ray R M) :=
⟨Quotient.map (fun v => -v) fun _ _ => RayVector.equiv_neg_iff.2⟩
/-- The ray given by the negation of a nonzero vector. -/
@[simp]
theorem neg_rayOfNeZero (v : M) (h : v ≠ 0) :
-rayOfNeZero R _ h = rayOfNeZero R (-v) (neg_ne_zero.2 h) :=
rfl
namespace Module.Ray
variable {R}
/-- Negating a ray twice produces the original ray. -/
instance : InvolutiveNeg (Module.Ray R M) where
neg := Neg.neg
neg_neg x := by apply ind R (by simp) x
-- Quotient.ind (fun a => congr_arg Quotient.mk' <| neg_neg _) x
/-- A ray does not equal its own negation. -/
theorem ne_neg_self [NoZeroSMulDivisors R M] (x : Module.Ray R M) : x ≠ -x := by
induction' x using Module.Ray.ind with x hx
rw [neg_rayOfNeZero, Ne, ray_eq_iff]
exact mt eq_zero_of_sameRay_self_neg hx
theorem neg_units_smul (u : Rˣ) (v : Module.Ray R M) : -u • v = -(u • v) := by
induction v using Module.Ray.ind
simp only [smul_rayOfNeZero, Units.smul_def, Units.val_neg, neg_smul, neg_rayOfNeZero]
-- Porting note: `(u.1 : R)` was `(u : R)`, CoeHead from R to Rˣ does not seem to work.
/-- Scaling by a negative unit is negation. -/
theorem units_smul_of_neg (u : Rˣ) (hu : u.1 < 0) (v : Module.Ray R M) : u • v = -v := by
rw [← neg_inj, neg_neg, ← neg_units_smul, units_smul_of_pos]
rwa [Units.val_neg, Right.neg_pos_iff]
@[simp]
protected theorem map_neg (f : M ≃ₗ[R] N) (v : Module.Ray R M) : map f (-v) = -map f v := by
induction' v using Module.Ray.ind with g hg
simp
end Module.Ray
end StrictOrderedCommRing
section LinearOrderedCommRing
variable {R : Type*} [LinearOrderedCommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
-- Porting note: Needed to add coercion ↥ below
/-- `SameRay` follows from membership of `MulAction.orbit` for the `Units.posSubgroup`. -/
theorem sameRay_of_mem_orbit {v₁ v₂ : M} (h : v₁ ∈ MulAction.orbit ↥(Units.posSubgroup R) v₂) :
SameRay R v₁ v₂ := by
rcases h with ⟨⟨r, hr : 0 < r.1⟩, rfl : r • v₂ = v₁⟩
exact SameRay.sameRay_pos_smul_left _ hr
/-- Scaling by an inverse unit is the same as scaling by itself. -/
@[simp]
theorem units_inv_smul (u : Rˣ) (v : Module.Ray R M) : u⁻¹ • v = u • v :=
have := mul_self_pos.2 u.ne_zero
calc
u⁻¹ • v = (u * u) • u⁻¹ • v := Eq.symm <| (u⁻¹ • v).units_smul_of_pos _ (by exact this)
_ = u • v := by rw [mul_smul, smul_inv_smul]
section
variable [NoZeroSMulDivisors R M]
@[simp]
theorem sameRay_smul_right_iff {v : M} {r : R} : SameRay R v (r • v) ↔ 0 ≤ r ∨ v = 0 :=
⟨fun hrv => or_iff_not_imp_left.2 fun hr => eq_zero_of_sameRay_neg_smul_right (not_le.1 hr) hrv,
or_imp.2 ⟨SameRay.sameRay_nonneg_smul_right v, fun h => h.symm ▸ SameRay.zero_left _⟩⟩
/-- A nonzero vector is in the same ray as a multiple of itself if and only if that multiple
is positive. -/
theorem sameRay_smul_right_iff_of_ne {v : M} (hv : v ≠ 0) {r : R} (hr : r ≠ 0) :
SameRay R v (r • v) ↔ 0 < r := by
simp only [sameRay_smul_right_iff, hv, or_false_iff, hr.symm.le_iff_lt]
@[simp]
theorem sameRay_smul_left_iff {v : M} {r : R} : SameRay R (r • v) v ↔ 0 ≤ r ∨ v = 0 :=
SameRay.sameRay_comm.trans sameRay_smul_right_iff
/-- A multiple of a nonzero vector is in the same ray as that vector if and only if that multiple
is positive. -/
theorem sameRay_smul_left_iff_of_ne {v : M} (hv : v ≠ 0) {r : R} (hr : r ≠ 0) :
SameRay R (r • v) v ↔ 0 < r :=
SameRay.sameRay_comm.trans (sameRay_smul_right_iff_of_ne hv hr)
@[simp]
theorem sameRay_neg_smul_right_iff {v : M} {r : R} : SameRay R (-v) (r • v) ↔ r ≤ 0 ∨ v = 0 := by
rw [← sameRay_neg_iff, neg_neg, ← neg_smul, sameRay_smul_right_iff, neg_nonneg]
theorem sameRay_neg_smul_right_iff_of_ne {v : M} {r : R} (hv : v ≠ 0) (hr : r ≠ 0) :
SameRay R (-v) (r • v) ↔ r < 0 := by
simp only [sameRay_neg_smul_right_iff, hv, or_false_iff, hr.le_iff_lt]
@[simp]
theorem sameRay_neg_smul_left_iff {v : M} {r : R} : SameRay R (r • v) (-v) ↔ r ≤ 0 ∨ v = 0 :=
SameRay.sameRay_comm.trans sameRay_neg_smul_right_iff
theorem sameRay_neg_smul_left_iff_of_ne {v : M} {r : R} (hv : v ≠ 0) (hr : r ≠ 0) :
SameRay R (r • v) (-v) ↔ r < 0 :=
SameRay.sameRay_comm.trans <| sameRay_neg_smul_right_iff_of_ne hv hr
-- Porting note: `(u.1 : R)` was `(u : R)`, CoeHead from R to Rˣ does not seem to work.
@[simp]
theorem units_smul_eq_self_iff {u : Rˣ} {v : Module.Ray R M} : u • v = v ↔ 0 < u.1 := by
induction' v using Module.Ray.ind with v hv
simp only [smul_rayOfNeZero, ray_eq_iff, Units.smul_def, sameRay_smul_left_iff_of_ne hv u.ne_zero]
@[simp]
theorem units_smul_eq_neg_iff {u : Rˣ} {v : Module.Ray R M} : u • v = -v ↔ u.1 < 0 := by
rw [← neg_inj, neg_neg, ← Module.Ray.neg_units_smul, units_smul_eq_self_iff, Units.val_neg,
neg_pos]
/-- Two vectors are in the same ray, or the first is in the same ray as the negation of the
second, if and only if they are not linearly independent. -/
theorem sameRay_or_sameRay_neg_iff_not_linearIndependent {x y : M} :
SameRay R x y ∨ SameRay R x (-y) ↔ ¬LinearIndependent R ![x, y] := by
by_cases hx : x = 0; · simpa [hx] using fun h : LinearIndependent R ![0, y] => h.ne_zero 0 rfl
by_cases hy : y = 0; · simpa [hy] using fun h : LinearIndependent R ![x, 0] => h.ne_zero 1 rfl
simp_rw [Fintype.not_linearIndependent_iff]
refine ⟨fun h => ?_, fun h => ?_⟩
· rcases h with ((hx0 | hy0 | ⟨r₁, r₂, hr₁, _, h⟩) | (hx0 | hy0 | ⟨r₁, r₂, hr₁, _, h⟩))
· exact False.elim (hx hx0)
· exact False.elim (hy hy0)
· refine ⟨![r₁, -r₂], ?_⟩
rw [Fin.sum_univ_two, Fin.exists_fin_two]
simp [h, hr₁.ne.symm]
· exact False.elim (hx hx0)
· exact False.elim (hy (neg_eq_zero.1 hy0))
· refine ⟨![r₁, r₂], ?_⟩
rw [Fin.sum_univ_two, Fin.exists_fin_two]
simp [h, hr₁.ne.symm]
· rcases h with ⟨m, hm, hmne⟩
rw [Fin.sum_univ_two, add_eq_zero_iff_eq_neg, Matrix.cons_val_zero,
Matrix.cons_val_one, Matrix.head_cons] at hm
rcases lt_trichotomy (m 0) 0 with (hm0 | hm0 | hm0) <;>
rcases lt_trichotomy (m 1) 0 with (hm1 | hm1 | hm1)
· refine
Or.inr (Or.inr (Or.inr ⟨-m 0, -m 1, Left.neg_pos_iff.2 hm0, Left.neg_pos_iff.2 hm1, ?_⟩))
rw [neg_smul_neg, neg_smul, hm, neg_neg]
· exfalso
simp [hm1, hx, hm0.ne] at hm
· refine Or.inl (Or.inr (Or.inr ⟨-m 0, m 1, Left.neg_pos_iff.2 hm0, hm1, ?_⟩))
rw [neg_smul, hm, neg_neg]
· exfalso
simp [hm0, hy, hm1.ne] at hm
· rw [Fin.exists_fin_two] at hmne
exact False.elim (not_and_or.2 hmne ⟨hm0, hm1⟩)
· exfalso
simp [hm0, hy, hm1.ne.symm] at hm
· refine Or.inl (Or.inr (Or.inr ⟨m 0, -m 1, hm0, Left.neg_pos_iff.2 hm1, ?_⟩))
rwa [neg_smul]
· exfalso
simp [hm1, hx, hm0.ne.symm] at hm
· refine Or.inr (Or.inr (Or.inr ⟨m 0, m 1, hm0, hm1, ?_⟩))
rwa [smul_neg]
/-- Two vectors are in the same ray, or they are nonzero and the first is in the same ray as the
negation of the second, if and only if they are not linearly independent. -/
theorem sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent {x y : M} :
SameRay R x y ∨ x ≠ 0 ∧ y ≠ 0 ∧ SameRay R x (-y) ↔ ¬LinearIndependent R ![x, y] := by
rw [← sameRay_or_sameRay_neg_iff_not_linearIndependent]
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0 <;> simp [hx, hy]
end
end LinearOrderedCommRing
namespace SameRay
variable {R : Type*} [LinearOrderedField R]
variable {M : Type*} [AddCommGroup M] [Module R M] {x y v₁ v₂ : M}
theorem exists_pos_left (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) :
∃ r : R, 0 < r ∧ r • x = y :=
let ⟨r₁, r₂, hr₁, hr₂, h⟩ := h.exists_pos hx hy
⟨r₂⁻¹ * r₁, mul_pos (inv_pos.2 hr₂) hr₁, by rw [mul_smul, h, inv_smul_smul₀ hr₂.ne']⟩
theorem exists_pos_right (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) :
∃ r : R, 0 < r ∧ x = r • y :=
(h.symm.exists_pos_left hy hx).imp fun _ => And.imp_right Eq.symm
/-- If a vector `v₂` is on the same ray as a nonzero vector `v₁`, then it is equal to `c • v₁` for
some nonnegative `c`. -/
theorem exists_nonneg_left (h : SameRay R x y) (hx : x ≠ 0) : ∃ r : R, 0 ≤ r ∧ r • x = y := by
obtain rfl | hy := eq_or_ne y 0
· exact ⟨0, le_rfl, zero_smul _ _⟩
· exact (h.exists_pos_left hx hy).imp fun _ => And.imp_left le_of_lt
/-- If a vector `v₁` is on the same ray as a nonzero vector `v₂`, then it is equal to `c • v₂` for
some nonnegative `c`. -/
theorem exists_nonneg_right (h : SameRay R x y) (hy : y ≠ 0) : ∃ r : R, 0 ≤ r ∧ x = r • y :=
(h.symm.exists_nonneg_left hy).imp fun _ => And.imp_right Eq.symm
/-- If vectors `v₁` and `v₂` are on the same ray, then for some nonnegative `a b`, `a + b = 1`, we
have `v₁ = a • (v₁ + v₂)` and `v₂ = b • (v₁ + v₂)`. -/
theorem exists_eq_smul_add (h : SameRay R v₁ v₂) :
∃ a b : R, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ v₁ = a • (v₁ + v₂) ∧ v₂ = b • (v₁ + v₂) := by
rcases h with (rfl | rfl | ⟨r₁, r₂, h₁, h₂, H⟩)
· use 0, 1
simp
· use 1, 0
simp
· have h₁₂ : 0 < r₁ + r₂ := add_pos h₁ h₂
refine
⟨r₂ / (r₁ + r₂), r₁ / (r₁ + r₂), div_nonneg h₂.le h₁₂.le, div_nonneg h₁.le h₁₂.le, ?_, ?_, ?_⟩
· rw [← add_div, add_comm, div_self h₁₂.ne']
· rw [div_eq_inv_mul, mul_smul, smul_add, ← H, ← add_smul, add_comm r₂, inv_smul_smul₀ h₁₂.ne']
· rw [div_eq_inv_mul, mul_smul, smul_add, H, ← add_smul, add_comm r₂, inv_smul_smul₀ h₁₂.ne']
/-- If vectors `v₁` and `v₂` are on the same ray, then they are nonnegative multiples of the same
vector. Actually, this vector can be assumed to be `v₁ + v₂`, see `SameRay.exists_eq_smul_add`. -/
theorem exists_eq_smul (h : SameRay R v₁ v₂) :
∃ (u : M) (a b : R), 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ v₁ = a • u ∧ v₂ = b • u :=
⟨v₁ + v₂, h.exists_eq_smul_add⟩
end SameRay
section LinearOrderedField
variable {R : Type*} [LinearOrderedField R]
variable {M : Type*} [AddCommGroup M] [Module R M] {x y : M}
theorem exists_pos_left_iff_sameRay (hx : x ≠ 0) (hy : y ≠ 0) :
(∃ r : R, 0 < r ∧ r • x = y) ↔ SameRay R x y := by
refine ⟨fun h => ?_, fun h => h.exists_pos_left hx hy⟩
rcases h with ⟨r, hr, rfl⟩
exact SameRay.sameRay_pos_smul_right x hr
theorem exists_pos_left_iff_sameRay_and_ne_zero (hx : x ≠ 0) :
(∃ r : R, 0 < r ∧ r • x = y) ↔ SameRay R x y ∧ y ≠ 0 := by
constructor
· rintro ⟨r, hr, rfl⟩
simp [hx, hr.le, hr.ne']
· rintro ⟨hxy, hy⟩
exact (exists_pos_left_iff_sameRay hx hy).2 hxy
theorem exists_nonneg_left_iff_sameRay (hx : x ≠ 0) :
(∃ r : R, 0 ≤ r ∧ r • x = y) ↔ SameRay R x y := by
refine ⟨fun h => ?_, fun h => h.exists_nonneg_left hx⟩
rcases h with ⟨r, hr, rfl⟩
exact SameRay.sameRay_nonneg_smul_right x hr
theorem exists_pos_right_iff_sameRay (hx : x ≠ 0) (hy : y ≠ 0) :
(∃ r : R, 0 < r ∧ x = r • y) ↔ SameRay R x y := by
rw [SameRay.sameRay_comm]
simp_rw [eq_comm (a := x)]
exact exists_pos_left_iff_sameRay hy hx
theorem exists_pos_right_iff_sameRay_and_ne_zero (hy : y ≠ 0) :
(∃ r : R, 0 < r ∧ x = r • y) ↔ SameRay R x y ∧ x ≠ 0 := by
rw [SameRay.sameRay_comm]
simp_rw [eq_comm (a := x)]
exact exists_pos_left_iff_sameRay_and_ne_zero hy
theorem exists_nonneg_right_iff_sameRay (hy : y ≠ 0) :
(∃ r : R, 0 ≤ r ∧ x = r • y) ↔ SameRay R x y := by
rw [SameRay.sameRay_comm]
simp_rw [eq_comm (a := x)]
exact exists_nonneg_left_iff_sameRay (R := R) hy
end LinearOrderedField
|
LinearAlgebra\Reflection.lean | /-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash, Deepro Choudhury
-/
import Mathlib.Algebra.Module.LinearMap.Basic
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.LinearAlgebra.Dual
import Mathlib.LinearAlgebra.FiniteSpan
/-!
# Reflections in linear algebra
Given an element `x` in a module `M` together with a linear form `f` on `M` such that `f x = 2`, the
map `y ↦ y - (f y) • x` is an involutive endomorphism of `M`, such that:
1. the kernel of `f` is fixed,
2. the point `x ↦ -x`.
Such endomorphisms are often called reflections of the module `M`. When `M` carries an inner product
for which `x` is perpendicular to the kernel of `f`, then (with mild assumptions) the endomorphism
is characterised by properties 1 and 2 above, and is a linear isometry.
## Main definitions / results:
* `Module.preReflection`: the definition of the map `y ↦ y - (f y) • x`. Its main utility lies in
the fact that it does not require the assumption `f x = 2`, giving the user freedom to defer
discharging this proof obligation.
* `Module.reflection`: the definition of the map `y ↦ y - (f y) • x`. This requires the assumption
that `f x = 2` but by way of compensation it produces a linear equivalence rather than a mere
linear map.
* `Module.Dual.eq_of_preReflection_mapsTo`: a uniqueness result about reflections preserving
finite spanning sets that is useful in the theory of root data / systems.
## TODO
Related definitions of reflection exists elsewhere in the library. These more specialised
definitions, which require an ambient `InnerProductSpace` structure, are `reflection` (of type
`LinearIsometryEquiv`) and `EuclideanGeometry.reflection` (of type `AffineIsometryEquiv`). We
should connect (or unify) these definitions with `Module.reflecton` defined here.
-/
open Set Function Pointwise
open Module hiding Finite
open Submodule (span)
noncomputable section
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] (x : M) (f : Dual R M) (y : M)
namespace Module
/-- Given an element `x` in a module `M` and a linear form `f` on `M`, we define the endomorphism
of `M` for which `y ↦ y - (f y) • x`.
One is typically interested in this endomorphism when `f x = 2`; this definition exists to allow the
user defer discharging this proof obligation. See also `Module.reflection`. -/
def preReflection : End R M :=
LinearMap.id - f.smulRight x
lemma preReflection_apply :
preReflection x f y = y - (f y) • x := by
simp [preReflection]
variable {x f}
lemma preReflection_apply_self (h : f x = 2) :
preReflection x f x = - x := by
rw [preReflection_apply, h, two_smul]; abel
lemma involutive_preReflection (h : f x = 2) :
Involutive (preReflection x f) :=
fun y ↦ by simp [h, smul_sub, two_smul, preReflection_apply]
lemma preReflection_preReflection (g : Dual R M) (h : f x = 2) :
preReflection (preReflection x f y) (preReflection f (Dual.eval R M x) g) =
(preReflection x f) ∘ₗ (preReflection y g) ∘ₗ (preReflection x f) := by
ext m
simp only [h, preReflection_apply, mul_comm (g x) (f m), mul_two, mul_assoc, Dual.eval_apply,
LinearMap.sub_apply, LinearMap.coe_comp, LinearMap.smul_apply, smul_eq_mul, smul_sub, sub_smul,
smul_smul, sub_mul, comp_apply, map_sub, map_smul, add_smul]
abel
/-- Given an element `x` in a module `M` and a linear form `f` on `M` for which `f x = 2`, we define
the endomorphism of `M` for which `y ↦ y - (f y) • x`.
It is an involutive endomorphism of `M` fixing the kernel of `f` for which `x ↦ -x`. -/
def reflection (h : f x = 2) : M ≃ₗ[R] M :=
{ preReflection x f, (involutive_preReflection h).toPerm with }
lemma reflection_apply (h : f x = 2) :
reflection h y = y - (f y) • x :=
preReflection_apply x f y
@[simp]
lemma reflection_apply_self (h : f x = 2) :
reflection h x = - x :=
preReflection_apply_self h
lemma involutive_reflection (h : f x = 2) :
Involutive (reflection h) :=
involutive_preReflection h
@[simp]
lemma reflection_symm (h : f x = 2) :
(reflection h).symm = reflection h :=
rfl
lemma invOn_reflection_of_mapsTo {Φ : Set M} (h : f x = 2) :
InvOn (reflection h) (reflection h) Φ Φ :=
⟨fun x _ ↦ involutive_reflection h x, fun x _ ↦ involutive_reflection h x⟩
lemma bijOn_reflection_of_mapsTo {Φ : Set M} (h : f x = 2) (h' : MapsTo (reflection h) Φ Φ) :
BijOn (reflection h) Φ Φ :=
(invOn_reflection_of_mapsTo h).bijOn h' h'
/-- See also `Module.Dual.eq_of_preReflection_mapsTo'` for a variant of this lemma which
applies when `Φ` does not span.
This rather technical-looking lemma exists because it is exactly what is needed to establish various
uniqueness results for root data / systems. One might regard this lemma as lying at the boundary of
linear algebra and combinatorics since the finiteness assumption is the key. -/
lemma Dual.eq_of_preReflection_mapsTo [CharZero R] [NoZeroSMulDivisors R M]
{x : M} (hx : x ≠ 0) {Φ : Set M} (hΦ₁ : Φ.Finite) (hΦ₂ : span R Φ = ⊤) {f g : Dual R M}
(hf₁ : f x = 2) (hf₂ : MapsTo (preReflection x f) Φ Φ)
(hg₁ : g x = 2) (hg₂ : MapsTo (preReflection x g) Φ Φ) :
f = g := by
let u := reflection hg₁ * reflection hf₁
have hu : u = LinearMap.id (R := R) (M := M) + (f - g).smulRight x := by
ext y
simp only [u, reflection_apply, hg₁, two_smul, LinearEquiv.coe_toLinearMap_mul,
LinearMap.id_coe, LinearEquiv.coe_coe, LinearMap.mul_apply, LinearMap.add_apply, id_eq,
LinearMap.coe_smulRight, LinearMap.sub_apply, map_sub, map_smul, sub_add_cancel_left,
smul_neg, sub_neg_eq_add, sub_smul]
abel
replace hu : ∀ (n : ℕ),
↑(u ^ n) = LinearMap.id (R := R) (M := M) + (n : R) • (f - g).smulRight x := by
intros n
induction n with
| zero => simp
| succ n ih =>
have : ((f - g).smulRight x).comp ((n : R) • (f - g).smulRight x) = 0 := by
ext; simp [hf₁, hg₁]
rw [pow_succ', LinearEquiv.coe_toLinearMap_mul, ih, hu, add_mul, mul_add, mul_add]
simp_rw [LinearMap.mul_eq_comp, LinearMap.comp_id, LinearMap.id_comp, this, add_zero,
add_assoc, Nat.cast_succ, add_smul, one_smul]
suffices IsOfFinOrder u by
obtain ⟨n, hn₀, hn₁⟩ := isOfFinOrder_iff_pow_eq_one.mp this
replace hn₁ : (↑(u ^ n) : M →ₗ[R] M) = LinearMap.id := LinearEquiv.toLinearMap_inj.mpr hn₁
simpa [hn₁, hn₀.ne', hx, sub_eq_zero] using hu n
exact u.isOfFinOrder_of_finite_of_span_eq_top_of_mapsTo hΦ₁ hΦ₂ (hg₂.comp hf₂)
/-- This rather technical-looking lemma exists because it is exactly what is needed to establish a
uniqueness result for root data. See the doc string of `Module.Dual.eq_of_preReflection_mapsTo` for
further remarks. -/
lemma Dual.eq_of_preReflection_mapsTo' [CharZero R] [NoZeroSMulDivisors R M]
{x : M} (hx : x ≠ 0) {Φ : Set M} (hΦ₁ : Φ.Finite) (hx' : x ∈ span R Φ) {f g : Dual R M}
(hf₁ : f x = 2) (hf₂ : MapsTo (preReflection x f) Φ Φ)
(hg₁ : g x = 2) (hg₂ : MapsTo (preReflection x g) Φ Φ) :
(span R Φ).subtype.dualMap f = (span R Φ).subtype.dualMap g := by
set Φ' : Set (span R Φ) := range (inclusion <| Submodule.subset_span (R := R) (s := Φ))
rw [← finite_coe_iff] at hΦ₁
have hΦ'₁ : Φ'.Finite := finite_range (inclusion Submodule.subset_span)
have hΦ'₂ : span R Φ' = ⊤ := by simp [Φ']
let x' : span R Φ := ⟨x, hx'⟩
have hx' : x' ≠ 0 := Subtype.coe_ne_coe.1 hx
have this : ∀ {F : Dual R M}, MapsTo (preReflection x F) Φ Φ →
MapsTo (preReflection x' ((span R Φ).subtype.dualMap F)) Φ' Φ' := by
intro F hF ⟨y, hy⟩ hy'
simp only [Φ', range_inclusion, SetLike.coe_sort_coe, mem_setOf_eq] at hy' ⊢
exact hF hy'
exact eq_of_preReflection_mapsTo hx' hΦ'₁ hΦ'₂ hf₁ (this hf₂) hg₁ (this hg₂)
variable {y}
variable {g : Dual R M}
lemma eq_of_mapsTo_reflection_of_mem [NoZeroSMulDivisors ℤ M] {Φ : Set M} (hΦ : Φ.Finite)
(hfx : f x = 2) (hgy : g y = 2) (hgx : g x = 2) (hfy : f y = 2)
(hxfΦ : MapsTo (preReflection x f) Φ Φ)
(hygΦ : MapsTo (preReflection y g) Φ Φ)
(hyΦ : y ∈ Φ) :
x = y := by
rw [← finite_coe_iff] at hΦ
set sxy : M ≃ₗ[R] M := (Module.reflection hgy).trans (Module.reflection hfx)
have hb : BijOn sxy Φ Φ :=
(bijOn_reflection_of_mapsTo hfx hxfΦ).comp (bijOn_reflection_of_mapsTo hgy hygΦ)
have hsxy : ∀ n : ℕ, (sxy^[n]) y = y + (2 * n : ℤ) • (x - y) := by
intro n
induction n with
| zero => simp
| succ n ih =>
simp only [iterate_succ', comp_apply, ih, zsmul_sub, map_add, LinearEquiv.trans_apply,
reflection_apply_self, map_neg, reflection_apply, hfy, two_smul, neg_sub, map_sub,
map_zsmul, hgx, smul_neg, smul_add, Nat.cast_succ, mul_add, mul_one, add_smul, sxy]
abel
set f' : ℕ → Φ := fun n ↦ ⟨(sxy^[n]) y, by
rw [← IsFixedPt.image_iterate hb.image_eq n]; exact mem_image_of_mem _ hyΦ⟩
have : ¬ Injective f' := not_injective_infinite_finite f'
contrapose! this
intros n m hnm
rw [Subtype.mk_eq_mk, hsxy, hsxy, add_right_inj, ← sub_eq_zero, ← sub_smul, smul_eq_zero,
sub_eq_zero, sub_eq_zero] at hnm
simpa using hnm.resolve_right this
lemma injOn_dualMap_subtype_span_range_range {ι : Type*} [NoZeroSMulDivisors ℤ M]
{r : ι ↪ M} {c : ι → Dual R M} (hfin : (range r).Finite)
(h_two : ∀ i, c i (r i) = 2)
(h_mapsTo : ∀ i, MapsTo (preReflection (r i) (c i)) (range r) (range r)) :
InjOn (span R (range r)).subtype.dualMap (range c) := by
rintro - ⟨i, rfl⟩ - ⟨j, rfl⟩ hij
congr
suffices ∀ k, c i (r k) = c j (r k) by
rw [← EmbeddingLike.apply_eq_iff_eq r]
exact eq_of_mapsTo_reflection_of_mem (f := c i) (g := c j) hfin (h_two i) (h_two j)
(by rw [← this, h_two]) (by rw [this, h_two]) (h_mapsTo i) (h_mapsTo j) (mem_range_self j)
intro k
simpa using LinearMap.congr_fun hij ⟨r k, Submodule.subset_span (mem_range_self k)⟩
end Module
|
LinearAlgebra\Semisimple.lean | /-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.FieldTheory.Perfect
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.LinearAlgebra.AnnihilatingPolynomial
import Mathlib.Order.CompleteSublattice
import Mathlib.RingTheory.Artinian
import Mathlib.RingTheory.QuotientNilpotent
import Mathlib.RingTheory.SimpleModule
/-!
# Semisimple linear endomorphisms
Given an `R`-module `M` together with an `R`-linear endomorphism `f : M → M`, the following two
conditions are equivalent:
1. Every `f`-invariant submodule of `M` has an `f`-invariant complement.
2. `M` is a semisimple `R[X]`-module, where the action of the polynomial ring is induced by `f`.
A linear endomorphism `f` satisfying these equivalent conditions is known as a *semisimple*
endomorphism. We provide basic definitions and results about such endomorphisms in this file.
## Main definitions / results:
* `Module.End.IsSemisimple`: the definition that a linear endomorphism is semisimple
* `Module.End.isSemisimple_iff`: the characterisation of semisimplicity in terms of invariant
submodules.
* `Module.End.eq_zero_of_isNilpotent_isSemisimple`: the zero endomorphism is the only endomorphism
that is both nilpotent and semisimple.
* `Module.End.isSemisimple_of_squarefree_aeval_eq_zero`: an endomorphism that is a root of a
square-free polynomial is semisimple (in finite dimensions over a field).
* `Module.End.IsSemisimple.minpoly_squarefree`: the minimal polynomial of a semisimple
endomorphism is squarefree.
* `IsSemisimple.of_mem_adjoin_pair`: every endomorphism in the subalgebra generated by two
commuting semisimple endomorphisms is semisimple, if the base field is perfect.
## TODO
In finite dimensions over a field:
* Triangularizable iff diagonalisable for semisimple endomorphisms
-/
open Set Function Polynomial
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
namespace Module.End
section CommRing
variable (f g : End R M)
/-- A linear endomorphism of an `R`-module `M` is called *semisimple* if the induced `R[X]`-module
structure on `M` is semisimple. This is equivalent to saying that every `f`-invariant `R`-submodule
of `M` has an `f`-invariant complement: see `Module.End.isSemisimple_iff`. -/
abbrev IsSemisimple := IsSemisimpleModule R[X] (AEval' f)
variable {f g}
lemma isSemisimple_iff :
f.IsSemisimple ↔ ∀ p : Submodule R M, p ≤ p.comap f → ∃ q, q ≤ q.comap f ∧ IsCompl p q := by
set s := (AEval.comapSubmodule R M f).range
have h : s = {p : Submodule R M | p ≤ p.comap f} := AEval.range_comapSubmodule R M f
let e := CompleteLatticeHom.toOrderIsoRangeOfInjective _ (AEval.injective_comapSubmodule R M f)
simp_rw [Module.End.IsSemisimple, IsSemisimpleModule, e.complementedLattice_iff,
s.isComplemented_iff, ← SetLike.mem_coe, h, mem_setOf_eq]
@[simp]
lemma isSemisimple_zero [IsSemisimpleModule R M] : IsSemisimple (0 : Module.End R M) := by
simpa [isSemisimple_iff] using exists_isCompl
@[simp]
lemma isSemisimple_id [IsSemisimpleModule R M] : IsSemisimple (LinearMap.id : Module.End R M) := by
simpa [isSemisimple_iff] using exists_isCompl
@[simp] lemma isSemisimple_neg : (-f).IsSemisimple ↔ f.IsSemisimple := by simp [isSemisimple_iff]
lemma eq_zero_of_isNilpotent_isSemisimple (hn : IsNilpotent f) (hs : f.IsSemisimple) : f = 0 := by
have ⟨n, h0⟩ := hn
rw [← aeval_X (R := R) f]; rw [← aeval_X_pow (R := R) f] at h0
rw [← RingHom.mem_ker, ← AEval.annihilator_eq_ker_aeval (M := M)] at h0 ⊢
exact hs.annihilator_isRadical ⟨n, h0⟩
@[simp]
lemma isSemisimple_sub_algebraMap_iff {μ : R} :
(f - algebraMap R (End R M) μ).IsSemisimple ↔ f.IsSemisimple := by
suffices ∀ p : Submodule R M, p ≤ p.comap (f - algebraMap R (Module.End R M) μ) ↔ p ≤ p.comap f by
simp [isSemisimple_iff, this]
refine fun p ↦ ⟨fun h x hx ↦ ?_, fun h x hx ↦ p.sub_mem (h hx) (p.smul_mem μ hx)⟩
simpa using p.add_mem (h hx) (p.smul_mem μ hx)
lemma IsSemisimple.restrict {p : Submodule R M} {hp : MapsTo f p p} (hf : f.IsSemisimple) :
IsSemisimple (f.restrict hp) := by
simp only [isSemisimple_iff] at hf ⊢
intro q hq
replace hq : MapsTo f (q.map p.subtype) (q.map p.subtype) := by
rintro - ⟨⟨x, hx⟩, hx', rfl⟩; exact ⟨⟨f x, hp hx⟩, by simpa using hq hx', rfl⟩
obtain ⟨r, hr₁, hr₂⟩ := hf _ hq
refine ⟨r.comap p.subtype, fun x hx ↦ hr₁ hx, ?_⟩
rw [← q.comap_map_eq_of_injective p.injective_subtype]
exact p.isCompl_comap_subtype_of_isCompl_of_le hr₂ <| p.map_subtype_le q
end CommRing
section field
variable {K : Type*} [Field K] [Module K M] {f g : End K M}
lemma IsSemisimple_smul_iff {t : K} (ht : t ≠ 0) :
(t • f).IsSemisimple ↔ f.IsSemisimple := by
simp [isSemisimple_iff, Submodule.comap_smul f (h := ht)]
lemma IsSemisimple_smul (t : K) (h : f.IsSemisimple) :
(t • f).IsSemisimple := by
wlog ht : t ≠ 0; · simp [not_not.mp ht]
rwa [IsSemisimple_smul_iff ht]
theorem isSemisimple_of_squarefree_aeval_eq_zero {p : K[X]}
(hp : Squarefree p) (hpf : aeval f p = 0) : f.IsSemisimple := by
rw [← RingHom.mem_ker, ← AEval.annihilator_eq_ker_aeval (M := M), mem_annihilator,
← IsTorsionBy, ← isTorsionBySet_singleton_iff, isTorsionBySet_iff_is_torsion_by_span] at hpf
let R := K[X] ⧸ Ideal.span {p}
have : IsReduced R :=
(Ideal.isRadical_iff_quotient_reduced _).mp (isRadical_iff_span_singleton.mp hp.isRadical)
have : FiniteDimensional K R := (AdjoinRoot.powerBasis hp.ne_zero).finite
have : IsArtinianRing R := .of_finite K R
have : IsSemisimpleRing R := IsArtinianRing.isSemisimpleRing_of_isReduced R
letI : Module R (AEval' f) := Module.IsTorsionBySet.module hpf
let e : AEval' f →ₛₗ[Ideal.Quotient.mk (Ideal.span {p})] AEval' f :=
{ AddMonoidHom.id _ with map_smul' := fun _ _ ↦ rfl }
exact (e.isSemisimpleModule_iff_of_bijective bijective_id).mpr inferInstance
variable [FiniteDimensional K M]
section
variable (hf : f.IsSemisimple)
/-- The minimal polynomial of a semisimple endomorphism is square free -/
theorem IsSemisimple.minpoly_squarefree : Squarefree (minpoly K f) :=
IsRadical.squarefree (minpoly.ne_zero <| Algebra.IsIntegral.isIntegral _) <| by
rw [isRadical_iff_span_singleton, span_minpoly_eq_annihilator]; exact hf.annihilator_isRadical
protected theorem IsSemisimple.aeval (p : K[X]) : (aeval f p).IsSemisimple :=
let R := K[X] ⧸ Ideal.span {minpoly K f}
have : Finite K R :=
(AdjoinRoot.powerBasis' <| minpoly.monic <| Algebra.IsIntegral.isIntegral f).finite
have : IsReduced R := (Ideal.isRadical_iff_quotient_reduced _).mp <|
span_minpoly_eq_annihilator K f ▸ hf.annihilator_isRadical
isSemisimple_of_squarefree_aeval_eq_zero ((minpoly.isRadical K _).squarefree <|
minpoly.ne_zero <| .of_finite K <| Ideal.Quotient.mkₐ K (.span {minpoly K f}) p) <| by
rw [← Ideal.Quotient.liftₐ_comp (.span {minpoly K f}) (aeval f)
fun a h ↦ by rwa [Ideal.span, ← minpoly.ker_aeval_eq_span_minpoly] at h, aeval_algHom,
AlgHom.comp_apply, AlgHom.comp_apply, ← aeval_algHom_apply, minpoly.aeval, map_zero]
theorem IsSemisimple.of_mem_adjoin_singleton {a : End K M}
(ha : a ∈ Algebra.adjoin K {f}) : a.IsSemisimple := by
rw [Algebra.adjoin_singleton_eq_range_aeval] at ha; obtain ⟨p, rfl⟩ := ha; exact .aeval hf _
protected theorem IsSemisimple.pow (n : ℕ) : (f ^ n).IsSemisimple :=
.of_mem_adjoin_singleton hf (pow_mem (Algebra.self_mem_adjoin_singleton _ _) _)
end
section PerfectField
variable [PerfectField K] (comm : Commute f g) (hf : f.IsSemisimple) (hg : g.IsSemisimple)
theorem IsSemisimple.of_mem_adjoin_pair {a : End K M} (ha : a ∈ Algebra.adjoin K {f, g}) :
a.IsSemisimple := by
let R := K[X] ⧸ Ideal.span {minpoly K f}
let S := AdjoinRoot ((minpoly K g).map <| algebraMap K R)
have : Finite K R :=
(AdjoinRoot.powerBasis' <| minpoly.monic <| Algebra.IsIntegral.isIntegral f).finite
have : Finite R S :=
(AdjoinRoot.powerBasis' <| (minpoly.monic <| Algebra.IsIntegral.isIntegral g).map _).finite
#adaptation_note
/--
After https://github.com/leanprover/lean4/pull/4119 we either need
to specify the `(S := R)` argument, or use `set_option maxSynthPendingDepth 2 in`.
In either case this step is too slow!
-/
set_option maxSynthPendingDepth 2 in
have : IsScalarTower K R S := .of_algebraMap_eq fun _ ↦ rfl
have : Finite K S := .trans R S
have : IsArtinianRing R := .of_finite K R
have : IsReduced R := (Ideal.isRadical_iff_quotient_reduced _).mp <|
span_minpoly_eq_annihilator K f ▸ hf.annihilator_isRadical
have : IsReduced S := by
simp_rw [S, AdjoinRoot, ← Ideal.isRadical_iff_quotient_reduced, ← isRadical_iff_span_singleton]
exact (PerfectField.separable_iff_squarefree.mpr hg.minpoly_squarefree).map.squarefree.isRadical
let φ : S →ₐ[K] End K M := Ideal.Quotient.liftₐ _ (eval₂AlgHom' (Ideal.Quotient.liftₐ _ (aeval f)
fun a ↦ ?_) g ?_) ((Ideal.span_singleton_le_iff_mem _).mpr ?_ : _ ≤ RingHom.ker _)
rotate_left 1
· rw [Ideal.span, ← minpoly.ker_aeval_eq_span_minpoly]; exact id
· rintro ⟨p⟩; exact p.induction_on (fun k ↦ by simp [R, Algebra.commute_algebraMap_left])
(fun p q hp hq ↦ by simpa using hp.add_left hq)
fun n k ↦ by simpa [R, pow_succ, ← mul_assoc _ _ X] using (·.mul_left comm)
· simpa only [RingHom.mem_ker, eval₂AlgHom'_apply, eval₂_map, AlgHom.comp_algebraMap_of_tower]
using minpoly.aeval K g
have : Algebra.adjoin K {f, g} ≤ φ.range := Algebra.adjoin_le fun x ↦ by
rintro (hx | hx) <;> rw [hx]
· exact ⟨AdjoinRoot.of _ (AdjoinRoot.root _), (eval₂_C _ _).trans (aeval_X f)⟩
· exact ⟨AdjoinRoot.root _, eval₂_X _ _⟩
obtain ⟨p, rfl⟩ := (AlgHom.mem_range _).mp (this ha)
refine isSemisimple_of_squarefree_aeval_eq_zero
((minpoly.isRadical K p).squarefree <| minpoly.ne_zero <| .of_finite K p) ?_
rw [aeval_algHom, φ.comp_apply, minpoly.aeval, map_zero]
theorem IsSemisimple.add_of_commute : (f + g).IsSemisimple := .of_mem_adjoin_pair
comm hf hg <| add_mem (Algebra.subset_adjoin <| .inl rfl) (Algebra.subset_adjoin <| .inr rfl)
theorem IsSemisimple.sub_of_commute : (f - g).IsSemisimple := .of_mem_adjoin_pair
comm hf hg <| sub_mem (Algebra.subset_adjoin <| .inl rfl) (Algebra.subset_adjoin <| .inr rfl)
theorem IsSemisimple.mul_of_commute : (f * g).IsSemisimple := .of_mem_adjoin_pair
comm hf hg <| mul_mem (Algebra.subset_adjoin <| .inl rfl) (Algebra.subset_adjoin <| .inr rfl)
end PerfectField
end field
end Module.End
|
LinearAlgebra\SesquilinearForm.lean | /-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andreas Swerdlow
-/
import Mathlib.LinearAlgebra.Basis
import Mathlib.LinearAlgebra.BilinearMap
/-!
# Sesquilinear maps
This files provides properties about sesquilinear maps and forms. The maps considered are of the
form `M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M`, where `I₁ : R₁ →+* R` and `I₂ : R₂ →+* R` are ring homomorphisms and
`M₁` is a module over `R₁`, `M₂` is a module over `R₂` and `M` is a module over `R`.
Sesquilinear forms are the special case that `M₁ = M₂`, `M = R₁ = R₂ = R`, and `I₁ = RingHom.id R`.
Taking additionally `I₂ = RingHom.id R`, then one obtains bilinear forms.
These forms are a special case of the bilinear maps defined in `BilinearMap.lean` and all basic
lemmas about construction and elementary calculations are found there.
## Main declarations
* `IsOrtho`: states that two vectors are orthogonal with respect to a sesquilinear map
* `IsSymm`, `IsAlt`: states that a sesquilinear form is symmetric and alternating, respectively
* `orthogonalBilin`: provides the orthogonal complement with respect to sesquilinear form
## References
* <https://en.wikipedia.org/wiki/Sesquilinear_form#Over_arbitrary_rings>
## Tags
Sesquilinear form, Sesquilinear map,
-/
variable {R R₁ R₂ R₃ M M₁ M₂ M₃ Mₗ₁ Mₗ₁' Mₗ₂ Mₗ₂' K K₁ K₂ V V₁ V₂ n : Type*}
namespace LinearMap
/-! ### Orthogonal vectors -/
section CommRing
-- the `ₗ` subscript variables are for special cases about linear (as opposed to semilinear) maps
variable [CommSemiring R] [CommSemiring R₁] [AddCommMonoid M₁] [Module R₁ M₁] [CommSemiring R₂]
[AddCommMonoid M₂] [Module R₂ M₂] [AddCommMonoid M] [Module R M]
{I₁ : R₁ →+* R} {I₂ : R₂ →+* R} {I₁' : R₁ →+* R}
/-- The proposition that two elements of a sesquilinear map space are orthogonal -/
def IsOrtho (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) (x : M₁) (y : M₂) : Prop :=
B x y = 0
theorem isOrtho_def {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} {x y} : B.IsOrtho x y ↔ B x y = 0 :=
Iff.rfl
theorem isOrtho_zero_left (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) (x) : IsOrtho B (0 : M₁) x := by
dsimp only [IsOrtho]
rw [map_zero B, zero_apply]
theorem isOrtho_zero_right (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) (x) : IsOrtho B x (0 : M₂) :=
map_zero (B x)
theorem isOrtho_flip {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M} {x y} : B.IsOrtho x y ↔ B.flip.IsOrtho y x := by
simp_rw [isOrtho_def, flip_apply]
/-- A set of vectors `v` is orthogonal with respect to some bilinear map `B` if and only
if for all `i ≠ j`, `B (v i) (v j) = 0`. For orthogonality between two elements, use
`BilinForm.isOrtho` -/
def IsOrthoᵢ (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M) (v : n → M₁) : Prop :=
Pairwise (B.IsOrtho on v)
theorem isOrthoᵢ_def {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M} {v : n → M₁} :
B.IsOrthoᵢ v ↔ ∀ i j : n, i ≠ j → B (v i) (v j) = 0 :=
Iff.rfl
theorem isOrthoᵢ_flip (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M) {v : n → M₁} :
B.IsOrthoᵢ v ↔ B.flip.IsOrthoᵢ v := by
simp_rw [isOrthoᵢ_def]
constructor <;> intro h i j hij
· rw [flip_apply]
exact h j i (Ne.symm hij)
simp_rw [flip_apply] at h
exact h j i (Ne.symm hij)
end CommRing
section Field
variable [Field K] [AddCommGroup V] [Module K V] [Field K₁] [AddCommGroup V₁] [Module K₁ V₁]
[Field K₂] [AddCommGroup V₂] [Module K₂ V₂]
{I₁ : K₁ →+* K} {I₂ : K₂ →+* K} {I₁' : K₁ →+* K} {J₁ : K →+* K} {J₂ : K →+* K}
-- todo: this also holds for [CommRing R] [IsDomain R] when J₁ is invertible
theorem ortho_smul_left {B : V₁ →ₛₗ[I₁] V₂ →ₛₗ[I₂] V} {x y} {a : K₁} (ha : a ≠ 0) :
IsOrtho B x y ↔ IsOrtho B (a • x) y := by
dsimp only [IsOrtho]
constructor <;> intro H
· rw [map_smulₛₗ₂, H, smul_zero]
· rw [map_smulₛₗ₂, smul_eq_zero] at H
cases' H with H H
· rw [map_eq_zero I₁] at H
trivial
· exact H
-- todo: this also holds for [CommRing R] [IsDomain R] when J₂ is invertible
theorem ortho_smul_right {B : V₁ →ₛₗ[I₁] V₂ →ₛₗ[I₂] V} {x y} {a : K₂} {ha : a ≠ 0} :
IsOrtho B x y ↔ IsOrtho B x (a • y) := by
dsimp only [IsOrtho]
constructor <;> intro H
· rw [map_smulₛₗ, H, smul_zero]
· rw [map_smulₛₗ, smul_eq_zero] at H
cases' H with H H
· simp at H
exfalso
exact ha H
· exact H
/-- A set of orthogonal vectors `v` with respect to some sesquilinear map `B` is linearly
independent if for all `i`, `B (v i) (v i) ≠ 0`. -/
theorem linearIndependent_of_isOrthoᵢ {B : V₁ →ₛₗ[I₁] V₁ →ₛₗ[I₁'] V} {v : n → V₁}
(hv₁ : B.IsOrthoᵢ v) (hv₂ : ∀ i, ¬B.IsOrtho (v i) (v i)) : LinearIndependent K₁ v := by
classical
rw [linearIndependent_iff']
intro s w hs i hi
have : B (s.sum fun i : n ↦ w i • v i) (v i) = 0 := by rw [hs, map_zero, zero_apply]
have hsum : (s.sum fun j : n ↦ I₁ (w j) • B (v j) (v i)) = I₁ (w i) • B (v i) (v i) := by
apply Finset.sum_eq_single_of_mem i hi
intro j _hj hij
rw [isOrthoᵢ_def.1 hv₁ _ _ hij, smul_zero]
simp_rw [B.map_sum₂, map_smulₛₗ₂, hsum] at this
apply (map_eq_zero I₁).mp
exact (smul_eq_zero.mp this).elim _root_.id (hv₂ i · |>.elim)
end Field
/-! ### Reflexive bilinear maps -/
section Reflexive
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁]
[Module R₁ M₁] {I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M}
/-- The proposition that a sesquilinear map is reflexive -/
def IsRefl (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M) : Prop :=
∀ x y, B x y = 0 → B y x = 0
namespace IsRefl
variable (H : B.IsRefl)
theorem eq_zero : ∀ {x y}, B x y = 0 → B y x = 0 := fun {x y} ↦ H x y
theorem ortho_comm {x y} : IsOrtho B x y ↔ IsOrtho B y x :=
⟨eq_zero H, eq_zero H⟩
theorem domRestrict (H : B.IsRefl) (p : Submodule R₁ M₁) : (B.domRestrict₁₂ p p).IsRefl :=
fun _ _ ↦ by
simp_rw [domRestrict₁₂_apply]
exact H _ _
@[simp]
theorem flip_isRefl_iff : B.flip.IsRefl ↔ B.IsRefl :=
⟨fun h x y H ↦ h y x ((B.flip_apply _ _).trans H), fun h x y ↦ h y x⟩
theorem ker_flip_eq_bot (H : B.IsRefl) (h : LinearMap.ker B = ⊥) : LinearMap.ker B.flip = ⊥ := by
refine ker_eq_bot'.mpr fun _ hx ↦ ker_eq_bot'.mp h _ ?_
ext
exact H _ _ (LinearMap.congr_fun hx _)
theorem ker_eq_bot_iff_ker_flip_eq_bot (H : B.IsRefl) :
LinearMap.ker B = ⊥ ↔ LinearMap.ker B.flip = ⊥ := by
refine ⟨ker_flip_eq_bot H, fun h ↦ ?_⟩
exact (congr_arg _ B.flip_flip.symm).trans (ker_flip_eq_bot (flip_isRefl_iff.mpr H) h)
end IsRefl
end Reflexive
/-! ### Symmetric bilinear forms -/
section Symmetric
variable [CommSemiring R] [AddCommMonoid M] [Module R M] {I : R →+* R} {B : M →ₛₗ[I] M →ₗ[R] R}
/-- The proposition that a sesquilinear form is symmetric -/
def IsSymm (B : M →ₛₗ[I] M →ₗ[R] R) : Prop :=
∀ x y, I (B x y) = B y x
namespace IsSymm
protected theorem eq (H : B.IsSymm) (x y) : I (B x y) = B y x :=
H x y
theorem isRefl (H : B.IsSymm) : B.IsRefl := fun x y H1 ↦ by
rw [← H.eq]
simp [H1]
theorem ortho_comm (H : B.IsSymm) {x y} : IsOrtho B x y ↔ IsOrtho B y x :=
H.isRefl.ortho_comm
theorem domRestrict (H : B.IsSymm) (p : Submodule R M) : (B.domRestrict₁₂ p p).IsSymm :=
fun _ _ ↦ by
simp_rw [domRestrict₁₂_apply]
exact H _ _
end IsSymm
@[simp]
theorem isSymm_zero : (0 : M →ₛₗ[I] M →ₗ[R] R).IsSymm := fun _ _ => map_zero _
theorem isSymm_iff_eq_flip {B : LinearMap.BilinForm R M} : B.IsSymm ↔ B = B.flip := by
constructor <;> intro h
· ext
rw [← h, flip_apply, RingHom.id_apply]
intro x y
conv_lhs => rw [h]
rfl
end Symmetric
/-! ### Alternating bilinear maps -/
section Alternating
section CommSemiring
section AddCommMonoid
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁]
[Module R₁ M₁] {I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {I : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M}
/-- The proposition that a sesquilinear map is alternating -/
def IsAlt (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M) : Prop :=
∀ x, B x x = 0
variable (H : B.IsAlt)
theorem IsAlt.self_eq_zero (x : M₁) : B x x = 0 :=
H x
theorem IsAlt.eq_of_add_add_eq_zero [IsCancelAdd M] {a b c : M₁} (hAdd : a + b + c = 0) :
B a b = B b c := by
have : B a a + B a b + B a c = B a c + B b c + B c c := by
simp_rw [← map_add, ← map_add₂, hAdd, map_zero, LinearMap.zero_apply]
rw [H, H, zero_add, add_zero, add_comm] at this
exact add_left_cancel this
end AddCommMonoid
section AddCommGroup
namespace IsAlt
variable [CommSemiring R] [AddCommGroup M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁]
[Module R₁ M₁] {I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {I : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M}
theorem neg (H : B.IsAlt) (x y : M₁) : -B x y = B y x := by
have H1 : B (y + x) (y + x) = 0 := self_eq_zero H (y + x)
simp? [map_add, self_eq_zero H] at H1 says
simp only [map_add, add_apply, self_eq_zero H, zero_add, add_zero] at H1
rw [add_eq_zero_iff_neg_eq] at H1
exact H1
theorem isRefl (H : B.IsAlt) : B.IsRefl := by
intro x y h
rw [← neg H, h, neg_zero]
theorem ortho_comm (H : B.IsAlt) {x y} : IsOrtho B x y ↔ IsOrtho B y x :=
H.isRefl.ortho_comm
end IsAlt
end AddCommGroup
end CommSemiring
section Semiring
variable [CommRing R] [AddCommGroup M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁]
[Module R₁ M₁] {I : R₁ →+* R}
theorem isAlt_iff_eq_neg_flip [NoZeroDivisors R] [CharZero R] {B : M₁ →ₛₗ[I] M₁ →ₛₗ[I] R} :
B.IsAlt ↔ B = -B.flip := by
constructor <;> intro h
· ext
simp_rw [neg_apply, flip_apply]
exact (h.neg _ _).symm
intro x
let h' := congr_fun₂ h x x
simp only [neg_apply, flip_apply, ← add_eq_zero_iff_eq_neg] at h'
exact add_self_eq_zero.mp h'
end Semiring
end Alternating
end LinearMap
namespace Submodule
/-! ### The orthogonal complement -/
variable [CommRing R] [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁] [AddCommGroup M] [Module R M]
{I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M}
/-- The orthogonal complement of a submodule `N` with respect to some bilinear map is the set of
elements `x` which are orthogonal to all elements of `N`; i.e., for all `y` in `N`, `B x y = 0`.
Note that for general (neither symmetric nor antisymmetric) bilinear maps this definition has a
chirality; in addition to this "left" orthogonal complement one could define a "right" orthogonal
complement for which, for all `y` in `N`, `B y x = 0`. This variant definition is not currently
provided in mathlib. -/
def orthogonalBilin (N : Submodule R₁ M₁) (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M) : Submodule R₁ M₁ where
carrier := { m | ∀ n ∈ N, B.IsOrtho n m }
zero_mem' x _ := B.isOrtho_zero_right x
add_mem' hx hy n hn := by
rw [LinearMap.IsOrtho, map_add, show B n _ = 0 from hx n hn, show B n _ = 0 from hy n hn,
zero_add]
smul_mem' c x hx n hn := by
rw [LinearMap.IsOrtho, LinearMap.map_smulₛₗ, show B n x = 0 from hx n hn, smul_zero]
variable {N L : Submodule R₁ M₁}
@[simp]
theorem mem_orthogonalBilin_iff {m : M₁} : m ∈ N.orthogonalBilin B ↔ ∀ n ∈ N, B.IsOrtho n m :=
Iff.rfl
theorem orthogonalBilin_le (h : N ≤ L) : L.orthogonalBilin B ≤ N.orthogonalBilin B :=
fun _ hn l hl ↦ hn l (h hl)
theorem le_orthogonalBilin_orthogonalBilin (b : B.IsRefl) :
N ≤ (N.orthogonalBilin B).orthogonalBilin B := fun n hn _m hm ↦ b _ _ (hm n hn)
end Submodule
namespace LinearMap
section Orthogonal
variable [Field K] [AddCommGroup V] [Module K V] [Field K₁] [AddCommGroup V₁] [Module K₁ V₁]
[AddCommGroup V₂] [Module K V₂] {J : K →+* K} {J₁ : K₁ →+* K} {J₁' : K₁ →+* K}
-- ↓ This lemma only applies in fields as we require `a * b = 0 → a = 0 ∨ b = 0`
theorem span_singleton_inf_orthogonal_eq_bot (B : V₁ →ₛₗ[J₁] V₁ →ₛₗ[J₁'] V₂) (x : V₁)
(hx : ¬B.IsOrtho x x) : (K₁ ∙ x) ⊓ Submodule.orthogonalBilin (K₁ ∙ x) B = ⊥ := by
rw [← Finset.coe_singleton]
refine eq_bot_iff.2 fun y h ↦ ?_
rcases mem_span_finset.1 h.1 with ⟨μ, rfl⟩
replace h := h.2 x (by simp [Submodule.mem_span] : x ∈ Submodule.span K₁ ({x} : Finset V₁))
rw [Finset.sum_singleton] at h ⊢
suffices hμzero : μ x = 0 by rw [hμzero, zero_smul, Submodule.mem_bot]
rw [isOrtho_def, map_smulₛₗ] at h
exact Or.elim (smul_eq_zero.mp h)
(fun y ↦ by simpa using y)
(fun hfalse ↦ False.elim <| hx hfalse)
-- ↓ This lemma only applies in fields since we use the `mul_eq_zero`
theorem orthogonal_span_singleton_eq_to_lin_ker {B : V →ₗ[K] V →ₛₗ[J] V₂} (x : V) :
Submodule.orthogonalBilin (K ∙ x) B = LinearMap.ker (B x) := by
ext y
simp_rw [Submodule.mem_orthogonalBilin_iff, LinearMap.mem_ker, Submodule.mem_span_singleton]
constructor
· exact fun h ↦ h x ⟨1, one_smul _ _⟩
· rintro h _ ⟨z, rfl⟩
rw [isOrtho_def, map_smulₛₗ₂, smul_eq_zero]
exact Or.intro_right _ h
-- todo: Generalize this to sesquilinear maps
theorem span_singleton_sup_orthogonal_eq_top {B : V →ₗ[K] V →ₗ[K] K} {x : V} (hx : ¬B.IsOrtho x x) :
(K ∙ x) ⊔ Submodule.orthogonalBilin (N := K ∙ x) (B := B) = ⊤ := by
rw [orthogonal_span_singleton_eq_to_lin_ker]
exact (B x).span_singleton_sup_ker_eq_top hx
-- todo: Generalize this to sesquilinear maps
/-- Given a bilinear form `B` and some `x` such that `B x x ≠ 0`, the span of the singleton of `x`
is complement to its orthogonal complement. -/
theorem isCompl_span_singleton_orthogonal {B : V →ₗ[K] V →ₗ[K] K} {x : V} (hx : ¬B.IsOrtho x x) :
IsCompl (K ∙ x) (Submodule.orthogonalBilin (N := K ∙ x) (B := B)) :=
{ disjoint := disjoint_iff.2 <| span_singleton_inf_orthogonal_eq_bot B x hx
codisjoint := codisjoint_iff.2 <| span_singleton_sup_orthogonal_eq_top hx }
end Orthogonal
/-! ### Adjoint pairs -/
section AdjointPair
section AddCommMonoid
variable [CommSemiring R]
variable [AddCommMonoid M] [Module R M]
variable [AddCommMonoid M₁] [Module R M₁]
variable [AddCommMonoid M₂] [Module R M₂]
variable [AddCommMonoid M₃] [Module R M₃]
variable {I : R →+* R}
variable {B F : M →ₗ[R] M →ₛₗ[I] M₃} {B' : M₁ →ₗ[R] M₁ →ₛₗ[I] M₃} {B'' : M₂ →ₗ[R] M₂ →ₛₗ[I] M₃}
variable {f f' : M →ₗ[R] M₁} {g g' : M₁ →ₗ[R] M}
variable (B B' f g)
/-- Given a pair of modules equipped with bilinear maps, this is the condition for a pair of
maps between them to be mutually adjoint. -/
def IsAdjointPair :=
∀ x y, B' (f x) y = B x (g y)
variable {B B' f g}
theorem isAdjointPair_iff_comp_eq_compl₂ : IsAdjointPair B B' f g ↔ B'.comp f = B.compl₂ g := by
constructor <;> intro h
· ext x y
rw [comp_apply, compl₂_apply]
exact h x y
· intro _ _
rw [← compl₂_apply, ← comp_apply, h]
theorem isAdjointPair_zero : IsAdjointPair B B' 0 0 := fun _ _ ↦ by simp only [zero_apply, map_zero]
theorem isAdjointPair_id : IsAdjointPair B B 1 1 := fun _ _ ↦ rfl
theorem IsAdjointPair.add (h : IsAdjointPair B B' f g) (h' : IsAdjointPair B B' f' g') :
IsAdjointPair B B' (f + f') (g + g') := fun x _ ↦ by
rw [f.add_apply, g.add_apply, B'.map_add₂, (B x).map_add, h, h']
theorem IsAdjointPair.comp {f' : M₁ →ₗ[R] M₂} {g' : M₂ →ₗ[R] M₁} (h : IsAdjointPair B B' f g)
(h' : IsAdjointPair B' B'' f' g') : IsAdjointPair B B'' (f'.comp f) (g.comp g') := fun _ _ ↦ by
rw [LinearMap.comp_apply, LinearMap.comp_apply, h', h]
theorem IsAdjointPair.mul {f g f' g' : Module.End R M} (h : IsAdjointPair B B f g)
(h' : IsAdjointPair B B f' g') : IsAdjointPair B B (f * f') (g' * g) :=
h'.comp h
end AddCommMonoid
section AddCommGroup
variable [CommRing R]
variable [AddCommGroup M] [Module R M]
variable [AddCommGroup M₁] [Module R M₁]
variable [AddCommGroup M₂] [Module R M₂]
variable {B F : M →ₗ[R] M →ₗ[R] M₂} {B' : M₁ →ₗ[R] M₁ →ₗ[R] M₂}
variable {f f' : M →ₗ[R] M₁} {g g' : M₁ →ₗ[R] M}
theorem IsAdjointPair.sub (h : IsAdjointPair B B' f g) (h' : IsAdjointPair B B' f' g') :
IsAdjointPair B B' (f - f') (g - g') := fun x _ ↦ by
rw [f.sub_apply, g.sub_apply, B'.map_sub₂, (B x).map_sub, h, h']
theorem IsAdjointPair.smul (c : R) (h : IsAdjointPair B B' f g) :
IsAdjointPair B B' (c • f) (c • g) := fun _ _ ↦ by
simp [h _]
end AddCommGroup
end AdjointPair
/-! ### Self-adjoint pairs-/
section SelfadjointPair
section AddCommMonoid
variable [CommSemiring R]
variable [AddCommMonoid M] [Module R M]
variable [AddCommMonoid M₁] [Module R M₁]
variable {I : R →+* R}
variable (B F : M →ₗ[R] M →ₛₗ[I] M₁)
/-- The condition for an endomorphism to be "self-adjoint" with respect to a pair of bilinear maps
on the underlying module. In the case that these two maps are identical, this is the usual concept
of self adjointness. In the case that one of the maps is the negation of the other, this is the
usual concept of skew adjointness. -/
def IsPairSelfAdjoint (f : Module.End R M) :=
IsAdjointPair B F f f
/-- An endomorphism of a module is self-adjoint with respect to a bilinear map if it serves as an
adjoint for itself. -/
protected def IsSelfAdjoint (f : Module.End R M) :=
IsAdjointPair B B f f
end AddCommMonoid
section AddCommGroup
variable [CommRing R]
variable [AddCommGroup M] [Module R M] [AddCommGroup M₁] [Module R M₁]
variable [AddCommGroup M₂] [Module R M₂] (B F : M →ₗ[R] M →ₗ[R] M₂)
/-- The set of pair-self-adjoint endomorphisms are a submodule of the type of all endomorphisms. -/
def isPairSelfAdjointSubmodule : Submodule R (Module.End R M) where
carrier := { f | IsPairSelfAdjoint B F f }
zero_mem' := isAdjointPair_zero
add_mem' hf hg := hf.add hg
smul_mem' c _ h := h.smul c
/-- An endomorphism of a module is skew-adjoint with respect to a bilinear map if its negation
serves as an adjoint. -/
def IsSkewAdjoint (f : Module.End R M) :=
IsAdjointPair B B f (-f)
/-- The set of self-adjoint endomorphisms of a module with bilinear map is a submodule. (In fact
it is a Jordan subalgebra.) -/
def selfAdjointSubmodule :=
isPairSelfAdjointSubmodule B B
/-- The set of skew-adjoint endomorphisms of a module with bilinear map is a submodule. (In fact
it is a Lie subalgebra.) -/
def skewAdjointSubmodule :=
isPairSelfAdjointSubmodule (-B) B
variable {B F}
@[simp]
theorem mem_isPairSelfAdjointSubmodule (f : Module.End R M) :
f ∈ isPairSelfAdjointSubmodule B F ↔ IsPairSelfAdjoint B F f :=
Iff.rfl
theorem isPairSelfAdjoint_equiv (e : M₁ ≃ₗ[R] M) (f : Module.End R M) :
IsPairSelfAdjoint B F f ↔
IsPairSelfAdjoint (B.compl₁₂ ↑e ↑e) (F.compl₁₂ ↑e ↑e) (e.symm.conj f) := by
have hₗ :
(F.compl₁₂ (↑e : M₁ →ₗ[R] M) (↑e : M₁ →ₗ[R] M)).comp (e.symm.conj f) =
(F.comp f).compl₁₂ (↑e : M₁ →ₗ[R] M) (↑e : M₁ →ₗ[R] M) := by
ext
simp only [LinearEquiv.symm_conj_apply, coe_comp, LinearEquiv.coe_coe, compl₁₂_apply,
LinearEquiv.apply_symm_apply, Function.comp_apply]
have hᵣ :
(B.compl₁₂ (↑e : M₁ →ₗ[R] M) (↑e : M₁ →ₗ[R] M)).compl₂ (e.symm.conj f) =
(B.compl₂ f).compl₁₂ (↑e : M₁ →ₗ[R] M) (↑e : M₁ →ₗ[R] M) := by
ext
simp only [LinearEquiv.symm_conj_apply, compl₂_apply, coe_comp, LinearEquiv.coe_coe,
compl₁₂_apply, LinearEquiv.apply_symm_apply, Function.comp_apply]
have he : Function.Surjective (⇑(↑e : M₁ →ₗ[R] M) : M₁ → M) := e.surjective
simp_rw [IsPairSelfAdjoint, isAdjointPair_iff_comp_eq_compl₂, hₗ, hᵣ, compl₁₂_inj he he]
theorem isSkewAdjoint_iff_neg_self_adjoint (f : Module.End R M) :
B.IsSkewAdjoint f ↔ IsAdjointPair (-B) B f f :=
show (∀ x y, B (f x) y = B x ((-f) y)) ↔ ∀ x y, B (f x) y = (-B) x (f y) by simp
@[simp]
theorem mem_selfAdjointSubmodule (f : Module.End R M) :
f ∈ B.selfAdjointSubmodule ↔ B.IsSelfAdjoint f :=
Iff.rfl
@[simp]
theorem mem_skewAdjointSubmodule (f : Module.End R M) :
f ∈ B.skewAdjointSubmodule ↔ B.IsSkewAdjoint f := by
rw [isSkewAdjoint_iff_neg_self_adjoint]
exact Iff.rfl
end AddCommGroup
end SelfadjointPair
/-! ### Nondegenerate bilinear maps -/
section Nondegenerate
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁]
[Module R₁ M₁] [CommSemiring R₂] [AddCommMonoid M₂] [Module R₂ M₂]
{I₁ : R₁ →+* R} {I₂ : R₂ →+* R} {I₁' : R₁ →+* R}
/-- A bilinear map is called left-separating if
the only element that is left-orthogonal to every other element is `0`; i.e.,
for every nonzero `x` in `M₁`, there exists `y` in `M₂` with `B x y ≠ 0`. -/
def SeparatingLeft (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) : Prop :=
∀ x : M₁, (∀ y : M₂, B x y = 0) → x = 0
variable (M₁ M₂ I₁ I₂)
/-- In a non-trivial module, zero is not non-degenerate. -/
theorem not_separatingLeft_zero [Nontrivial M₁] : ¬(0 : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M).SeparatingLeft :=
let ⟨m, hm⟩ := exists_ne (0 : M₁)
fun h ↦ hm (h m fun _n ↦ rfl)
variable {M₁ M₂ I₁ I₂}
theorem SeparatingLeft.ne_zero [Nontrivial M₁] {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M}
(h : B.SeparatingLeft) : B ≠ 0 := fun h0 ↦ not_separatingLeft_zero M₁ M₂ I₁ I₂ <| h0 ▸ h
section Linear
variable [AddCommMonoid Mₗ₁] [AddCommMonoid Mₗ₂] [AddCommMonoid Mₗ₁'] [AddCommMonoid Mₗ₂']
variable [Module R Mₗ₁] [Module R Mₗ₂] [Module R Mₗ₁'] [Module R Mₗ₂']
variable {B : Mₗ₁ →ₗ[R] Mₗ₂ →ₗ[R] M} (e₁ : Mₗ₁ ≃ₗ[R] Mₗ₁') (e₂ : Mₗ₂ ≃ₗ[R] Mₗ₂')
theorem SeparatingLeft.congr (h : B.SeparatingLeft) :
(e₁.arrowCongr (e₂.arrowCongr (LinearEquiv.refl R M)) B).SeparatingLeft := by
intro x hx
rw [← e₁.symm.map_eq_zero_iff]
refine h (e₁.symm x) fun y ↦ ?_
specialize hx (e₂ y)
simp only [LinearEquiv.arrowCongr_apply, LinearEquiv.symm_apply_apply,
LinearEquiv.map_eq_zero_iff] at hx
exact hx
@[simp]
theorem separatingLeft_congr_iff :
(e₁.arrowCongr (e₂.arrowCongr (LinearEquiv.refl R M)) B).SeparatingLeft ↔ B.SeparatingLeft :=
⟨fun h ↦ by
convert h.congr e₁.symm e₂.symm
ext x y
simp,
SeparatingLeft.congr e₁ e₂⟩
end Linear
/-- A bilinear map is called right-separating if
the only element that is right-orthogonal to every other element is `0`; i.e.,
for every nonzero `y` in `M₂`, there exists `x` in `M₁` with `B x y ≠ 0`. -/
def SeparatingRight (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) : Prop :=
∀ y : M₂, (∀ x : M₁, B x y = 0) → y = 0
/-- A bilinear map is called non-degenerate if it is left-separating and right-separating. -/
def Nondegenerate (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) : Prop :=
SeparatingLeft B ∧ SeparatingRight B
@[simp]
theorem flip_separatingRight {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} :
B.flip.SeparatingRight ↔ B.SeparatingLeft :=
⟨fun hB x hy ↦ hB x hy, fun hB x hy ↦ hB x hy⟩
@[simp]
theorem flip_separatingLeft {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} :
B.flip.SeparatingLeft ↔ SeparatingRight B := by rw [← flip_separatingRight, flip_flip]
@[simp]
theorem flip_nondegenerate {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} : B.flip.Nondegenerate ↔ B.Nondegenerate :=
Iff.trans and_comm (and_congr flip_separatingRight flip_separatingLeft)
theorem separatingLeft_iff_linear_nontrivial {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} :
B.SeparatingLeft ↔ ∀ x : M₁, B x = 0 → x = 0 := by
constructor <;> intro h x hB
· simpa only [hB, zero_apply, eq_self_iff_true, forall_const] using h x
have h' : B x = 0 := by
ext
rw [zero_apply]
exact hB _
exact h x h'
theorem separatingRight_iff_linear_flip_nontrivial {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} :
B.SeparatingRight ↔ ∀ y : M₂, B.flip y = 0 → y = 0 := by
rw [← flip_separatingLeft, separatingLeft_iff_linear_nontrivial]
/-- A bilinear map is left-separating if and only if it has a trivial kernel. -/
theorem separatingLeft_iff_ker_eq_bot {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} :
B.SeparatingLeft ↔ LinearMap.ker B = ⊥ :=
Iff.trans separatingLeft_iff_linear_nontrivial LinearMap.ker_eq_bot'.symm
/-- A bilinear map is right-separating if and only if its flip has a trivial kernel. -/
theorem separatingRight_iff_flip_ker_eq_bot {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} :
B.SeparatingRight ↔ LinearMap.ker B.flip = ⊥ := by
rw [← flip_separatingLeft, separatingLeft_iff_ker_eq_bot]
end CommSemiring
section CommRing
variable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup M₁] [Module R M₁] {I I' : R →+* R}
theorem IsRefl.nondegenerate_of_separatingLeft {B : M →ₗ[R] M →ₗ[R] M₁} (hB : B.IsRefl)
(hB' : B.SeparatingLeft) : B.Nondegenerate := by
refine ⟨hB', ?_⟩
rw [separatingRight_iff_flip_ker_eq_bot, hB.ker_eq_bot_iff_ker_flip_eq_bot.mp]
rwa [← separatingLeft_iff_ker_eq_bot]
theorem IsRefl.nondegenerate_of_separatingRight {B : M →ₗ[R] M →ₗ[R] M₁} (hB : B.IsRefl)
(hB' : B.SeparatingRight) : B.Nondegenerate := by
refine ⟨?_, hB'⟩
rw [separatingLeft_iff_ker_eq_bot, hB.ker_eq_bot_iff_ker_flip_eq_bot.mpr]
rwa [← separatingRight_iff_flip_ker_eq_bot]
/-- The restriction of a reflexive bilinear map `B` onto a submodule `W` is
nondegenerate if `W` has trivial intersection with its orthogonal complement,
that is `Disjoint W (W.orthogonalBilin B)`. -/
theorem nondegenerate_restrict_of_disjoint_orthogonal {B : M →ₗ[R] M →ₗ[R] M₁} (hB : B.IsRefl)
{W : Submodule R M} (hW : Disjoint W (W.orthogonalBilin B)) :
(B.domRestrict₁₂ W W).Nondegenerate := by
refine (hB.domRestrict W).nondegenerate_of_separatingLeft ?_
rintro ⟨x, hx⟩ b₁
rw [Submodule.mk_eq_zero, ← Submodule.mem_bot R]
refine hW.le_bot ⟨hx, fun y hy ↦ ?_⟩
specialize b₁ ⟨y, hy⟩
simp_rw [domRestrict₁₂_apply] at b₁
rw [hB.ortho_comm]
exact b₁
/-- An orthogonal basis with respect to a left-separating bilinear map has no self-orthogonal
elements. -/
theorem IsOrthoᵢ.not_isOrtho_basis_self_of_separatingLeft [Nontrivial R]
{B : M →ₛₗ[I] M →ₛₗ[I'] M₁} {v : Basis n R M} (h : B.IsOrthoᵢ v) (hB : B.SeparatingLeft)
(i : n) : ¬B.IsOrtho (v i) (v i) := by
intro ho
refine v.ne_zero i (hB (v i) fun m ↦ ?_)
obtain ⟨vi, rfl⟩ := v.repr.symm.surjective m
rw [Basis.repr_symm_apply, Finsupp.total_apply, Finsupp.sum, map_sum]
apply Finset.sum_eq_zero
rintro j -
rw [map_smulₛₗ]
suffices B (v i) (v j) = 0 by rw [this, smul_zero]
obtain rfl | hij := eq_or_ne i j
· exact ho
· exact h hij
/-- An orthogonal basis with respect to a right-separating bilinear map has no self-orthogonal
elements. -/
theorem IsOrthoᵢ.not_isOrtho_basis_self_of_separatingRight [Nontrivial R]
{B : M →ₛₗ[I] M →ₛₗ[I'] M₁} {v : Basis n R M} (h : B.IsOrthoᵢ v) (hB : B.SeparatingRight)
(i : n) : ¬B.IsOrtho (v i) (v i) := by
rw [isOrthoᵢ_flip] at h
rw [isOrtho_flip]
exact h.not_isOrtho_basis_self_of_separatingLeft (flip_separatingLeft.mpr hB) i
/-- Given an orthogonal basis with respect to a bilinear map, the bilinear map is left-separating if
the basis has no elements which are self-orthogonal. -/
theorem IsOrthoᵢ.separatingLeft_of_not_isOrtho_basis_self [NoZeroSMulDivisors R M₁]
{B : M →ₗ[R] M →ₗ[R] M₁} (v : Basis n R M) (hO : B.IsOrthoᵢ v)
(h : ∀ i, ¬B.IsOrtho (v i) (v i)) : B.SeparatingLeft := by
intro m hB
obtain ⟨vi, rfl⟩ := v.repr.symm.surjective m
rw [LinearEquiv.map_eq_zero_iff]
ext i
rw [Finsupp.zero_apply]
specialize hB (v i)
simp_rw [Basis.repr_symm_apply, Finsupp.total_apply, Finsupp.sum, map_sum₂, map_smulₛₗ₂] at hB
rw [Finset.sum_eq_single i] at hB
· exact (smul_eq_zero.mp hB).elim _root_.id (h i).elim
· intro j _hj hij
replace hij : B (v j) (v i) = 0 := hO hij
rw [hij, RingHom.id_apply, smul_zero]
· intro hi
replace hi : vi i = 0 := Finsupp.not_mem_support_iff.mp hi
rw [hi, RingHom.id_apply, zero_smul]
/-- Given an orthogonal basis with respect to a bilinear map, the bilinear map is right-separating
if the basis has no elements which are self-orthogonal. -/
theorem IsOrthoᵢ.separatingRight_iff_not_isOrtho_basis_self [NoZeroSMulDivisors R M₁]
{B : M →ₗ[R] M →ₗ[R] M₁} (v : Basis n R M) (hO : B.IsOrthoᵢ v)
(h : ∀ i, ¬B.IsOrtho (v i) (v i)) : B.SeparatingRight := by
rw [isOrthoᵢ_flip] at hO
rw [← flip_separatingLeft]
refine IsOrthoᵢ.separatingLeft_of_not_isOrtho_basis_self v hO fun i ↦ ?_
rw [isOrtho_flip]
exact h i
/-- Given an orthogonal basis with respect to a bilinear map, the bilinear map is nondegenerate
if the basis has no elements which are self-orthogonal. -/
theorem IsOrthoᵢ.nondegenerate_of_not_isOrtho_basis_self [NoZeroSMulDivisors R M₁]
{B : M →ₗ[R] M →ₗ[R] M₁} (v : Basis n R M) (hO : B.IsOrthoᵢ v)
(h : ∀ i, ¬B.IsOrtho (v i) (v i)) : B.Nondegenerate :=
⟨IsOrthoᵢ.separatingLeft_of_not_isOrtho_basis_self v hO h,
IsOrthoᵢ.separatingRight_iff_not_isOrtho_basis_self v hO h⟩
end CommRing
end Nondegenerate
end LinearMap
|
LinearAlgebra\SModEq.lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Polynomial.Eval
import Mathlib.RingTheory.Ideal.Quotient
/-!
# modular equivalence for submodule
-/
open Submodule
open Polynomial
variable {R : Type*} [Ring R]
variable {A : Type*} [CommRing A]
variable {M : Type*} [AddCommGroup M] [Module R M] (U U₁ U₂ : Submodule R M)
variable {x x₁ x₂ y y₁ y₂ z z₁ z₂ : M}
variable {N : Type*} [AddCommGroup N] [Module R N] (V V₁ V₂ : Submodule R N)
/-- A predicate saying two elements of a module are equivalent modulo a submodule. -/
def SModEq (x y : M) : Prop :=
(Submodule.Quotient.mk x : M ⧸ U) = Submodule.Quotient.mk y
notation:50 x " ≡ " y " [SMOD " N "]" => SModEq N x y
variable {U U₁ U₂}
protected theorem SModEq.def :
x ≡ y [SMOD U] ↔ (Submodule.Quotient.mk x : M ⧸ U) = Submodule.Quotient.mk y :=
Iff.rfl
namespace SModEq
theorem sub_mem : x ≡ y [SMOD U] ↔ x - y ∈ U := by rw [SModEq.def, Submodule.Quotient.eq]
@[simp]
theorem top : x ≡ y [SMOD (⊤ : Submodule R M)] :=
(Submodule.Quotient.eq ⊤).2 mem_top
@[simp]
theorem bot : x ≡ y [SMOD (⊥ : Submodule R M)] ↔ x = y := by
rw [SModEq.def, Submodule.Quotient.eq, mem_bot, sub_eq_zero]
@[mono]
theorem mono (HU : U₁ ≤ U₂) (hxy : x ≡ y [SMOD U₁]) : x ≡ y [SMOD U₂] :=
(Submodule.Quotient.eq U₂).2 <| HU <| (Submodule.Quotient.eq U₁).1 hxy
@[refl]
protected theorem refl (x : M) : x ≡ x [SMOD U] :=
@rfl _ _
protected theorem rfl : x ≡ x [SMOD U] :=
SModEq.refl _
instance : IsRefl _ (SModEq U) :=
⟨SModEq.refl⟩
@[symm]
nonrec theorem symm (hxy : x ≡ y [SMOD U]) : y ≡ x [SMOD U] :=
hxy.symm
@[trans]
nonrec theorem trans (hxy : x ≡ y [SMOD U]) (hyz : y ≡ z [SMOD U]) : x ≡ z [SMOD U] :=
hxy.trans hyz
instance instTrans : Trans (SModEq U) (SModEq U) (SModEq U) where
trans := trans
theorem add (hxy₁ : x₁ ≡ y₁ [SMOD U]) (hxy₂ : x₂ ≡ y₂ [SMOD U]) : x₁ + x₂ ≡ y₁ + y₂ [SMOD U] := by
rw [SModEq.def] at hxy₁ hxy₂ ⊢
simp_rw [Quotient.mk_add, hxy₁, hxy₂]
theorem smul (hxy : x ≡ y [SMOD U]) (c : R) : c • x ≡ c • y [SMOD U] := by
rw [SModEq.def] at hxy ⊢
simp_rw [Quotient.mk_smul, hxy]
lemma nsmul (hxy : x ≡ y [SMOD U]) (n : ℕ) : n • x ≡ n • y [SMOD U] := by
rw [SModEq.def] at hxy ⊢
simp_rw [Quotient.mk_smul, hxy]
lemma zsmul (hxy : x ≡ y [SMOD U]) (n : ℤ) : n • x ≡ n • y [SMOD U] := by
rw [SModEq.def] at hxy ⊢
simp_rw [Quotient.mk_smul, hxy]
theorem mul {I : Ideal A} {x₁ x₂ y₁ y₂ : A} (hxy₁ : x₁ ≡ y₁ [SMOD I])
(hxy₂ : x₂ ≡ y₂ [SMOD I]) : x₁ * x₂ ≡ y₁ * y₂ [SMOD I] := by
simp only [SModEq.def, Ideal.Quotient.mk_eq_mk, map_mul] at hxy₁ hxy₂ ⊢
rw [hxy₁, hxy₂]
lemma pow {I : Ideal A} {x y : A} (n : ℕ) (hxy : x ≡ y [SMOD I]) :
x ^ n ≡ y ^ n [SMOD I] := by
simp only [SModEq.def, Ideal.Quotient.mk_eq_mk, map_pow] at hxy ⊢
rw [hxy]
lemma neg (hxy : x ≡ y [SMOD U]) : - x ≡ - y [SMOD U] := by
simpa only [SModEq.def, Quotient.mk_neg, neg_inj]
lemma sub (hxy₁ : x₁ ≡ y₁ [SMOD U]) (hxy₂ : x₂ ≡ y₂ [SMOD U]) : x₁ - x₂ ≡ y₁ - y₂ [SMOD U] := by
rw [SModEq.def] at hxy₁ hxy₂ ⊢
simp_rw [Quotient.mk_sub, hxy₁, hxy₂]
theorem zero : x ≡ 0 [SMOD U] ↔ x ∈ U := by rw [SModEq.def, Submodule.Quotient.eq, sub_zero]
theorem map (hxy : x ≡ y [SMOD U]) (f : M →ₗ[R] N) : f x ≡ f y [SMOD U.map f] :=
(Submodule.Quotient.eq _).2 <| f.map_sub x y ▸ mem_map_of_mem <| (Submodule.Quotient.eq _).1 hxy
theorem comap {f : M →ₗ[R] N} (hxy : f x ≡ f y [SMOD V]) : x ≡ y [SMOD V.comap f] :=
(Submodule.Quotient.eq _).2 <|
show f (x - y) ∈ V from (f.map_sub x y).symm ▸ (Submodule.Quotient.eq _).1 hxy
theorem eval {R : Type*} [CommRing R] {I : Ideal R} {x y : R} (h : x ≡ y [SMOD I]) (f : R[X]) :
f.eval x ≡ f.eval y [SMOD I] := by
rw [SModEq.def] at h ⊢
show Ideal.Quotient.mk I (f.eval x) = Ideal.Quotient.mk I (f.eval y)
replace h : Ideal.Quotient.mk I x = Ideal.Quotient.mk I y := h
rw [← Polynomial.eval₂_at_apply, ← Polynomial.eval₂_at_apply, h]
end SModEq
|
LinearAlgebra\Span.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
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.Ring.Idempotents
import Mathlib.Data.Set.Pointwise.SMul
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`.
## Notations
* 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₂]
section
variable (R)
/-- 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 }
variable {R}
-- Porting note: renamed field to `principal'` and added `principal` to fix explicit argument
/-- 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' : ∃ a, S = span R {a}
theorem IsPrincipal.principal (S : Submodule R M) [S.IsPrincipal] :
∃ a, S = span R {a} :=
Submodule.IsPrincipal.principal'
end
variable {s t : Set M}
theorem mem_span : x ∈ span R s ↔ ∀ p : Submodule R M, s ⊆ p → x ∈ p :=
mem_iInter₂
@[aesop safe 20 apply (rule_sets := [SetLike])]
theorem subset_span : s ⊆ span R s := fun _ h => mem_span.2 fun _ hp => hp h
theorem span_le {p} : span R s ≤ p ↔ s ⊆ p :=
⟨Subset.trans subset_span, fun ss _ h => mem_span.1 h _ ss⟩
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
/-- 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)
/-- 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)
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_subset f 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
@[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⟩
-- See also `span_preimage_eq` below.
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
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 : M → Prop} (h : x ∈ span R s) (mem : ∀ x ∈ s, p x) (zero : p 0)
(add : ∀ x y, p x → p y → p (x + y)) (smul : ∀ (a : R) (x), p x → p (a • x)) : p x :=
((@span_le (p := ⟨⟨⟨p, by intros x y; exact add x y⟩, zero⟩, smul⟩)) s).2 mem h
/-- An induction principle for span membership. This is a version of `Submodule.span_induction`
for binary predicates. -/
theorem span_induction₂ {p : M → M → Prop} {a b : M} (ha : a ∈ Submodule.span R s)
(hb : b ∈ Submodule.span R s) (mem_mem : ∀ x ∈ s, ∀ y ∈ s, p x y)
(zero_left : ∀ y, p 0 y) (zero_right : ∀ x, p x 0)
(add_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y)
(add_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂))
(smul_left : ∀ (r : R) x y, p x y → p (r • x) y)
(smul_right : ∀ (r : R) x y, p x y → p x (r • y)) : p a b :=
Submodule.span_induction ha
(fun x hx => Submodule.span_induction hb (mem_mem x hx) (zero_right x) (add_right x) fun r =>
smul_right r x)
(zero_left b) (fun x₁ x₂ => add_left x₁ x₂ b) fun r x => smul_left r x b
/-- A dependent version of `Submodule.span_induction`. -/
@[elab_as_elim]
theorem span_induction' {p : ∀ x, x ∈ span R s → Prop}
(mem : ∀ (x) (h : x ∈ s), p x (subset_span h))
(zero : p 0 (Submodule.zero_mem _))
(add : ∀ x hx y 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
refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) => hc
refine
span_induction hx (fun m hm => ⟨subset_span hm, mem m hm⟩) ⟨zero_mem _, zero⟩
(fun x y hx hy =>
Exists.elim hx fun hx' hx =>
Exists.elim hy fun hy' hy => ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩)
fun r x hx => Exists.elim hx fun hx' hx => ⟨smul_mem _ _ hx', smul r _ _ hx⟩
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 ↦ span_induction hx (fun x hx ↦ subset_closure ⟨1, trivial, x, hx, one_smul R x⟩)
(zero_mem _) (fun _ _ ↦ add_mem) fun r m hm ↦ closure_induction hm ?_ ?_ fun _ _ h h' ↦ ?_)
(closure_le.2 ?_)
· rintro _ ⟨r, -, m, hm, rfl⟩; exact smul_mem _ _ (subset_span hm)
· rintro _ ⟨r', -, m, hm, rfl⟩; exact subset_closure ⟨r * r', trivial, m, hm, mul_smul r r' m⟩
· rw [smul_zero]; apply zero_mem
· rw [smul_add]; exact add_mem h h'
/-- 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 : M → Prop} (h : x ∈ span R s) (zero : p 0)
(add : ∀ x y, p x → p y → p (x + y)) (smul_mem : ∀ r : R, ∀ x ∈ s, p (r • x)) : p x := by
rw [← mem_toAddSubmonoid, span_eq_closure] at h
refine AddSubmonoid.closure_induction h ?_ zero add
rintro _ ⟨r, -, m, hm, rfl⟩
exact smul_mem r m hm
/-- A dependent version of `Submodule.closure_induction`. -/
@[elab_as_elim]
theorem closure_induction' {p : ∀ x, x ∈ span R s → Prop}
(zero : p 0 (Submodule.zero_mem _))
(add : ∀ x hx y 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
refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) ↦ hc
refine closure_induction hx ⟨zero_mem _, zero⟩
(fun x y hx hy ↦ Exists.elim hx fun hx' hx ↦
Exists.elim hy fun hy' hy ↦ ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩)
fun r x hx ↦ ⟨Submodule.smul_mem _ _ (subset_span hx), 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 x hx _ ↦ by
refine span_induction' (p := fun x hx ↦ (⟨x, hx⟩ : span R s) ∈ span R (Subtype.val ⁻¹' s))
(fun x' hx' ↦ subset_span hx') ?_ (fun x _ y _ ↦ ?_) (fun r x _ ↦ ?_) hx
· exact zero_mem _
· exact add_mem
· exact smul_mem _ _
@[simp]
lemma span_setOf_mem_eq_top :
span R {x : span R s | (x : M) ∈ s} = ⊤ :=
span_span_coe_preimage
theorem span_nat_eq_addSubmonoid_closure (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
@[simp]
theorem span_nat_eq (s : AddSubmonoid M) : (span ℕ (s : Set M)).toAddSubmonoid = s := by
rw [span_nat_eq_addSubmonoid_closure, s.closure_eq]
theorem span_int_eq_addSubgroup_closure {M : Type*} [AddCommGroup M] (s : Set M) :
(span ℤ s).toAddSubgroup = AddSubgroup.closure s :=
Eq.symm <|
AddSubgroup.closure_eq_of_le _ subset_span fun x hx =>
span_induction hx (fun x hx => AddSubgroup.subset_closure hx) (AddSubgroup.zero_mem _)
(fun _ _ => AddSubgroup.add_mem _) fun _ _ _ => AddSubgroup.zsmul_mem _ ‹_› _
@[simp]
theorem span_int_eq {M : Type*} [AddCommGroup M] (s : AddSubgroup M) :
(span ℤ (s : Set M)).toAddSubgroup = s := by rw [span_int_eq_addSubgroup_closure, s.closure_eq]
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
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
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
/-- 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)
rw [smul_smul]
erw [hr.unit.inv_val]
rw [one_smul]
@[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, Subtype.coe_mk,
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
/-- 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.Continuous' ((↑) : Submodule R M → Set M) :=
⟨SetLike.coe_mono, coe_iSup_of_chain⟩
@[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]
lemma exists_add_eq_of_codisjoint (h : Codisjoint p p') (x : M) :
∃ y ∈ p, ∃ z ∈ p', y + z = x := by
suffices x ∈ p ⊔ p' by exact Submodule.mem_sup.mp this
simpa only [h.eq_top] using Submodule.mem_top
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_toAddSubgroup {R M : Type*} [Ring R] [AddCommGroup M] [Module R M]
(p p' : Submodule R M) : (p ⊔ p').toAddSubgroup = p.toAddSubgroup ⊔ p'.toAddSubgroup := by
ext x
rw [mem_toAddSubgroup, mem_sup, AddSubgroup.mem_sup]
rfl
end
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} [Monoid S] [SMul S R] [MulAction 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 disjoint_span_singleton {K E : Type*} [DivisionRing K] [AddCommGroup E] [Module K E]
{s : Submodule K E} {x : E} : Disjoint s (K ∙ x) ↔ x ∈ s → x = 0 := by
refine disjoint_def.trans ⟨fun H hx => H x hx <| subset_span <| mem_singleton x, ?_⟩
intro H y hy hyx
obtain ⟨c, rfl⟩ := mem_span_singleton.1 hyx
by_cases hc : c = 0
· rw [hc, zero_smul]
· rw [s.smul_mem_iff hc] at hy
rw [H hy, smul_zero]
theorem disjoint_span_singleton' {K E : Type*} [DivisionRing K] [AddCommGroup E] [Module K E]
{p : Submodule K E} {x : E} (x0 : x ≠ 0) : Disjoint p (K ∙ x) ↔ x ∉ p :=
disjoint_span_singleton.trans ⟨fun h₁ h₂ => x0 (h₁ h₂), fun h₁ h₂ => (h₁ h₂).elim⟩
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]
variable (R S s)
/-- If `R` is "smaller" ring than `S` then the span by `R` is smaller than the span by `S`. -/
theorem span_le_restrictScalars [Semiring S] [SMul R S] [Module S M] [IsScalarTower R S M] :
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 [Semiring S] [SMul R S] [Module S M] [IsScalarTower R S M] :
↑(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. -/
theorem span_span_of_tower [Semiring S] [SMul R S] [Module S M] [IsScalarTower R S M] :
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)
variable {R S s}
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⟩
@[simp]
theorem span_singleton_eq_bot : (R ∙ x) = ⊥ ↔ x = 0 :=
span_eq_bot.trans <| 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 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 `lean4#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 `lean4#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 not_mem_span_of_apply_not_mem_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)
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_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 hx (fun x hx => ?_) ?_ (fun x y hx hy => ?_) fun r x 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) {C : M → Prop} {x : M}
(hx : x ∈ ⨆ i, p i) (hp : ∀ (i), ∀ x ∈ p i, C x) (h0 : C 0)
(hadd : ∀ x y, C x → C y → C (x + y)) : C x := by
rw [← mem_toAddSubmonoid, iSup_toAddSubmonoid] at hx
exact AddSubmonoid.iSup_induction (x := x) _ hx hp h0 hadd
/-- A dependent version of `submodule.iSup_induction`. -/
@[elab_as_elim]
theorem iSup_induction' {ι : Sort*} (p : ι → Submodule R M) {C : ∀ x, (x ∈ ⨆ i, p i) → Prop}
(mem : ∀ (i) (x) (hx : x ∈ p i), C x (mem_iSup_of_mem i hx)) (zero : C 0 (zero_mem _))
(add : ∀ x y hx hy, C x hx → C y hy → C (x + y) (add_mem ‹_› ‹_›)) {x : M}
(hx : x ∈ ⨆ i, p i) : C x hx := by
refine Exists.elim ?_ fun (hx : x ∈ ⨆ i, p i) (hc : C x hx) => hc
refine iSup_induction p (C := fun x : M ↦ ∃ (hx : x ∈ ⨆ i, p i), C 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]⟩⟩⟩
/-- 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_not_mem {I : Submodule R M} {a : M} : (I < I ⊔ R ∙ a) ↔ a ∉ I := by simp
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 hx (fun x 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⟩
end
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 [Prod.zero_eq_mk]
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 [SetLike.le_def]; 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⟩
end AddCommMonoid
section AddCommGroup
variable [Ring R] [AddCommGroup M] [Module R M]
@[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
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, add_left_comm]⟩
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 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]
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
@[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
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_sujective hf, hp, comap_top]
lemma biSup_comap_eq_top_of_range_eq_biSup
{R R₂ : Type*} [Ring 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 DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V]
/-- There is no vector subspace between `p` and `(K ∙ x) ⊔ p`, `WCovBy` version. -/
theorem wcovBy_span_singleton_sup (x : V) (p : Submodule K V) : WCovBy p ((K ∙ x) ⊔ p) := by
refine ⟨le_sup_right, fun q hpq hqp ↦ hqp.not_le ?_⟩
rcases SetLike.exists_of_lt hpq with ⟨y, hyq, hyp⟩
obtain ⟨c, z, hz, rfl⟩ : ∃ c : K, ∃ z ∈ p, 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 `p` and `(K ∙ x) ⊔ p`, `CovBy` version. -/
theorem covBy_span_singleton_sup {x : V} {p : Submodule K V} (h : x ∉ p) : CovBy p ((K ∙ x) ⊔ p) :=
⟨by simpa, (wcovBy_span_singleton_sup _ _).2⟩
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
/-- The range of `toSpanSingleton x` is the span of `x`. -/
theorem span_singleton_eq_range (x : M) : (R ∙ x) = range (toSpanSingleton R M x) :=
Submodule.ext fun y => by
refine Iff.trans ?_ LinearMap.mem_range.symm
exact mem_span_singleton
-- @[simp] -- Porting note (#10618): simp can prove this
theorem toSpanSingleton_one (x : M) : toSpanSingleton R M x 1 = x :=
one_smul _ _
@[simp]
theorem toSpanSingleton_zero : toSpanSingleton R M 0 = 0 := by
ext
simp
variable {R M}
theorem toSpanSingleton_isIdempotentElem_iff {e : R} :
IsIdempotentElem (toSpanSingleton R R e) ↔ IsIdempotentElem e := by
simp_rw [IsIdempotentElem, LinearMap.ext_iff, 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 [mul_apply]
exact ⟨fun h r ↦ by rw [← mul_one r, ← smul_eq_mul, map_smul, map_smul, h], (· 1)⟩
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₂]
/-- 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) (span_singleton_eq_range R M x).symm)
@[simp] theorem toSpanNonzeroSingleton_apply (t : R) :
LinearEquiv.toSpanNonzeroSingleton R M x h t =
(⟨t • x, Submodule.smul_mem _ _ (Submodule.mem_span_singleton_self x)⟩ : R ∙ x) := by
rfl
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
|
LinearAlgebra\StdBasis.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Matrix.Basis
import Mathlib.LinearAlgebra.Basis
import Mathlib.LinearAlgebra.Pi
/-!
# The standard basis
This file defines the standard basis `Pi.basis (s : ∀ j, Basis (ι j) R (M j))`,
which is the `Σ j, ι j`-indexed basis of `Π j, M j`. The basis vectors are given by
`Pi.basis s ⟨j, i⟩ j' = LinearMap.stdBasis R M j' (s j) i = if j = j' then s i else 0`.
The standard basis on `R^η`, i.e. `η → R` is called `Pi.basisFun`.
To give a concrete example, `LinearMap.stdBasis R (fun (i : Fin 3) ↦ R) i 1`
gives the `i`th unit basis vector in `R³`, and `Pi.basisFun R (Fin 3)` proves
this is a basis over `Fin 3 → R`.
## Main definitions
- `LinearMap.stdBasis R M`: if `x` is a basis vector of `M i`, then
`LinearMap.stdBasis R M i x` is the `i`th standard basis vector of `Π i, M i`.
- `Pi.basis s`: given a basis `s i` for each `M i`, the standard basis on `Π i, M i`
- `Pi.basisFun R η`: the standard basis on `R^η`, i.e. `η → R`, given by
`Pi.basisFun R η i j = if i = j then 1 else 0`.
- `Matrix.stdBasis R n m`: the standard basis on `Matrix n m R`, given by
`Matrix.stdBasis R n m (i, j) i' j' = if (i, j) = (i', j') then 1 else 0`.
-/
open Function Set Submodule
namespace LinearMap
variable (R : Type*) {ι : Type*} [Semiring R] (φ : ι → Type*) [∀ i, AddCommMonoid (φ i)]
[∀ i, Module R (φ i)] [DecidableEq ι]
/-- The standard basis of the product of `φ`. -/
def stdBasis : ∀ i : ι, φ i →ₗ[R] ∀ i, φ i :=
single
theorem stdBasis_apply (i : ι) (b : φ i) : stdBasis R φ i b = update (0 : (a : ι) → φ a) i b :=
rfl
@[simp]
theorem stdBasis_apply' (i i' : ι) : (stdBasis R (fun _x : ι => R) i) 1 i' = ite (i = i') 1 0 := by
rw [LinearMap.stdBasis_apply, Function.update_apply, Pi.zero_apply]
congr 1; rw [eq_iff_iff, eq_comm]
theorem coe_stdBasis (i : ι) : ⇑(stdBasis R φ i) = Pi.single i :=
rfl
@[simp]
theorem stdBasis_same (i : ι) (b : φ i) : stdBasis R φ i b i = b :=
Pi.single_eq_same i b
theorem stdBasis_ne (i j : ι) (h : j ≠ i) (b : φ i) : stdBasis R φ i b j = 0 :=
Pi.single_eq_of_ne h b
theorem stdBasis_eq_pi_diag (i : ι) : stdBasis R φ i = pi (diag i) := by
ext x j
-- Porting note: made types explicit
convert (update_apply (R := R) (φ := φ) (ι := ι) 0 x i j _).symm
rfl
theorem ker_stdBasis (i : ι) : ker (stdBasis R φ i) = ⊥ :=
ker_eq_bot_of_injective <| Pi.single_injective _ _
theorem proj_comp_stdBasis (i j : ι) : (proj i).comp (stdBasis R φ j) = diag j i := by
rw [stdBasis_eq_pi_diag, proj_pi]
theorem proj_stdBasis_same (i : ι) : (proj i).comp (stdBasis R φ i) = id :=
LinearMap.ext <| stdBasis_same R φ i
theorem proj_stdBasis_ne (i j : ι) (h : i ≠ j) : (proj i).comp (stdBasis R φ j) = 0 :=
LinearMap.ext <| stdBasis_ne R φ _ _ h
theorem iSup_range_stdBasis_le_iInf_ker_proj (I J : Set ι) (h : Disjoint I J) :
⨆ i ∈ I, range (stdBasis R φ i) ≤ ⨅ i ∈ J, ker (proj i : (∀ i, φ i) →ₗ[R] φ i) := by
refine iSup_le fun i => iSup_le fun hi => range_le_iff_comap.2 ?_
simp only [← ker_comp, eq_top_iff, SetLike.le_def, mem_ker, comap_iInf, mem_iInf]
rintro b - j hj
rw [proj_stdBasis_ne R φ j i, zero_apply]
rintro rfl
exact h.le_bot ⟨hi, hj⟩
theorem iInf_ker_proj_le_iSup_range_stdBasis {I : Finset ι} {J : Set ι} (hu : Set.univ ⊆ ↑I ∪ J) :
⨅ i ∈ J, ker (proj i : (∀ i, φ i) →ₗ[R] φ i) ≤ ⨆ i ∈ I, range (stdBasis R φ i) :=
SetLike.le_def.2
(by
intro b hb
simp only [mem_iInf, mem_ker, proj_apply] at hb
rw [←
show (∑ i ∈ I, stdBasis R φ i (b i)) = b by
ext i
rw [Finset.sum_apply, ← stdBasis_same R φ i (b i)]
refine Finset.sum_eq_single i (fun j _ ne => stdBasis_ne _ _ _ _ ne.symm _) ?_
intro hiI
rw [stdBasis_same]
exact hb _ ((hu trivial).resolve_left hiI)]
exact sum_mem_biSup fun i _ => mem_range_self (stdBasis R φ i) (b i))
theorem iSup_range_stdBasis_eq_iInf_ker_proj {I J : Set ι} (hd : Disjoint I J)
(hu : Set.univ ⊆ I ∪ J) (hI : Set.Finite I) :
⨆ i ∈ I, range (stdBasis R φ i) = ⨅ i ∈ J, ker (proj i : (∀ i, φ i) →ₗ[R] φ i) := by
refine le_antisymm (iSup_range_stdBasis_le_iInf_ker_proj _ _ _ _ hd) ?_
have : Set.univ ⊆ ↑hI.toFinset ∪ J := by rwa [hI.coe_toFinset]
refine le_trans (iInf_ker_proj_le_iSup_range_stdBasis R φ this) (iSup_mono fun i => ?_)
rw [Set.Finite.mem_toFinset]
theorem iSup_range_stdBasis [Finite ι] : ⨆ i, range (stdBasis R φ i) = ⊤ := by
cases nonempty_fintype ι
convert top_unique (iInf_emptyset.ge.trans <| iInf_ker_proj_le_iSup_range_stdBasis R φ _)
· rename_i i
exact ((@iSup_pos _ _ _ fun _ => range <| stdBasis R φ i) <| Finset.mem_univ i).symm
· rw [Finset.coe_univ, Set.union_empty]
theorem disjoint_stdBasis_stdBasis (I J : Set ι) (h : Disjoint I J) :
Disjoint (⨆ i ∈ I, range (stdBasis R φ i)) (⨆ i ∈ J, range (stdBasis R φ i)) := by
refine
Disjoint.mono (iSup_range_stdBasis_le_iInf_ker_proj _ _ _ _ <| disjoint_compl_right)
(iSup_range_stdBasis_le_iInf_ker_proj _ _ _ _ <| disjoint_compl_right) ?_
simp only [disjoint_iff_inf_le, SetLike.le_def, mem_iInf, mem_inf, mem_ker, mem_bot, proj_apply,
funext_iff]
rintro b ⟨hI, hJ⟩ i
classical
by_cases hiI : i ∈ I
· by_cases hiJ : i ∈ J
· exact (h.le_bot ⟨hiI, hiJ⟩).elim
· exact hJ i hiJ
· exact hI i hiI
theorem stdBasis_eq_single {a : R} :
(fun i : ι => (stdBasis R (fun _ : ι => R) i) a) = fun i : ι => ↑(Finsupp.single i a) :=
funext fun i => (Finsupp.single_eq_pi_single i a).symm
end LinearMap
namespace Pi
open LinearMap
open Set
variable {R : Type*}
section Module
variable {η : Type*} {ιs : η → Type*} {Ms : η → Type*}
theorem linearIndependent_stdBasis [Ring R] [∀ i, AddCommGroup (Ms i)] [∀ i, Module R (Ms i)]
[DecidableEq η] (v : ∀ j, ιs j → Ms j) (hs : ∀ i, LinearIndependent R (v i)) :
LinearIndependent R fun ji : Σj, ιs j => stdBasis R Ms ji.1 (v ji.1 ji.2) := by
have hs' : ∀ j : η, LinearIndependent R fun i : ιs j => stdBasis R Ms j (v j i) := by
intro j
exact (hs j).map' _ (ker_stdBasis _ _ _)
apply linearIndependent_iUnion_finite hs'
intro j J _ hiJ
have h₀ :
∀ j, span R (range fun i : ιs j => stdBasis R Ms j (v j i)) ≤
LinearMap.range (stdBasis R Ms j) := by
intro j
rw [span_le, LinearMap.range_coe]
apply range_comp_subset_range
have h₁ :
span R (range fun i : ιs j => stdBasis R Ms j (v j i)) ≤
⨆ i ∈ ({j} : Set _), LinearMap.range (stdBasis R Ms i) := by
rw [@iSup_singleton _ _ _ fun i => LinearMap.range (stdBasis R (Ms) i)]
apply h₀
have h₂ :
⨆ j ∈ J, span R (range fun i : ιs j => stdBasis R Ms j (v j i)) ≤
⨆ j ∈ J, LinearMap.range (stdBasis R (fun j : η => Ms j) j) :=
iSup₂_mono fun i _ => h₀ i
have h₃ : Disjoint (fun i : η => i ∈ ({j} : Set _)) J := by
convert Set.disjoint_singleton_left.2 hiJ using 0
exact (disjoint_stdBasis_stdBasis _ _ _ _ h₃).mono h₁ h₂
variable [Semiring R] [∀ i, AddCommMonoid (Ms i)] [∀ i, Module R (Ms i)]
section Fintype
variable [Fintype η]
open LinearEquiv
/-- `Pi.basis (s : ∀ j, Basis (ιs j) R (Ms j))` is the `Σ j, ιs j`-indexed basis on `Π j, Ms j`
given by `s j` on each component.
For the standard basis over `R` on the finite-dimensional space `η → R` see `Pi.basisFun`.
-/
protected noncomputable def basis (s : ∀ j, Basis (ιs j) R (Ms j)) :
Basis (Σj, ιs j) R (∀ j, Ms j) :=
Basis.ofRepr
((LinearEquiv.piCongrRight fun j => (s j).repr) ≪≫ₗ
(Finsupp.sigmaFinsuppLEquivPiFinsupp R).symm)
-- Porting note: was
-- -- The `AddCommMonoid (Π j, Ms j)` instance was hard to find.
-- -- Defining this in tactic mode seems to shake up instance search enough
-- -- that it works by itself.
-- refine Basis.ofRepr (?_ ≪≫ₗ (Finsupp.sigmaFinsuppLEquivPiFinsupp R).symm)
-- exact LinearEquiv.piCongrRight fun j => (s j).repr
@[simp]
theorem basis_repr_stdBasis [DecidableEq η] (s : ∀ j, Basis (ιs j) R (Ms j)) (j i) :
(Pi.basis s).repr (stdBasis R _ j (s j i)) = Finsupp.single ⟨j, i⟩ 1 := by
ext ⟨j', i'⟩
by_cases hj : j = j'
· subst hj
-- Porting note: needed to add more lemmas
simp only [Pi.basis, LinearEquiv.trans_apply, Basis.repr_self, stdBasis_same,
LinearEquiv.piCongrRight, Finsupp.sigmaFinsuppLEquivPiFinsupp_symm_apply,
Basis.repr_symm_apply, LinearEquiv.coe_mk, ne_eq, Sigma.mk.inj_iff, heq_eq_eq, true_and]
symm
-- Porting note: `Sigma.mk.inj` not found in the following, replaced by `Sigma.mk.inj_iff.mp`
exact
Finsupp.single_apply_left
(fun i i' (h : (⟨j, i⟩ : Σj, ιs j) = ⟨j, i'⟩) => eq_of_heq (Sigma.mk.inj_iff.mp h).2) _ _ _
simp only [Pi.basis, LinearEquiv.trans_apply, Finsupp.sigmaFinsuppLEquivPiFinsupp_symm_apply,
LinearEquiv.piCongrRight]
dsimp
rw [stdBasis_ne _ _ _ _ (Ne.symm hj), LinearEquiv.map_zero, Finsupp.zero_apply,
Finsupp.single_eq_of_ne]
rintro ⟨⟩
contradiction
@[simp]
theorem basis_apply [DecidableEq η] (s : ∀ j, Basis (ιs j) R (Ms j)) (ji) :
Pi.basis s ji = stdBasis R _ ji.1 (s ji.1 ji.2) :=
Basis.apply_eq_iff.mpr (by simp)
@[simp]
theorem basis_repr (s : ∀ j, Basis (ιs j) R (Ms j)) (x) (ji) :
(Pi.basis s).repr x ji = (s ji.1).repr (x ji.1) ji.2 :=
rfl
end Fintype
section
variable [Finite η]
variable (R η)
/-- The basis on `η → R` where the `i`th basis vector is `Function.update 0 i 1`. -/
noncomputable def basisFun : Basis η R (η → R) :=
Basis.ofEquivFun (LinearEquiv.refl _ _)
@[simp]
theorem basisFun_apply [DecidableEq η] (i) : basisFun R η i = stdBasis R (fun _ : η => R) i 1 := by
simp only [basisFun, Basis.coe_ofEquivFun, LinearEquiv.refl_symm, LinearEquiv.refl_apply,
stdBasis_apply]
@[simp]
theorem basisFun_repr (x : η → R) (i : η) : (Pi.basisFun R η).repr x i = x i := by simp [basisFun]
@[simp]
theorem basisFun_equivFun : (Pi.basisFun R η).equivFun = LinearEquiv.refl _ _ :=
Basis.equivFun_ofEquivFun _
end
end Module
end Pi
namespace Module
variable (ι R M N : Type*) [Finite ι] [CommSemiring R]
[AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N]
/-- The natural linear equivalence: `Mⁱ ≃ Hom(Rⁱ, M)` for an `R`-module `M`. -/
noncomputable def piEquiv : (ι → M) ≃ₗ[R] ((ι → R) →ₗ[R] M) := Basis.constr (Pi.basisFun R ι) R
lemma piEquiv_apply_apply (ι R M : Type*) [Fintype ι] [CommSemiring R]
[AddCommMonoid M] [Module R M] (v : ι → M) (w : ι → R) :
piEquiv ι R M v w = ∑ i, w i • v i := by
simp only [piEquiv, Basis.constr_apply_fintype, Basis.equivFun_apply]
congr
@[simp] lemma range_piEquiv (v : ι → M) :
LinearMap.range (piEquiv ι R M v) = span R (range v) :=
Basis.constr_range _ _
@[simp] lemma surjective_piEquiv_apply_iff (v : ι → M) :
Surjective (piEquiv ι R M v) ↔ span R (range v) = ⊤ := by
rw [← LinearMap.range_eq_top, range_piEquiv]
end Module
namespace Matrix
variable (R : Type*) (m n : Type*) [Fintype m] [Finite n] [Semiring R]
/-- The standard basis of `Matrix m n R`. -/
noncomputable def stdBasis : Basis (m × n) R (Matrix m n R) :=
Basis.reindex (Pi.basis fun _ : m => Pi.basisFun R n) (Equiv.sigmaEquivProd _ _)
variable {n m}
theorem stdBasis_eq_stdBasisMatrix (i : m) (j : n) [DecidableEq m] [DecidableEq n] :
stdBasis R m n (i, j) = stdBasisMatrix i j (1 : R) := by
-- Porting note: `simp` fails to apply `Pi.basis_apply`
ext a b
by_cases hi : i = a <;> by_cases hj : j = b
· simp [stdBasis, hi, hj, Basis.coe_reindex, comp_apply, Equiv.sigmaEquivProd_symm_apply,
StdBasisMatrix.apply_same]
erw [Pi.basis_apply]
simp
· simp only [stdBasis, hi, Basis.coe_reindex, comp_apply, Equiv.sigmaEquivProd_symm_apply,
hj, and_false, not_false_iff, StdBasisMatrix.apply_of_ne]
erw [Pi.basis_apply]
simp [hj]
· simp only [stdBasis, hj, Basis.coe_reindex, comp_apply, Equiv.sigmaEquivProd_symm_apply,
hi, and_true, not_false_iff, StdBasisMatrix.apply_of_ne]
erw [Pi.basis_apply]
simp [hi, hj, Ne.symm hi, LinearMap.stdBasis_ne]
· simp only [stdBasis, Basis.coe_reindex, comp_apply, Equiv.sigmaEquivProd_symm_apply,
hi, hj, and_self, not_false_iff, StdBasisMatrix.apply_of_ne]
erw [Pi.basis_apply]
simp [hi, hj, Ne.symm hj, Ne.symm hi, LinearMap.stdBasis_ne]
end Matrix
|
LinearAlgebra\SymplecticGroup.lean | /-
Copyright (c) 2022 Matej Penciak. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Matej Penciak, Moritz Doll, Fabien Clery
-/
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
/-!
# The Symplectic Group
This file defines the symplectic group and proves elementary properties.
## Main Definitions
* `Matrix.J`: the canonical `2n × 2n` skew-symmetric matrix
* `symplecticGroup`: the group of symplectic matrices
## TODO
* Every symplectic matrix has determinant 1.
* For `n = 1` the symplectic group coincides with the special linear group.
-/
open Matrix
variable {l R : Type*}
namespace Matrix
variable (l) [DecidableEq l] (R) [CommRing R]
section JMatrixLemmas
/-- The matrix defining the canonical skew-symmetric bilinear form. -/
def J : Matrix (l ⊕ l) (l ⊕ l) R :=
Matrix.fromBlocks 0 (-1) 1 0
@[simp]
theorem J_transpose : (J l R)ᵀ = -J l R := by
rw [J, fromBlocks_transpose, ← neg_one_smul R (fromBlocks _ _ _ _ : Matrix (l ⊕ l) (l ⊕ l) R),
fromBlocks_smul, Matrix.transpose_zero, Matrix.transpose_one, transpose_neg]
simp [fromBlocks]
variable [Fintype l]
theorem J_squared : J l R * J l R = -1 := by
rw [J, fromBlocks_multiply]
simp only [Matrix.zero_mul, Matrix.neg_mul, zero_add, neg_zero, Matrix.one_mul, add_zero]
rw [← neg_zero, ← Matrix.fromBlocks_neg, ← fromBlocks_one]
theorem J_inv : (J l R)⁻¹ = -J l R := by
refine Matrix.inv_eq_right_inv ?_
rw [Matrix.mul_neg, J_squared]
exact neg_neg 1
theorem J_det_mul_J_det : det (J l R) * det (J l R) = 1 := by
rw [← det_mul, J_squared, ← one_smul R (-1 : Matrix _ _ R), smul_neg, ← neg_smul, det_smul,
Fintype.card_sum, det_one, mul_one]
apply Even.neg_one_pow
exact even_add_self _
theorem isUnit_det_J : IsUnit (det (J l R)) :=
isUnit_iff_exists_inv.mpr ⟨det (J l R), J_det_mul_J_det _ _⟩
end JMatrixLemmas
variable [Fintype l]
/-- The group of symplectic matrices over a ring `R`. -/
def symplecticGroup : Submonoid (Matrix (l ⊕ l) (l ⊕ l) R) where
carrier := { A | A * J l R * Aᵀ = J l R }
mul_mem' {a b} ha hb := by
simp only [Set.mem_setOf_eq, transpose_mul] at *
rw [← Matrix.mul_assoc, a.mul_assoc, a.mul_assoc, hb]
exact ha
one_mem' := by simp
end Matrix
namespace SymplecticGroup
variable [DecidableEq l] [Fintype l] [CommRing R]
open Matrix
theorem mem_iff {A : Matrix (l ⊕ l) (l ⊕ l) R} :
A ∈ symplecticGroup l R ↔ A * J l R * Aᵀ = J l R := by simp [symplecticGroup]
-- Porting note: Previous proof was `by infer_instance`
instance coeMatrix : Coe (symplecticGroup l R) (Matrix (l ⊕ l) (l ⊕ l) R) :=
⟨Subtype.val⟩
section SymplecticJ
variable (l) (R)
theorem J_mem : J l R ∈ symplecticGroup l R := by
rw [mem_iff, J, fromBlocks_multiply, fromBlocks_transpose, fromBlocks_multiply]
simp
/-- The canonical skew-symmetric matrix as an element in the symplectic group. -/
def symJ : symplecticGroup l R :=
⟨J l R, J_mem l R⟩
variable {l} {R}
@[simp]
theorem coe_J : ↑(symJ l R) = J l R := rfl
end SymplecticJ
variable {A : Matrix (l ⊕ l) (l ⊕ l) R}
theorem neg_mem (h : A ∈ symplecticGroup l R) : -A ∈ symplecticGroup l R := by
rw [mem_iff] at h ⊢
simp [h]
theorem symplectic_det (hA : A ∈ symplecticGroup l R) : IsUnit <| det A := by
rw [isUnit_iff_exists_inv]
use A.det
refine (isUnit_det_J l R).mul_left_cancel ?_
rw [mul_one]
rw [mem_iff] at hA
apply_fun det at hA
simp only [det_mul, det_transpose] at hA
rw [mul_comm A.det, mul_assoc] at hA
exact hA
theorem transpose_mem (hA : A ∈ symplecticGroup l R) : Aᵀ ∈ symplecticGroup l R := by
rw [mem_iff] at hA ⊢
rw [transpose_transpose]
have huA := symplectic_det hA
have huAT : IsUnit Aᵀ.det := by
rw [Matrix.det_transpose]
exact huA
calc
Aᵀ * J l R * A = (-Aᵀ) * (J l R)⁻¹ * A := by
rw [J_inv]
simp
_ = (-Aᵀ) * (A * J l R * Aᵀ)⁻¹ * A := by rw [hA]
_ = -(Aᵀ * (Aᵀ⁻¹ * (J l R)⁻¹)) * A⁻¹ * A := by
simp only [Matrix.mul_inv_rev, Matrix.mul_assoc, Matrix.neg_mul]
_ = -(J l R)⁻¹ := by
rw [mul_nonsing_inv_cancel_left _ _ huAT, nonsing_inv_mul_cancel_right _ _ huA]
_ = J l R := by simp [J_inv]
@[simp]
theorem transpose_mem_iff : Aᵀ ∈ symplecticGroup l R ↔ A ∈ symplecticGroup l R :=
⟨fun hA => by simpa using transpose_mem hA, transpose_mem⟩
theorem mem_iff' : A ∈ symplecticGroup l R ↔ Aᵀ * J l R * A = J l R := by
rw [← transpose_mem_iff, mem_iff, transpose_transpose]
instance hasInv : Inv (symplecticGroup l R) where
inv A := ⟨(-J l R) * (A : Matrix (l ⊕ l) (l ⊕ l) R)ᵀ * J l R,
mul_mem (mul_mem (neg_mem <| J_mem _ _) <| transpose_mem A.2) <| J_mem _ _⟩
theorem coe_inv (A : symplecticGroup l R) : (↑A⁻¹ : Matrix _ _ _) = (-J l R) * (↑A)ᵀ * J l R := rfl
theorem inv_left_mul_aux (hA : A ∈ symplecticGroup l R) : -(J l R * Aᵀ * J l R * A) = 1 :=
calc
-(J l R * Aᵀ * J l R * A) = (-J l R) * (Aᵀ * J l R * A) := by
simp only [Matrix.mul_assoc, Matrix.neg_mul]
_ = (-J l R) * J l R := by
rw [mem_iff'] at hA
rw [hA]
_ = (-1 : R) • (J l R * J l R) := by simp only [Matrix.neg_mul, neg_smul, one_smul]
_ = (-1 : R) • (-1 : Matrix _ _ _) := by rw [J_squared]
_ = 1 := by simp only [neg_smul_neg, one_smul]
theorem coe_inv' (A : symplecticGroup l R) : (↑A⁻¹ : Matrix (l ⊕ l) (l ⊕ l) R) = (↑A)⁻¹ := by
refine (coe_inv A).trans (inv_eq_left_inv ?_).symm
simp [inv_left_mul_aux, coe_inv]
theorem inv_eq_symplectic_inv (A : Matrix (l ⊕ l) (l ⊕ l) R) (hA : A ∈ symplecticGroup l R) :
A⁻¹ = (-J l R) * Aᵀ * J l R :=
inv_eq_left_inv (by simp only [Matrix.neg_mul, inv_left_mul_aux hA])
instance : Group (symplecticGroup l R) :=
{ SymplecticGroup.hasInv, Submonoid.toMonoid _ with
mul_left_inv := fun A => by
apply Subtype.ext
simp only [Submonoid.coe_one, Submonoid.coe_mul, Matrix.neg_mul, coe_inv]
exact inv_left_mul_aux A.2 }
end SymplecticGroup
|
LinearAlgebra\TensorPower.lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.PiTensorProduct
import Mathlib.Logic.Equiv.Fin
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.
-/
suppress_compilation
open scoped TensorProduct
/-- Homogenous 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)
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
variable {R}
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)) <|
(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 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 a => gradedMonoid_eq_of_cast (zero_add _) (one_mul _)
mul_one := fun a => gradedMonoid_eq_of_cast (add_zero _) (mul_one _)
mul_assoc := fun a b c => 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 a => LinearMap.map_zero _
zero_mul := fun b => LinearMap.map_zero₂ _ _
mul_add := fun a b₁ b₂ => LinearMap.map_add _ _ _
add_mul := fun a₁ a₂ b => 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
|
LinearAlgebra\Trace.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen, Antoine Labelle
-/
import Mathlib.LinearAlgebra.Contraction
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
/-!
# Trace of a linear map
This file defines the trace of a linear map.
See also `LinearAlgebra/Matrix/Trace.lean` for the trace of a matrix.
## Tags
linear_map, trace, diagonal
-/
noncomputable section
universe u v w
namespace LinearMap
open Matrix
open FiniteDimensional
open TensorProduct
section
variable (R : Type u) [CommSemiring R] {M : Type v} [AddCommMonoid M] [Module R M]
variable {ι : Type w} [DecidableEq ι] [Fintype ι]
variable {κ : Type*} [DecidableEq κ] [Fintype κ]
variable (b : Basis ι R M) (c : Basis κ R M)
/-- The trace of an endomorphism given a basis. -/
def traceAux : (M →ₗ[R] M) →ₗ[R] R :=
Matrix.traceLinearMap ι R R ∘ₗ ↑(LinearMap.toMatrix b b)
-- Can't be `simp` because it would cause a loop.
theorem traceAux_def (b : Basis ι R M) (f : M →ₗ[R] M) :
traceAux R b f = Matrix.trace (LinearMap.toMatrix b b f) :=
rfl
theorem traceAux_eq : traceAux R b = traceAux R c :=
LinearMap.ext fun f =>
calc
Matrix.trace (LinearMap.toMatrix b b f) =
Matrix.trace (LinearMap.toMatrix b b ((LinearMap.id.comp f).comp LinearMap.id)) := by
rw [LinearMap.id_comp, LinearMap.comp_id]
_ = Matrix.trace (LinearMap.toMatrix c b LinearMap.id * LinearMap.toMatrix c c f *
LinearMap.toMatrix b c LinearMap.id) := by
rw [LinearMap.toMatrix_comp _ c, LinearMap.toMatrix_comp _ c]
_ = Matrix.trace (LinearMap.toMatrix c c f * LinearMap.toMatrix b c LinearMap.id *
LinearMap.toMatrix c b LinearMap.id) := by
rw [Matrix.mul_assoc, Matrix.trace_mul_comm]
_ = Matrix.trace (LinearMap.toMatrix c c ((f.comp LinearMap.id).comp LinearMap.id)) := by
rw [LinearMap.toMatrix_comp _ b, LinearMap.toMatrix_comp _ c]
_ = Matrix.trace (LinearMap.toMatrix c c f) := by rw [LinearMap.comp_id, LinearMap.comp_id]
open scoped Classical
variable (M)
/-- Trace of an endomorphism independent of basis. -/
def trace : (M →ₗ[R] M) →ₗ[R] R :=
if H : ∃ s : Finset M, Nonempty (Basis s R M) then traceAux R H.choose_spec.some else 0
variable {M}
/-- Auxiliary lemma for `trace_eq_matrix_trace`. -/
theorem trace_eq_matrix_trace_of_finset {s : Finset M} (b : Basis s R M) (f : M →ₗ[R] M) :
trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by
have : ∃ s : Finset M, Nonempty (Basis s R M) := ⟨s, ⟨b⟩⟩
rw [trace, dif_pos this, ← traceAux_def]
congr 1
apply traceAux_eq
theorem trace_eq_matrix_trace (f : M →ₗ[R] M) :
trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by
rw [trace_eq_matrix_trace_of_finset R b.reindexFinsetRange, ← traceAux_def, ← traceAux_def,
traceAux_eq R b b.reindexFinsetRange]
theorem trace_mul_comm (f g : M →ₗ[R] M) : trace R M (f * g) = trace R M (g * f) :=
if H : ∃ s : Finset M, Nonempty (Basis s R M) then by
let ⟨s, ⟨b⟩⟩ := H
simp_rw [trace_eq_matrix_trace R b, LinearMap.toMatrix_mul]
apply Matrix.trace_mul_comm
else by rw [trace, dif_neg H, LinearMap.zero_apply, LinearMap.zero_apply]
lemma trace_mul_cycle (f g h : M →ₗ[R] M) :
trace R M (f * g * h) = trace R M (h * f * g) := by
rw [LinearMap.trace_mul_comm, ← mul_assoc]
lemma trace_mul_cycle' (f g h : M →ₗ[R] M) :
trace R M (f * (g * h)) = trace R M (h * (f * g)) := by
rw [← mul_assoc, LinearMap.trace_mul_comm]
/-- The trace of an endomorphism is invariant under conjugation -/
@[simp]
theorem trace_conj (g : M →ₗ[R] M) (f : (M →ₗ[R] M)ˣ) :
trace R M (↑f * g * ↑f⁻¹) = trace R M g := by
rw [trace_mul_comm]
simp
@[simp]
lemma trace_lie {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] (f g : Module.End R M) :
trace R M ⁅f, g⁆ = 0 := by
rw [Ring.lie_def, map_sub, trace_mul_comm]
exact sub_self _
end
section
variable {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M]
variable (N P : Type*) [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P]
variable {ι : Type*}
/-- The trace of a linear map correspond to the contraction pairing under the isomorphism
`End(M) ≃ M* ⊗ M`-/
theorem trace_eq_contract_of_basis [Finite ι] (b : Basis ι R M) :
LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M := by
classical
cases nonempty_fintype ι
apply Basis.ext (Basis.tensorProduct (Basis.dualBasis b) b)
rintro ⟨i, j⟩
simp only [Function.comp_apply, Basis.tensorProduct_apply, Basis.coe_dualBasis, coe_comp]
rw [trace_eq_matrix_trace R b, toMatrix_dualTensorHom]
by_cases hij : i = j
· rw [hij]
simp
rw [Matrix.StdBasisMatrix.trace_zero j i (1 : R) hij]
simp [Finsupp.single_eq_pi_single, hij]
/-- The trace of a linear map correspond to the contraction pairing under the isomorphism
`End(M) ≃ M* ⊗ M`-/
theorem trace_eq_contract_of_basis' [Fintype ι] [DecidableEq ι] (b : Basis ι R M) :
LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquivOfBasis b).symm.toLinearMap := by
simp [LinearEquiv.eq_comp_toLinearMap_symm, trace_eq_contract_of_basis b]
section
variable (R M)
variable [Module.Free R M] [Module.Finite R M] [Module.Free R N] [Module.Finite R N]
/-- When `M` is finite free, the trace of a linear map correspond to the contraction pairing under
the isomorphism `End(M) ≃ M* ⊗ M`-/
@[simp]
theorem trace_eq_contract : LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M :=
trace_eq_contract_of_basis (Module.Free.chooseBasis R M)
@[simp]
theorem trace_eq_contract_apply (x : Module.Dual R M ⊗[R] M) :
(LinearMap.trace R M) ((dualTensorHom R M M) x) = contractLeft R M x := by
rw [← comp_apply, trace_eq_contract]
/-- When `M` is finite free, the trace of a linear map correspond to the contraction pairing under
the isomorphism `End(M) ≃ M* ⊗ M`-/
theorem trace_eq_contract' :
LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquiv R M M).symm.toLinearMap :=
trace_eq_contract_of_basis' (Module.Free.chooseBasis R M)
/-- The trace of the identity endomorphism is the dimension of the free module -/
@[simp]
theorem trace_one : trace R M 1 = (finrank R M : R) := by
cases subsingleton_or_nontrivial R
· simp [eq_iff_true_of_subsingleton]
have b := Module.Free.chooseBasis R M
rw [trace_eq_matrix_trace R b, toMatrix_one, finrank_eq_card_chooseBasisIndex]
simp
/-- The trace of the identity endomorphism is the dimension of the free module -/
@[simp]
theorem trace_id : trace R M id = (finrank R M : R) := by rw [← one_eq_id, trace_one]
@[simp]
theorem trace_transpose : trace R (Module.Dual R M) ∘ₗ Module.Dual.transpose = trace R M := by
let e := dualTensorHomEquiv R M M
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext f m; simp [e]
theorem trace_prodMap :
trace R (M × N) ∘ₗ prodMapLinear R M N M N R =
(coprod id id : R × R →ₗ[R] R) ∘ₗ prodMap (trace R M) (trace R N) := by
let e := (dualTensorHomEquiv R M M).prod (dualTensorHomEquiv R N N)
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext
· simp only [e, dualTensorHomEquiv, LinearEquiv.coe_prod, dualTensorHomEquivOfBasis_toLinearMap,
AlgebraTensorModule.curry_apply, curry_apply, coe_restrictScalars, coe_comp, coe_inl,
Function.comp_apply, prodMap_apply, map_zero, prodMapLinear_apply, dualTensorHom_prodMap_zero,
trace_eq_contract_apply, contractLeft_apply, fst_apply, coprod_apply, id_coe, id_eq, add_zero]
· simp only [e, dualTensorHomEquiv, LinearEquiv.coe_prod, dualTensorHomEquivOfBasis_toLinearMap,
AlgebraTensorModule.curry_apply, curry_apply, coe_restrictScalars, coe_comp, coe_inr,
Function.comp_apply, prodMap_apply, map_zero, prodMapLinear_apply, zero_prodMap_dualTensorHom,
trace_eq_contract_apply, contractLeft_apply, snd_apply, coprod_apply, id_coe, id_eq, zero_add]
variable {R M N P}
theorem trace_prodMap' (f : M →ₗ[R] M) (g : N →ₗ[R] N) :
trace R (M × N) (prodMap f g) = trace R M f + trace R N g := by
have h := LinearMap.ext_iff.1 (trace_prodMap R M N) (f, g)
simp only [coe_comp, Function.comp_apply, prodMap_apply, coprod_apply, id_coe, id,
prodMapLinear_apply] at h
exact h
variable (R M N P)
open TensorProduct Function
theorem trace_tensorProduct : compr₂ (mapBilinear R M N M N) (trace R (M ⊗ N)) =
compl₁₂ (lsmul R R : R →ₗ[R] R →ₗ[R] R) (trace R M) (trace R N) := by
apply
(compl₁₂_inj (show Surjective (dualTensorHom R M M) from (dualTensorHomEquiv R M M).surjective)
(show Surjective (dualTensorHom R N N) from (dualTensorHomEquiv R N N).surjective)).1
ext f m g n
simp only [AlgebraTensorModule.curry_apply, toFun_eq_coe, TensorProduct.curry_apply,
coe_restrictScalars, compl₁₂_apply, compr₂_apply, mapBilinear_apply,
trace_eq_contract_apply, contractLeft_apply, lsmul_apply, Algebra.id.smul_eq_mul,
map_dualTensorHom, dualDistrib_apply]
theorem trace_comp_comm :
compr₂ (llcomp R M N M) (trace R M) = compr₂ (llcomp R N M N).flip (trace R N) := by
apply
(compl₁₂_inj (show Surjective (dualTensorHom R N M) from (dualTensorHomEquiv R N M).surjective)
(show Surjective (dualTensorHom R M N) from (dualTensorHomEquiv R M N).surjective)).1
ext g m f n
simp only [AlgebraTensorModule.curry_apply, TensorProduct.curry_apply,
coe_restrictScalars, compl₁₂_apply, compr₂_apply, flip_apply, llcomp_apply',
comp_dualTensorHom, LinearMapClass.map_smul, trace_eq_contract_apply,
contractLeft_apply, smul_eq_mul, mul_comm]
variable {R M N P}
@[simp]
theorem trace_transpose' (f : M →ₗ[R] M) :
trace R _ (Module.Dual.transpose (R := R) f) = trace R M f := by
rw [← comp_apply, trace_transpose]
theorem trace_tensorProduct' (f : M →ₗ[R] M) (g : N →ₗ[R] N) :
trace R (M ⊗ N) (map f g) = trace R M f * trace R N g := by
have h := LinearMap.ext_iff.1 (LinearMap.ext_iff.1 (trace_tensorProduct R M N) f) g
simp only [compr₂_apply, mapBilinear_apply, compl₁₂_apply, lsmul_apply,
Algebra.id.smul_eq_mul] at h
exact h
theorem trace_comp_comm' (f : M →ₗ[R] N) (g : N →ₗ[R] M) :
trace R M (g ∘ₗ f) = trace R N (f ∘ₗ g) := by
have h := LinearMap.ext_iff.1 (LinearMap.ext_iff.1 (trace_comp_comm R M N) g) f
simp only [llcomp_apply', compr₂_apply, flip_apply] at h
exact h
end
variable {N P}
variable [Module.Free R N] [Module.Finite R N] [Module.Free R P] [Module.Finite R P] in
lemma trace_comp_cycle (f : M →ₗ[R] N) (g : N →ₗ[R] P) (h : P →ₗ[R] M) :
trace R P (g ∘ₗ f ∘ₗ h) = trace R N (f ∘ₗ h ∘ₗ g) := by
rw [trace_comp_comm', comp_assoc]
variable [Module.Free R M] [Module.Finite R M] [Module.Free R P] [Module.Finite R P] in
lemma trace_comp_cycle' (f : M →ₗ[R] N) (g : N →ₗ[R] P) (h : P →ₗ[R] M) :
trace R P ((g ∘ₗ f) ∘ₗ h) = trace R M ((h ∘ₗ g) ∘ₗ f) := by
rw [trace_comp_comm', ← comp_assoc]
@[simp]
theorem trace_conj' (f : M →ₗ[R] M) (e : M ≃ₗ[R] N) : trace R N (e.conj f) = trace R M f := by
classical
by_cases hM : ∃ s : Finset M, Nonempty (Basis s R M)
· obtain ⟨s, ⟨b⟩⟩ := hM
haveI := Module.Finite.of_basis b
haveI := (Module.free_def R M).mpr ⟨_, ⟨b⟩⟩
haveI := Module.Finite.of_basis (b.map e)
haveI := (Module.free_def R N).mpr ⟨_, ⟨(b.map e).reindex (e.toEquiv.image _)⟩⟩
rw [e.conj_apply, trace_comp_comm', ← comp_assoc, LinearEquiv.comp_coe,
LinearEquiv.self_trans_symm, LinearEquiv.refl_toLinearMap, id_comp]
· rw [trace, trace, dif_neg hM, dif_neg ?_, zero_apply, zero_apply]
rintro ⟨s, ⟨b⟩⟩
exact hM ⟨s.image e.symm, ⟨(b.map e.symm).reindex
((e.symm.toEquiv.image s).trans (Equiv.Set.ofEq Finset.coe_image.symm))⟩⟩
theorem IsProj.trace {p : Submodule R M} {f : M →ₗ[R] M} (h : IsProj p f) [Module.Free R p]
[Module.Finite R p] [Module.Free R (ker f)] [Module.Finite R (ker f)] :
trace R M f = (finrank R p : R) := by
rw [h.eq_conj_prodMap, trace_conj', trace_prodMap', trace_id, map_zero, add_zero]
variable [Module.Free R M] [Module.Finite R M] in
lemma isNilpotent_trace_of_isNilpotent {f : M →ₗ[R] M} (hf : IsNilpotent f) :
IsNilpotent (trace R M f) := by
let b : Basis _ R M := Module.Free.chooseBasis R M
rw [trace_eq_matrix_trace R b]
apply Matrix.isNilpotent_trace_of_isNilpotent
simpa
variable [Module.Free R M] [Module.Finite R M] in
lemma trace_comp_eq_mul_of_commute_of_isNilpotent [IsReduced R] {f g : Module.End R M}
(μ : R) (h_comm : Commute f g) (hg : IsNilpotent (g - algebraMap R _ μ)) :
trace R M (f ∘ₗ g) = μ * trace R M f := by
set n := g - algebraMap R _ μ
replace hg : trace R M (f ∘ₗ n) = 0 := by
rw [← isNilpotent_iff_eq_zero, ← mul_eq_comp]
refine isNilpotent_trace_of_isNilpotent (Commute.isNilpotent_mul_right ?_ hg)
exact h_comm.sub_right (Algebra.commute_algebraMap_right μ f)
have hμ : g = algebraMap R _ μ + n := eq_add_of_sub_eq' rfl
have : f ∘ₗ algebraMap R _ μ = μ • f := by ext; simp -- TODO Surely exists?
rw [hμ, comp_add, map_add, hg, add_zero, this, LinearMap.map_smul, smul_eq_mul]
@[simp]
lemma trace_baseChange [Module.Free R M] [Module.Finite R M]
(f : M →ₗ[R] M) (A : Type*) [CommRing A] [Algebra R A] :
trace A _ (f.baseChange A) = algebraMap R A (trace R _ f) := by
let b := Module.Free.chooseBasis R M
let b' := Algebra.TensorProduct.basis A b
change _ = (algebraMap R A : R →+ A) _
simp [b', trace_eq_matrix_trace R b, trace_eq_matrix_trace A b', AddMonoidHom.map_trace]
end
end LinearMap
|
LinearAlgebra\UnitaryGroup.lean | /-
Copyright (c) 2021 Shing Tak Lam. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Shing Tak Lam
-/
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.Algebra.Star.Unitary
/-!
# The Unitary Group
This file defines elements of the unitary group `Matrix.unitaryGroup n α`, where `α` is a
`StarRing`. This consists of all `n` by `n` matrices with entries in `α` such that the
star-transpose is its inverse. In addition, we define the group structure on
`Matrix.unitaryGroup n α`, and the embedding into the general linear group
`LinearMap.GeneralLinearGroup α (n → α)`.
We also define the orthogonal group `Matrix.orthogonalGroup n β`, where `β` is a `CommRing`.
## Main Definitions
* `Matrix.unitaryGroup` is the submonoid of matrices where the star-transpose is the inverse; the
group structure (under multiplication) is inherited from a more general `unitary` construction.
* `Matrix.UnitaryGroup.embeddingGL` is the embedding `Matrix.unitaryGroup n α → GLₙ(α)`, where
`GLₙ(α)` is `LinearMap.GeneralLinearGroup α (n → α)`.
* `Matrix.orthogonalGroup` is the submonoid of matrices where the transpose is the inverse.
## References
* https://en.wikipedia.org/wiki/Unitary_group
## Tags
matrix group, group, unitary group, orthogonal group
-/
universe u v
namespace Matrix
open LinearMap Matrix
section
variable (n : Type u) [DecidableEq n] [Fintype n]
variable (α : Type v) [CommRing α] [StarRing α]
/-- `Matrix.unitaryGroup n` is the group of `n` by `n` matrices where the star-transpose is the
inverse.
-/
abbrev unitaryGroup :=
unitary (Matrix n n α)
end
variable {n : Type u} [DecidableEq n] [Fintype n]
variable {α : Type v} [CommRing α] [StarRing α] {A : Matrix n n α}
theorem mem_unitaryGroup_iff : A ∈ Matrix.unitaryGroup n α ↔ A * star A = 1 := by
refine ⟨And.right, fun hA => ⟨?_, hA⟩⟩
simpa only [mul_eq_one_comm] using hA
theorem mem_unitaryGroup_iff' : A ∈ Matrix.unitaryGroup n α ↔ star A * A = 1 := by
refine ⟨And.left, fun hA => ⟨hA, ?_⟩⟩
rwa [mul_eq_one_comm] at hA
theorem det_of_mem_unitary {A : Matrix n n α} (hA : A ∈ Matrix.unitaryGroup n α) :
A.det ∈ unitary α := by
constructor
· simpa [star, det_transpose] using congr_arg det hA.1
· simpa [star, det_transpose] using congr_arg det hA.2
namespace UnitaryGroup
instance coeMatrix : Coe (unitaryGroup n α) (Matrix n n α) :=
⟨Subtype.val⟩
instance coeFun : CoeFun (unitaryGroup n α) fun _ => n → n → α where coe A := A.val
/-- `Matrix.UnitaryGroup.toLin' A` is matrix multiplication of vectors by `A`, as a linear map.
After the group structure on `Matrix.unitaryGroup n` is defined, we show in
`Matrix.UnitaryGroup.toLinearEquiv` that this gives a linear equivalence.
-/
def toLin' (A : unitaryGroup n α) :=
Matrix.toLin' A.1
theorem ext_iff (A B : unitaryGroup n α) : A = B ↔ ∀ i j, A i j = B i j :=
Subtype.ext_iff_val.trans ⟨fun h i j => congr_fun (congr_fun h i) j, Matrix.ext⟩
@[ext]
theorem ext (A B : unitaryGroup n α) : (∀ i j, A i j = B i j) → A = B :=
(UnitaryGroup.ext_iff A B).mpr
theorem star_mul_self (A : unitaryGroup n α) : star A.1 * A.1 = 1 :=
A.2.1
@[simp]
theorem det_isUnit (A : unitaryGroup n α) : IsUnit (A : Matrix n n α).det :=
isUnit_iff_isUnit_det _ |>.mp <| (unitary.toUnits A).isUnit
section CoeLemmas
variable (A B : unitaryGroup n α)
@[simp] theorem inv_val : ↑A⁻¹ = (star A : Matrix n n α) := rfl
@[simp] theorem inv_apply : ⇑A⁻¹ = (star A : Matrix n n α) := rfl
@[simp] theorem mul_val : ↑(A * B) = A.1 * B.1 := rfl
@[simp] theorem mul_apply : ⇑(A * B) = A.1 * B.1 := rfl
@[simp] theorem one_val : ↑(1 : unitaryGroup n α) = (1 : Matrix n n α) := rfl
@[simp] theorem one_apply : ⇑(1 : unitaryGroup n α) = (1 : Matrix n n α) := rfl
@[simp]
theorem toLin'_mul : toLin' (A * B) = (toLin' A).comp (toLin' B) :=
Matrix.toLin'_mul A.1 B.1
@[simp]
theorem toLin'_one : toLin' (1 : unitaryGroup n α) = LinearMap.id :=
Matrix.toLin'_one
end CoeLemmas
-- Porting note (#11215): TODO: redefine `toGL`/`embeddingGL` as in this example:
example : unitaryGroup n α →* GeneralLinearGroup α (n → α) :=
.toHomUnits ⟨⟨toLin', toLin'_one⟩, toLin'_mul⟩
-- Porting note: then we can get `toLinearEquiv` from `GeneralLinearGroup.toLinearEquiv`
/-- `Matrix.unitaryGroup.toLinearEquiv A` is matrix multiplication of vectors by `A`, as a linear
equivalence. -/
def toLinearEquiv (A : unitaryGroup n α) : (n → α) ≃ₗ[α] n → α :=
{ Matrix.toLin' A.1 with
invFun := toLin' A⁻¹
left_inv := fun x =>
calc
(toLin' A⁻¹).comp (toLin' A) x = (toLin' (A⁻¹ * A)) x := by rw [← toLin'_mul]
_ = x := by rw [mul_left_inv, toLin'_one, id_apply]
right_inv := fun x =>
calc
(toLin' A).comp (toLin' A⁻¹) x = toLin' (A * A⁻¹) x := by rw [← toLin'_mul]
_ = x := by rw [mul_right_inv, toLin'_one, id_apply] }
/-- `Matrix.unitaryGroup.toGL` is the map from the unitary group to the general linear group -/
def toGL (A : unitaryGroup n α) : GeneralLinearGroup α (n → α) :=
GeneralLinearGroup.ofLinearEquiv (toLinearEquiv A)
theorem coe_toGL (A : unitaryGroup n α) : (toGL A).1 = toLin' A := rfl
@[simp]
theorem toGL_one : toGL (1 : unitaryGroup n α) = 1 := Units.ext <| by
simp only [coe_toGL, toLin'_one]
rfl
@[simp]
theorem toGL_mul (A B : unitaryGroup n α) : toGL (A * B) = toGL A * toGL B := Units.ext <| by
simp only [coe_toGL, toLin'_mul]
rfl
/-- `Matrix.unitaryGroup.embeddingGL` is the embedding from `Matrix.unitaryGroup n α` to
`LinearMap.GeneralLinearGroup n α`. -/
def embeddingGL : unitaryGroup n α →* GeneralLinearGroup α (n → α) :=
⟨⟨fun A => toGL A, toGL_one⟩, toGL_mul⟩
end UnitaryGroup
section specialUnitaryGroup
variable (n) (α)
/-- `Matrix.specialUnitaryGroup` is the group of unitary `n` by `n` matrices where the determinant
is 1. (This definition is only correct if 2 is invertible.)-/
abbrev specialUnitaryGroup := unitaryGroup n α ⊓ MonoidHom.mker detMonoidHom
variable {n} {α}
theorem mem_specialUnitaryGroup_iff :
A ∈ specialUnitaryGroup n α ↔ A ∈ unitaryGroup n α ∧ A.det = 1 :=
Iff.rfl
end specialUnitaryGroup
section OrthogonalGroup
variable (n) (β : Type v) [CommRing β]
-- Porting note (#11215): TODO: will lemmas about `Matrix.orthogonalGroup` work without making
-- `starRingOfComm` a local instance? E.g., can we talk about unitary group and orthogonal group
-- at the same time?
attribute [local instance] starRingOfComm
/-- `Matrix.orthogonalGroup n` is the group of `n` by `n` matrices where the transpose is the
inverse. -/
abbrev orthogonalGroup := unitaryGroup n β
theorem mem_orthogonalGroup_iff {A : Matrix n n β} :
A ∈ Matrix.orthogonalGroup n β ↔ A * star A = 1 := by
refine ⟨And.right, fun hA => ⟨?_, hA⟩⟩
simpa only [mul_eq_one_comm] using hA
theorem mem_orthogonalGroup_iff' {A : Matrix n n β} :
A ∈ Matrix.orthogonalGroup n β ↔ star A * A = 1 := by
refine ⟨And.left, fun hA => ⟨hA, ?_⟩⟩
rwa [mul_eq_one_comm] at hA
end OrthogonalGroup
section specialOrthogonalGroup
variable (n) (β : Type v) [CommRing β]
attribute [local instance] starRingOfComm
/-- `Matrix.specialOrthogonalGroup n` is the group of orthogonal `n` by `n` where the determinant
is one. (This definition is only correct if 2 is invertible.)-/
abbrev specialOrthogonalGroup := specialUnitaryGroup n β
variable {n} {β} {A : Matrix n n β}
theorem mem_specialOrthogonalGroup_iff :
A ∈ specialOrthogonalGroup n β ↔ A ∈ orthogonalGroup n β ∧ A.det = 1 :=
Iff.rfl
end specialOrthogonalGroup
end Matrix
|
LinearAlgebra\Vandermonde.lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.GeomSum
import Mathlib.LinearAlgebra.Matrix.Block
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.Nondegenerate
/-!
# Vandermonde matrix
This file defines the `vandermonde` matrix and gives its determinant.
## Main definitions
- `vandermonde v`: a square matrix with the `i, j`th entry equal to `v i ^ j`.
## Main results
- `det_vandermonde`: `det (vandermonde v)` is the product of `v i - v j`, where
`(i, j)` ranges over the unordered pairs.
-/
variable {R : Type*} [CommRing R]
open Equiv Finset
open Matrix
namespace Matrix
/-- `vandermonde v` is the square matrix with `i`th row equal to `1, v i, v i ^ 2, v i ^ 3, ...`.
-/
def vandermonde {n : ℕ} (v : Fin n → R) : Matrix (Fin n) (Fin n) R := fun i j => v i ^ (j : ℕ)
@[simp]
theorem vandermonde_apply {n : ℕ} (v : Fin n → R) (i j) : vandermonde v i j = v i ^ (j : ℕ) :=
rfl
@[simp]
theorem vandermonde_cons {n : ℕ} (v0 : R) (v : Fin n → R) :
vandermonde (Fin.cons v0 v : Fin n.succ → R) =
Fin.cons (fun (j : Fin n.succ) => v0 ^ (j : ℕ)) fun i => Fin.cons 1
fun j => v i * vandermonde v i j := by
ext i j
refine Fin.cases (by simp) (fun i => ?_) i
refine Fin.cases (by simp) (fun j => ?_) j
simp [pow_succ']
theorem vandermonde_succ {n : ℕ} (v : Fin n.succ → R) :
vandermonde v =
Fin.cons (fun (j : Fin n.succ) => v 0 ^ (j : ℕ)) fun i =>
Fin.cons 1 fun j => v i.succ * vandermonde (Fin.tail v) i j := by
conv_lhs => rw [← Fin.cons_self_tail v, vandermonde_cons]
rfl
theorem vandermonde_mul_vandermonde_transpose {n : ℕ} (v w : Fin n → R) (i j) :
(vandermonde v * (vandermonde w)ᵀ) i j = ∑ k : Fin n, (v i * w j) ^ (k : ℕ) := by
simp only [vandermonde_apply, Matrix.mul_apply, Matrix.transpose_apply, mul_pow]
theorem vandermonde_transpose_mul_vandermonde {n : ℕ} (v : Fin n → R) (i j) :
((vandermonde v)ᵀ * vandermonde v) i j = ∑ k : Fin n, v k ^ (i + j : ℕ) := by
simp only [vandermonde_apply, Matrix.mul_apply, Matrix.transpose_apply, pow_add]
theorem det_vandermonde {n : ℕ} (v : Fin n → R) :
det (vandermonde v) = ∏ i : Fin n, ∏ j ∈ Ioi i, (v j - v i) := by
unfold vandermonde
induction' n with n ih
· exact det_eq_one_of_card_eq_zero (Fintype.card_fin 0)
calc
det (of fun i j : Fin n.succ => v i ^ (j : ℕ)) =
det
(of fun i j : Fin n.succ =>
Matrix.vecCons (v 0 ^ (j : ℕ)) (fun i => v (Fin.succ i) ^ (j : ℕ) - v 0 ^ (j : ℕ)) i) :=
det_eq_of_forall_row_eq_smul_add_const (Matrix.vecCons 0 1) 0 (Fin.cons_zero _ _) ?_
_ =
det
(of fun i j : Fin n =>
Matrix.vecCons (v 0 ^ (j.succ : ℕ))
(fun i : Fin n => v (Fin.succ i) ^ (j.succ : ℕ) - v 0 ^ (j.succ : ℕ))
(Fin.succAbove 0 i)) := by
simp_rw [det_succ_column_zero, Fin.sum_univ_succ, of_apply, Matrix.cons_val_zero, submatrix,
of_apply, Matrix.cons_val_succ, Fin.val_zero, pow_zero, one_mul, sub_self,
mul_zero, zero_mul, Finset.sum_const_zero, add_zero]
_ =
det
(of fun i j : Fin n =>
(v (Fin.succ i) - v 0) *
∑ k ∈ Finset.range (j + 1 : ℕ), v i.succ ^ k * v 0 ^ (j - k : ℕ) :
Matrix _ _ R) := by
congr
ext i j
rw [Fin.succAbove_zero, Matrix.cons_val_succ, Fin.val_succ, mul_comm]
exact (geom_sum₂_mul (v i.succ) (v 0) (j + 1 : ℕ)).symm
_ =
(∏ i ∈ Finset.univ, (v (Fin.succ i) - v 0)) *
det fun i j : Fin n =>
∑ k ∈ Finset.range (j + 1 : ℕ), v i.succ ^ k * v 0 ^ (j - k : ℕ) :=
(det_mul_column (fun i => v (Fin.succ i) - v 0) _)
_ = (∏ i ∈ Finset.univ, (v (Fin.succ i) - v 0)) *
det fun i j : Fin n => v (Fin.succ i) ^ (j : ℕ) := congr_arg _ ?_
_ = ∏ i : Fin n.succ, ∏ j ∈ Ioi i, (v j - v i) := by
simp_rw [Fin.prod_univ_succ, Fin.prod_Ioi_zero, Fin.prod_Ioi_succ]
have h := ih (v ∘ Fin.succ)
unfold Function.comp at h
rw [h]
· intro i j
simp_rw [of_apply]
rw [Matrix.cons_val_zero]
refine Fin.cases ?_ (fun i => ?_) i
· simp
rw [Matrix.cons_val_succ, Matrix.cons_val_succ, Pi.one_apply]
ring
· cases n
· rw [det_eq_one_of_card_eq_zero (Fintype.card_fin 0),
det_eq_one_of_card_eq_zero (Fintype.card_fin 0)]
apply det_eq_of_forall_col_eq_smul_add_pred fun _ => v 0
· intro j
simp
· intro i j
simp only [smul_eq_mul, Pi.add_apply, Fin.val_succ, Fin.coe_castSucc, Pi.smul_apply]
rw [Finset.sum_range_succ, add_comm, tsub_self, pow_zero, mul_one, Finset.mul_sum]
congr 1
refine Finset.sum_congr rfl fun i' hi' => ?_
rw [mul_left_comm (v 0), Nat.succ_sub, pow_succ']
exact Nat.lt_succ_iff.mp (Finset.mem_range.mp hi')
theorem det_vandermonde_eq_zero_iff [IsDomain R] {n : ℕ} {v : Fin n → R} :
det (vandermonde v) = 0 ↔ ∃ i j : Fin n, v i = v j ∧ i ≠ j := by
constructor
· simp only [det_vandermonde v, Finset.prod_eq_zero_iff, sub_eq_zero, forall_exists_index]
rintro i ⟨_, j, h₁, h₂⟩
exact ⟨j, i, h₂, (mem_Ioi.mp h₁).ne'⟩
· simp only [Ne, forall_exists_index, and_imp]
refine fun i j h₁ h₂ => Matrix.det_zero_of_row_eq h₂ (funext fun k => ?_)
rw [vandermonde_apply, vandermonde_apply, h₁]
theorem det_vandermonde_ne_zero_iff [IsDomain R] {n : ℕ} {v : Fin n → R} :
det (vandermonde v) ≠ 0 ↔ Function.Injective v := by
unfold Function.Injective
simp only [det_vandermonde_eq_zero_iff, Ne, not_exists, not_and, Classical.not_not]
@[simp]
theorem det_vandermonde_add {n : ℕ} (v : Fin n → R) (a : R) :
(Matrix.vandermonde fun i ↦ v i + a).det = (Matrix.vandermonde v).det := by
simp [Matrix.det_vandermonde]
@[simp]
theorem det_vandermonde_sub {n : ℕ} (v : Fin n → R) (a : R) :
(Matrix.vandermonde fun i ↦ v i - a).det = (Matrix.vandermonde v).det := by
rw [← det_vandermonde_add v (- a)]
simp only [← sub_eq_add_neg]
theorem eq_zero_of_forall_index_sum_pow_mul_eq_zero {R : Type*} [CommRing R] [IsDomain R] {n : ℕ}
{f v : Fin n → R} (hf : Function.Injective f)
(hfv : ∀ j, (∑ i : Fin n, f j ^ (i : ℕ) * v i) = 0) : v = 0 :=
eq_zero_of_mulVec_eq_zero (det_vandermonde_ne_zero_iff.mpr hf) (funext hfv)
theorem eq_zero_of_forall_index_sum_mul_pow_eq_zero {R : Type*} [CommRing R] [IsDomain R] {n : ℕ}
{f v : Fin n → R} (hf : Function.Injective f) (hfv : ∀ j, (∑ i, v i * f j ^ (i : ℕ)) = 0) :
v = 0 := by
apply eq_zero_of_forall_index_sum_pow_mul_eq_zero hf
simp_rw [mul_comm]
exact hfv
theorem eq_zero_of_forall_pow_sum_mul_pow_eq_zero {R : Type*} [CommRing R] [IsDomain R] {n : ℕ}
{f v : Fin n → R} (hf : Function.Injective f)
(hfv : ∀ i : Fin n, (∑ j : Fin n, v j * f j ^ (i : ℕ)) = 0) : v = 0 :=
eq_zero_of_vecMul_eq_zero (det_vandermonde_ne_zero_iff.mpr hf) (funext hfv)
open Polynomial
theorem eval_matrixOfPolynomials_eq_vandermonde_mul_matrixOfPolynomials {n : ℕ}
(v : Fin n → R) (p : Fin n → R[X]) (h_deg : ∀ i, (p i).natDegree ≤ i) :
Matrix.of (fun i j => ((p j).eval (v i))) =
(Matrix.vandermonde v) * (Matrix.of (fun (i j : Fin n) => (p j).coeff i)) := by
ext i j
rw [Matrix.mul_apply, eval, Matrix.of_apply, eval₂]
simp only [eq_intCast, Int.cast_id, Matrix.vandermonde]
have : (p j).support ⊆ range n := supp_subset_range <| Nat.lt_of_le_of_lt (h_deg j) <| Fin.prop j
rw [sum_eq_of_subset _ (fun j => zero_mul ((v i) ^ j)) this, ← Fin.sum_univ_eq_sum_range]
congr
ext k
rw [mul_comm, Matrix.of_apply, RingHom.id_apply]
theorem det_eval_matrixOfPolynomials_eq_det_vandermonde {n : ℕ} (v : Fin n → R) (p : Fin n → R[X])
(h_deg : ∀ i, (p i).natDegree = i) (h_monic : ∀ i, Monic <| p i) :
(Matrix.vandermonde v).det = (Matrix.of (fun i j => ((p j).eval (v i)))).det := by
rw [Matrix.eval_matrixOfPolynomials_eq_vandermonde_mul_matrixOfPolynomials v p (fun i ↦
Nat.le_of_eq (h_deg i)), Matrix.det_mul,
Matrix.det_matrixOfPolynomials p h_deg h_monic, mul_one]
end Matrix
|
LinearAlgebra\AffineSpace\AffineEquiv.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
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. -/
-- Porting note(#5171): this linter isn't ported yet.
-- @[nolint has_nonempty_instance]
structure AffineEquiv (k P₁ P₂ : Type*) {V₁ V₂ : Type*} [Ring k] [AddCommGroup V₁] [Module k V₁]
[AddTorsor V₁ P₁] [AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂] extends P₁ ≃ P₂ where
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₁] [Module k V₁]
[AddTorsor V₁ P₁] [AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂] [AddCommGroup V₃]
[Module k V₃] [AddTorsor V₃ P₃] [AddCommGroup V₄] [Module k V₄] [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
-- Porting note: added `AffineMap.mk.injEq`
simp only [toAffineMap_mk, AffineMap.mk.injEq, Equiv.coe_inj,
LinearEquiv.toLinearMap_inj] at H
congr
exacts [H.1, H.2]
@[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 : CoeFun (P₁ ≃ᵃ[k] P₂) fun _ => P₁ → P₂ :=
DFunLike.hasCoeToFun
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]
-- Porting note: removed `simp`: proof is `simp only [DFunLike.coe_fn_eq]`
theorem coeFn_inj {e e' : P₁ ≃ᵃ[k] P₂} : (e : P₁ → P₂) = e' ↔ e = e' :=
coeFn_injective.eq_iff
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 symm_toEquiv (e : P₁ ≃ᵃ[k] P₂) : e.toEquiv.symm = e.symm.toEquiv :=
rfl
@[simp]
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
@[simp]
theorem range_eq (e : P₁ ≃ᵃ[k] P₂) : range e = univ :=
e.surjective.range_eq
@[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
-- Porting note: removed `simp`, proof is `by simp only [@EmbeddingLike.apply_eq_iff_eq]`
theorem apply_eq_iff_eq (e : P₁ ≃ᵃ[k] P₂) {p₁ p₂ : P₁} : e p₁ = e p₂ ↔ p₁ = p₂ :=
e.toEquiv.apply_eq_iff_eq
@[simp]
theorem image_symm (f : P₁ ≃ᵃ[k] P₂) (s : Set P₂) : f.symm '' s = f ⁻¹' s :=
f.symm.toEquiv.image_eq_preimage _
@[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] -- Porting note: removed attribute
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 e₁ e₂ e₃ := trans_assoc _ _ _
one_mul := trans_refl
mul_one := refl_trans
mul_left_inv := 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 _ _ }
left_inv _ := AffineEquiv.ext fun _ => rfl
right_inv _ := Units.ext <| AffineMap.ext fun _ => rfl
map_mul' _ _ := rfl
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₁ (Multiplicative.toAdd v)
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)
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
@[simp]
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
set_option linter.deprecated false in
/-- `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_bit0 {x y : P₁} (h : Injective (2 • · : V₁ → V₁)) :
pointReflection k x y = y ↔ y = x :=
Equiv.pointReflection_fixed_iff_of_injective_bit0 h
set_option linter.deprecated false in
theorem injective_pointReflection_left_of_injective_bit0
(h : Injective (2 • · : V₁ → V₁)) (y : P₁) :
Injective fun x : P₁ => pointReflection k x y :=
Equiv.injective_pointReflection_left_of_injective_bit0 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_bit0 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 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, pointReflection_apply]
end AffineMap
|
LinearAlgebra\AffineSpace\AffineMap.lean | /-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Data.Set.Pointwise.Interval
import Mathlib.LinearAlgebra.AffineSpace.Basic
import Mathlib.LinearAlgebra.BilinearMap
import Mathlib.LinearAlgebra.Pi
import Mathlib.LinearAlgebra.Prod
import Mathlib.Tactic.Abel
/-!
# 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`.
## Notations
* `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.NormedSpace.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
toFun : P1 → P2
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
cases' (AddTorsor.nonempty : Nonempty P1) with p
congr with v
apply vadd_right_cancel (f p)
erw [← f_add, h, ← g_add]
instance AffineMap.hasCoeToFun (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] : CoeFun (P1 →ᵃ[k] P2) fun _ => P1 → P2 :=
DFunLike.hasCoeToFun
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
-- Porting note: `map_vadd` is `simp`, but we still have to pass it explicitly
smul c f := ⟨c • ⇑f, c • f.linear, fun p v => by simp [smul_add, map_vadd f]⟩
one_smul f := ext fun p => one_smul _ _
mul_smul c₁ c₂ f := ext fun p => 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, add_sub, 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 vsub_apply (f g : P1 →ᵃ[k] P2) (p : P1) : (f -ᵥ g : P1 →ᵃ[k] V2) p = f p -ᵥ g p :=
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]
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. -/
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, vadd_vsub_assoc]
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, vadd_vsub_assoc]
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
-- Porting note: `simp` needs `Set.mem_vsub` to be an expression
simp only [(Set.mem_vsub), Set.mem_image,
exists_exists_and_eq_and, exists_and_left, ← f.linearMap_vsub]
constructor
· rintro ⟨x, hx, y, hy, hv⟩
exact ⟨x -ᵥ y, ⟨x, hx, y, hy, rfl⟩, hv⟩
· rintro ⟨-, ⟨x, hx, y, hy, rfl⟩, rfl⟩
exact ⟨x, hx, y, hy, 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)
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
variable {k}
@[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
rw [comp_lineMap]
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
/-- 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*} [LinearOrderedField 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 [const_apply _ _] -- Porting note: `simp` needs `_`s to use this lemma
right_inv := by
rintro ⟨v, f⟩
ext <;> simp [const_apply _ _, const_linear _ _] -- Porting note: `simp` needs `_`s
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`.
-/
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, Function.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-tyoe 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 agrement 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-tyoe 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 `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 homothety_apply (c : P1) (r : k) (p : P1) : homothety c r p = r • (p -ᵥ c : V1) +ᵥ c :=
rfl
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
|
LinearAlgebra\AffineSpace\AffineSubspace.lean | /-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv
/-!
# 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.
* `AffineSubspace.parallel`, notation `∥`, gives the property of two affine subspaces being
parallel (one being a translate of the other).
* `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.NormedSpace.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
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)
/-- 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]
variable {P}
/-- 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} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) :
p1 -ᵥ p2 ∈ vectorSpan k s :=
vsub_set_subset_vectorSpan k s (vsub_mem_vsub hp1 hp2)
/-- 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 | ∃ p1 ∈ s, ∃ v ∈ vectorSpan k s, p = v +ᵥ p1 }
/-- 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 ⟨p2, ⟨hp2, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩
rw [hv2p, vadd_vadd]
exact ⟨p2, hp2, v + v2, (vectorSpan k s).add_mem hv hv2, 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} {p1 p2 : P}
(hp1 : p1 ∈ spanPoints k s) (hp2 : p2 ∈ spanPoints k s) : p1 -ᵥ p2 ∈ vectorSpan k s := by
rcases hp1 with ⟨p1a, ⟨hp1a, ⟨v1, ⟨hv1, hv1p⟩⟩⟩⟩
rcases hp2 with ⟨p2a, ⟨hp2a, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩
rw [hv1p, hv2p, vsub_vadd_eq_vsub_sub (v1 +ᵥ p1a), vadd_vsub_assoc, add_comm, add_sub_assoc]
have hv1v2 : v1 - v2 ∈ vectorSpan k s := (vectorSpan k s).sub_mem hv1 hv2
refine (vectorSpan k s).add_mem ?_ hv1v2
exact vsub_mem_vectorSpan k hp1a hp2a
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) {p1 p2 p3 : P},
p1 ∈ carrier → p2 ∈ carrier → p3 ∈ carrier → c • (p1 -ᵥ p2 : V) +ᵥ p3 ∈ 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. -/
-- Porting note: removed `simp`, proof is `simp only [SetLike.mem_coe]`
theorem mem_coe (p : P) (s : AffineSubspace k P) : p ∈ (s : Set P) ↔ p ∈ s :=
Iff.rfl
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
cases' h with p hp
exact vsub_self p ▸ vsub_mem_vsub hp hp
add_mem' := by
rintro _ _ ⟨p1, hp1, p2, hp2, rfl⟩ ⟨p3, hp3, p4, hp4, rfl⟩
rw [← vadd_vsub_assoc]
refine vsub_mem_vsub ?_ hp4
convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp3
rw [one_smul]
smul_mem' := by
rintro c _ ⟨p1, hp1, p2, hp2, rfl⟩
rw [← vadd_vsub (c • (p1 -ᵥ p2)) p2]
refine vsub_mem_vsub ?_ hp2
exact s.smul_vsub_vadd_mem c hp1 hp2 hp2
/-- `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 ↔ ∃ p1 ∈ s, ∃ p2 ∈ s, v = p1 -ᵥ p2 := 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 ⟨p1, hp1, p2, hp2, hv⟩
rw [hv]
convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp
rw [one_smul]
exact s.mem_coe k P _
/-- Subtracting two points in the subspace produces a vector in the direction. -/
theorem vsub_mem_direction {s : AffineSubspace k P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) :
p1 -ᵥ p2 ∈ s.direction :=
vsub_mem_vectorSpan k hp1 hp2
/-- 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 ⟨p1, hp1, p2, hp2, rfl⟩
exact ⟨p1 -ᵥ p2 +ᵥ p, vadd_mem_of_mem_direction (vsub_mem_direction hp1 hp2) hp, vadd_vsub _ _⟩
· rintro v ⟨p2, hp2, rfl⟩
exact ⟨p2, hp2, 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 ↔ ∃ p2 ∈ s, v = p2 -ᵥ p := by
rw [← SetLike.mem_coe, coe_direction_eq_vsub_set_right hp]
exact ⟨fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩, fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, 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 ↔ ∃ p2 ∈ s, v = p -ᵥ p2 := by
rw [← SetLike.mem_coe, coe_direction_eq_vsub_set_left hp]
exact ⟨fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩, fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩⟩
/-- 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) (p2 : P) :
p2 -ᵥ p ∈ s.direction ↔ p2 ∈ 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) (p2 : P) :
p -ᵥ p2 ∈ s.direction ↔ p2 ∈ s := by
rw [mem_direction_iff_eq_vsub_left hp]
simp
/-- 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 {s1 s2 : AffineSubspace k P} (hd : s1.direction = s2.direction)
(hn : ((s1 : Set P) ∩ s2).Nonempty) : s1 = s2 := 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
-- See note [reducible non instances]
/-- This is not an instance because it loops with `AddTorsor.nonempty`. -/
abbrev 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'
attribute [local instance] toAddTorsor
@[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
theorem subtype_apply (s : AffineSubspace k P) [Nonempty s] (p : s) : s.subtype p = p :=
rfl
@[simp]
theorem coeSubtype (s : AffineSubspace k P) [Nonempty s] : (s.subtype : s → P) = ((↑) : s → P) :=
rfl
theorem injective_subtype (s : AffineSubspace k P) [Nonempty s] : Function.Injective s.subtype :=
Subtype.coe_injective
/-- 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 | ∃ v ∈ direction, q = v +ᵥ p }
smul_vsub_vadd_mem c p1 p2 p3 hp1 hp2 hp3 := by
rcases hp1 with ⟨v1, hv1, hp1⟩
rcases hp2 with ⟨v2, hv2, hp2⟩
rcases hp3 with ⟨v3, hv3, hp3⟩
use c • (v1 - v2) + v3, direction.add_mem (direction.smul_mem c (direction.sub_mem hv1 hv2)) hv3
simp [hp1, hp2, hp3, vadd_vadd]
/-- 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 :=
⟨0, ⟨direction.zero_mem, (zero_vadd _ _).symm⟩⟩
/-- 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 :=
⟨v, hv, rfl⟩
/-- 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 ⟨p1, ⟨v1, hv1, hp1⟩, p2, ⟨v2, hv2, hp2⟩, hv⟩
rw [hv, hp1, hp2, vadd_vsub_vadd_cancel_right]
exact direction.sub_mem hv1 hv2
· exact fun hv => ⟨v +ᵥ p, vadd_mem_mk' _ hv, p, self_mem_mk' _ _, (vadd_vsub _ _).symm⟩
/-- A point lies in an affine subspace constructed from another point and a direction if and only
if their difference is in that direction. -/
theorem mem_mk'_iff_vsub_mem {p₁ p₂ : P} {direction : Submodule k V} :
p₂ ∈ mk' p₁ direction ↔ p₂ -ᵥ p₁ ∈ direction := by
refine ⟨fun h => ?_, fun h => ?_⟩
· rw [← direction_mk' p₁ direction]
exact vsub_mem_direction h (self_mem_mk' _ _)
· rw [← vsub_vadd p₂ p₁]
exact vadd_mem_mk' p₁ h
/-- 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} {s1 : AffineSubspace k P} (h : s ⊆ s1) :
spanPoints k s ⊆ s1 := by
rintro p ⟨p1, hp1, v, hv, hp⟩
rw [hp]
have hp1s1 : p1 ∈ (s1 : Set P) := Set.mem_of_mem_of_subset hp1 h
refine vadd_mem_of_mem_direction ?_ hp1s1
have hs : vectorSpan k s ≤ s1.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
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₀
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 _ _ _ hp1 hp2 hp3 :=
vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan k hp3
((vectorSpan k s).smul_mem c
(vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints k hp1 hp2))
/-- 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
/-- 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 ⟨p1, ⟨p2, hp2, v1, hv1, hp1⟩, p3, ⟨p4, hp4, v2, hv2, hp3⟩, rfl⟩
simp only [SetLike.mem_coe]
rw [hp1, hp3, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc]
exact
(vectorSpan k s).sub_mem ((vectorSpan k s).add_mem hv1 (vsub_mem_vectorSpan k hp2 hp4)) hv2
· 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
end affineSpan
namespace AffineSubspace
variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V]
[S : AffineSpace V P]
instance : CompleteLattice (AffineSubspace k P) :=
{
PartialOrder.lift ((↑) : AffineSubspace k P → Set P)
coe_injective with
sup := fun s1 s2 => affineSpan k (s1 ∪ s2)
le_sup_left := fun s1 s2 =>
Set.Subset.trans Set.subset_union_left (subset_spanPoints k _)
le_sup_right := fun s1 s2 =>
Set.Subset.trans Set.subset_union_right (subset_spanPoints k _)
sup_le := fun s1 s2 s3 hs1 hs2 => spanPoints_subset_coe_of_subset_coe (Set.union_subset hs1 hs2)
inf := fun s1 s2 =>
mk (s1 ∩ s2) fun c p1 p2 p3 hp1 hp2 hp3 =>
⟨s1.smul_vsub_vadd_mem c hp1.1 hp2.1 hp3.1, s2.smul_vsub_vadd_mem c hp1.2 hp2.2 hp3.2⟩
inf_le_left := fun _ _ => Set.inter_subset_left
inf_le_right := fun _ _ => Set.inter_subset_right
le_sInf := fun S s1 hs1 => by
-- Porting note: surely there is an easier way?
refine Set.subset_sInter (t := (s1 : Set P)) ?_
rintro t ⟨s, _hs, rfl⟩
exact Set.subset_iInter (hs1 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 p1 p2 p3 hp1 hp2 hp3 =>
Set.mem_iInter₂.2 fun s2 hs2 => by
rw [Set.mem_iInter₂] at *
exact s2.smul_vsub_vadd_mem c (hp1 s2 hs2) (hp2 s2 hs2) (hp3 s2 hs2)
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 (s1 s2 : AffineSubspace k P) : s1 ≤ s2 ↔ (s1 : Set P) ⊆ s2 :=
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' (s1 s2 : AffineSubspace k P) : s1 ≤ s2 ↔ ∀ p ∈ s1, p ∈ s2 :=
Iff.rfl
/-- The `<` order on subspaces is the same as that on the corresponding sets. -/
theorem lt_def (s1 s2 : AffineSubspace k P) : s1 < s2 ↔ (s1 : Set P) ⊂ s2 :=
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 (s1 s2 : AffineSubspace k P) : ¬s1 ≤ s2 ↔ ∃ p ∈ s1, p ∉ s2 :=
Set.not_subset
/-- If a subspace is less than another, there is a point only in the second. -/
theorem exists_of_lt {s1 s2 : AffineSubspace k P} (h : s1 < s2) : ∃ p ∈ s2, p ∉ s1 :=
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 (s1 s2 : AffineSubspace k P) :
s1 < s2 ↔ s1 ≤ s2 ∧ ∃ p ∈ s2, p ∉ s1 := by
rw [lt_iff_le_not_le, 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⟩
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 (spanPoints_subset_coe_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 s1 _s2 :=
⟨fun h => Set.Subset.trans (subset_spanPoints k s1) h, spanPoints_subset_coe_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_spanPoints 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 affine span of a single point, coerced to a set, contains just that point. -/
@[simp 1001] -- Porting note: 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]
@[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
/-- 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)
/-- `⊤`, coerced to a set, is the whole set of points. -/
@[simp]
theorem top_coe : ((⊤ : AffineSubspace k P) : Set P) = Set.univ :=
rfl
variable {P}
/-- All points are in `⊤`. -/
@[simp]
theorem mem_top (p : P) : p ∈ (⊤ : AffineSubspace k P) :=
Set.mem_univ p
variable (P)
/-- The direction of `⊤` is the whole module as a submodule. -/
@[simp]
theorem direction_top : (⊤ : AffineSubspace k P).direction = ⊤ := by
cases' S.nonempty with p
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⟩
attribute [local instance] toAddTorsor
/-- 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' _p _v := rfl
variable {P}
/-- No points are in `⊥`. -/
theorem not_mem_bot (p : P) : p ∉ (⊥ : AffineSubspace k P) :=
Set.not_mem_empty p
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
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₂
/-- 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 inf_coe (s1 s2 : AffineSubspace k P) : (s1 ⊓ s2 : Set P) = (s1 : Set P) ∩ s2 :=
rfl
/-- 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) (s1 s2 : AffineSubspace k P) : p ∈ s1 ⊓ s2 ↔ p ∈ s1 ∧ p ∈ s2 :=
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 (s1 s2 : AffineSubspace k P) :
(s1 ⊓ s2).direction ≤ s1.direction ⊓ s2.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
/-- If one affine subspace is less than or equal to another, the same applies to their
directions. -/
theorem direction_le {s1 s2 : AffineSubspace k P} (h : s1 ≤ s2) : s1.direction ≤ s2.direction := by
simp only [direction_eq_vectorSpan, vectorSpan_def]
exact vectorSpan_mono k h
/-- If one nonempty affine subspace is less than another, the same applies to their directions -/
theorem direction_lt_of_nonempty {s1 s2 : AffineSubspace k P} (h : s1 < s2)
(hn : (s1 : Set P).Nonempty) : s1.direction < s2.direction := by
cases' hn with p hp
rw [lt_iff_le_and_exists] at h
rcases h with ⟨hle, p2, hp2, hp2s1⟩
rw [SetLike.lt_iff_le_and_exists]
use direction_le hle, p2 -ᵥ p, vsub_mem_direction hp2 (hle hp)
intro hm
rw [vsub_right_mem_direction_iff_mem hp p2] at hm
exact hp2s1 hm
/-- The sup of the directions of two affine subspaces is less than or equal to the direction of
their sup. -/
theorem sup_direction_le (s1 s2 : AffineSubspace k P) :
s1.direction ⊔ s2.direction ≤ (s1 ⊔ s2).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 : s1 ≤ s1 ⊔ s2)) hp)
(sInf_le_sInf fun p hp => Set.Subset.trans (vsub_self_mono (le_sup_right : s2 ≤ s1 ⊔ s2)) 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 {s1 s2 : AffineSubspace k P}
(h1 : (s1 : Set P).Nonempty) (h2 : (s2 : Set P).Nonempty) (he : (s1 ∩ s2 : Set P) = ∅) :
s1.direction ⊔ s2.direction < (s1 ⊔ s2).direction := by
cases' h1 with p1 hp1
cases' h2 with p2 hp2
rw [SetLike.lt_iff_le_and_exists]
use sup_direction_le s1 s2, p2 -ᵥ p1,
vsub_mem_direction ((le_sup_right : s2 ≤ s1 ⊔ s2) hp2) ((le_sup_left : s1 ≤ s1 ⊔ s2) hp1)
intro h
rw [Submodule.mem_sup] at h
rcases h with ⟨v1, hv1, v2, hv2, hv1v2⟩
rw [← sub_eq_zero, sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm v1, add_assoc, ←
vadd_vsub_assoc, ← neg_neg v2, add_comm, ← sub_eq_add_neg, ← vsub_vadd_eq_vsub_sub,
vsub_eq_zero_iff_eq] at hv1v2
refine Set.Nonempty.ne_empty ?_ he
use v1 +ᵥ p1, vadd_mem_of_mem_direction hv1 hp1
rw [hv1v2]
exact vadd_mem_of_mem_direction (Submodule.neg_mem _ hv2) hp2
/-- 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 {s1 s2 : AffineSubspace k P}
(h1 : (s1 : Set P).Nonempty) (h2 : (s2 : Set P).Nonempty)
(hd : s1.direction ⊔ s2.direction = ⊤) : ((s1 : Set P) ∩ s2).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 {s1 s2 : AffineSubspace k P}
(h1 : (s1 : Set P).Nonempty) (h2 : (s2 : Set P).Nonempty)
(hd : IsCompl s1.direction s2.direction) : ∃ p, (s1 : Set P) ∩ s2 = {p} := by
cases' inter_nonempty_of_nonempty_of_sup_direction_eq_top h1 h2 hd.sup_eq_top with p hp
use p
ext q
rw [Set.mem_singleton_iff]
constructor
· rintro ⟨hq1, hq2⟩
have hqp : q -ᵥ p ∈ s1.direction ⊓ s2.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_spanPoints _ _)
rintro p ⟨p1, hp1, v, hv, rfl⟩
exact vadd_mem_of_mem_direction hv hp1
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 ⟨p1, hp1, p2, hp2, hv⟩
simp_rw [← vsub_sub_vsub_cancel_left p1 p2 p] at hv
rw [← hv, SetLike.mem_coe, Submodule.mem_span]
exact fun m hm => Submodule.sub_mem _ (hm ⟨p2, hp2, rfl⟩) (hm ⟨p1, hp1, rfl⟩)
· rintro v ⟨p2, hp2, hv⟩
exact ⟨p, hp, p2, hp2, 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 ⟨p1, hp1, p2, hp2, hv⟩
simp_rw [← vsub_sub_vsub_cancel_right p1 p2 p] at hv
rw [← hv, SetLike.mem_coe, Submodule.mem_span]
exact fun m hm => Submodule.sub_mem _ (hm ⟨p1, hp1, rfl⟩) (hm ⟨p2, hp2, rfl⟩)
· rintro v ⟨p2, hp2, hv⟩
exact ⟨p2, hp2, 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,
Subtype.coe_mk]
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,
Subtype.coe_mk]
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⟩
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
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`. -/
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
refine Exists.elim ?_ fun (hx : x ∈ affineSpan k s) (hc : p x hx) => hc
-- Porting note: Lean couldn't infer the motive
refine affineSpan_induction (p := fun y => ∃ z, p y z) h ?_ ?_
· exact fun y hy => ⟨subset_affineSpan _ _ hy, mem y hy⟩
· exact fun c u v w hu hv hw =>
Exists.elim hu fun hu' hu =>
Exists.elim hv fun hv' hv =>
Exists.elim hw fun hw' hw =>
⟨AffineSubspace.smul_vsub_vadd_mem _ _ hu' hv' hw',
smul_vsub_vadd _ _ _ _ _ _ _ hu hv hw⟩
section WithLocalInstance
attribute [local instance] AffineSubspace.toAddTorsor
/-- 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 _ _
end WithLocalInstance
/-- 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]
/-- 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₂)
/-- 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]
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}
/-- 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]
/-- 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. -/
@[mono]
theorem affineSpan_mono {s₁ s₂ : Set P} (h : s₁ ⊆ s₂) : affineSpan k s₁ ≤ affineSpan k s₂ :=
spanPoints_subset_coe_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
show x ∈ Submodule.span k s
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
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 {s1 s2 : AffineSubspace k P} {p1 p2 : P} (hp1 : p1 ∈ s1) (hp2 : p2 ∈ s2) :
(s1 ⊔ s2).direction = s1.direction ⊔ s2.direction ⊔ k ∙ p2 -ᵥ p1 := by
refine le_antisymm ?_ ?_
· change (affineSpan k ((s1 : Set P) ∪ s2)).direction ≤ _
rw [← mem_coe] at hp1
rw [direction_affineSpan, vectorSpan_eq_span_vsub_set_right k (Set.mem_union_left _ hp1),
Submodule.span_le]
rintro v ⟨p3, hp3, rfl⟩
cases' hp3 with hp3 hp3
· rw [sup_assoc, sup_comm, SetLike.mem_coe, Submodule.mem_sup]
use 0, Submodule.zero_mem _, p3 -ᵥ p1, vsub_mem_direction hp3 hp1
rw [zero_add]
· rw [sup_assoc, SetLike.mem_coe, Submodule.mem_sup]
use 0, Submodule.zero_mem _, p3 -ᵥ p1
rw [and_comm, zero_add]
use rfl
rw [← vsub_add_vsub_cancel p3 p2 p1, Submodule.mem_sup]
use p3 -ᵥ p2, vsub_mem_direction hp3 hp2, p2 -ᵥ p1, 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_spanPoints k p2 _ (Set.mem_union_right _ hp2))
(mem_spanPoints k p1 _ (Set.mem_union_left _ hp1))))
hp
/-- 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} {p1 p2 : P} (hp1 : p1 ∈ s) :
(affineSpan k (insert p2 (s : Set P))).direction =
Submodule.span k {p2 -ᵥ p1} ⊔ s.direction := by
rw [sup_comm, ← Set.union_singleton, ← coe_affineSpan_singleton k V p2]
change (s ⊔ affineSpan k {p2}).direction = _
rw [direction_sup hp1 (mem_affineSpan k (Set.mem_singleton _)), direction_affineSpan]
simp
/-- Given a point `p1` in an affine subspace `s`, and a point `p2`, a point `p` is in the span of
`s` with `p2` added if and only if it is a multiple of `p2 -ᵥ p1` added to a point in `s`. -/
theorem mem_affineSpan_insert_iff {s : AffineSubspace k P} {p1 : P} (hp1 : p1 ∈ s) (p2 p : P) :
p ∈ affineSpan k (insert p2 (s : Set P)) ↔
∃ r : k, ∃ p0 ∈ s, p = r • (p2 -ᵥ p1 : V) +ᵥ p0 := by
rw [← mem_coe] at hp1
rw [← vsub_right_mem_direction_iff_mem (mem_affineSpan k (Set.mem_insert_of_mem _ hp1)),
direction_affineSpan_insert hp1, Submodule.mem_sup]
constructor
· rintro ⟨v1, hv1, v2, hv2, hp⟩
rw [Submodule.mem_span_singleton] at hv1
rcases hv1 with ⟨r, rfl⟩
use r, v2 +ᵥ p1, vadd_mem_of_mem_direction hv2 hp1
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, p3, hp3, rfl⟩
use r • (p2 -ᵥ p1), Submodule.mem_span_singleton.2 ⟨r, rfl⟩, p3 -ᵥ p1,
vsub_mem_direction hp3 hp1
rw [vadd_vsub_assoc]
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
rw [vectorSpan_def, vectorSpan_def, f.image_vsub_image, Submodule.span_image]
-- Porting note: Lean unfolds things too far with `simp` here.
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
-- The simpNF linter says that the LHS can be simplified via `AffineSubspace.mem_map`.
-- However this is a higher priority lemma.
-- https://github.com/leanprover/std4/issues/207
@[simp 1100, nolint simpNF]
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
rw [direction_eq_vectorSpan, direction_eq_vectorSpan, coe_map,
AffineMap.vectorSpan_image_eq_submodule_map]
-- Porting note: again, Lean unfolds too aggressively with `simp`
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⟩)
· rw [image_empty, span_empty, span_empty, map_bot]
-- Porting note: I don't know exactly why this `simp` was broken.
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)⟩
section inclusion
variable {S₁ S₂ : AffineSubspace k P₁} [Nonempty S₁] [Nonempty S₂]
attribute [local instance] AffineSubspace.toAddTorsor
/-- 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₂) : S₁ →ᵃ[k] S₂ where
toFun := Set.inclusion h
linear := Submodule.inclusion <| AffineSubspace.direction_le h
map_vadd' _ _ := 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]
end AffineMap
namespace AffineEquiv
section ofEq
variable (S₁ S₂ : AffineSubspace k P₁) [Nonempty S₁] [Nonempty S₂]
attribute [local instance] AffineSubspace.toAddTorsor
/-- 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.Set.ofEq <| congr_arg _ h
linear := .ofEq _ _ <| congr_arg _ h
map_vadd' _ _ := 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 :=
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_self, 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]
-- Porting note: more issues with `simp`
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
|
LinearAlgebra\AffineSpace\Basic.lean | /-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Algebra.AddTorsor
/-!
# 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.
-/
@[inherit_doc] scoped[Affine] notation "AffineSpace" => AddTorsor
|
LinearAlgebra\AffineSpace\Basis.lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.LinearAlgebra.AffineSpace.Independent
import Mathlib.LinearAlgebra.AffineSpace.Pointwise
import Mathlib.LinearAlgebra.Basis
/-!
# 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
open Set
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
protected toFun : ι → P
protected ind' : AffineIndependent k toFun
protected tot' : affineSpan k (range toFun) = ⊤
variable {ι ι' 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'
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
dsimp only
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, LinearEquiv.coe_coe, 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
-- Porting note:
-- in mathlib3 we didn't need to given the `fun j => j ≠ i` argument to `Subtype.coe_mk`,
-- but I don't think we can complain: this proof was over-golfed.
rw [coord, AffineMap.coe_mk, ← @Subtype.coe_mk _ (fun j => j ≠ 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_not_mem (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]
@[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]
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
|
LinearAlgebra\AffineSpace\Combination.lean | /-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Algebra.Module.BigOperators
import Mathlib.Data.Fintype.BigOperators
import Mathlib.LinearAlgebra.AffineSpace.AffineMap
import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace
import Mathlib.LinearAlgebra.Finsupp
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} := by
ext x
fin_cases x <;> simp
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]
/-- `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
erw [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 `s.filter pred`. -/
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) =
(s.filter pred).weightedVSubOfPoint p b w := by
rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_subtype_eq_sum_filter]
/-- A weighted sum over `s.filter pred` 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) :
(s.filter pred).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, LinearMap.sum_apply]
/-- `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]
/-- `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 `s.filter pred`. -/
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) =
(s.filter pred).weightedVSub p w :=
s.weightedVSubOfPoint_subtype_eq_filter _ _ _ _
/-- A weighted sum over `s.filter pred` 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) : (s.filter pred).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 only [affineCombination, weightedVSubOfPoint_apply, id, vadd_right_cancel_iff,
Function.comp_apply, AffineMap.coe_mk]
let g₁ : s → V := fun i => w (f i) • (f i -ᵥ Classical.choice S.nonempty)
let g₂ : P → V := fun i => w i • (i -ᵥ Classical.choice S.nonempty)
change univ.sum g₁ = (image f univ).sum g₂
have hgf : g₁ = g₂ ∘ f := by
ext
simp
rw [hgf, sum_image]
· simp only [Function.comp_apply]
· exact fun _ _ _ _ hxy => hf hxy
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. -/
@[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) : (s.filter (· ≠ 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 `s.filter pred`. -/
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) =
(s.filter pred).affineCombination k p w := by
rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_subtype_eq_filter]
/-- An affine combination over `s.filter pred` 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) :
(s.filter pred).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]
variable (k)
/-- Weights for expressing a single point as an affine combination. -/
def affineCombinationSingleWeights [DecidableEq ι] (i : ι) : ι → k :=
Function.update (Function.const ι 0) i 1
@[simp]
theorem affineCombinationSingleWeights_apply_self [DecidableEq ι] (i : ι) :
affineCombinationSingleWeights k i i = 1 := by simp [affineCombinationSingleWeights]
@[simp]
theorem affineCombinationSingleWeights_apply_of_ne [DecidableEq ι] {i j : ι} (h : j ≠ i) :
affineCombinationSingleWeights k i j = 0 := by simp [affineCombinationSingleWeights, 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
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 ι (card s : k)⁻¹
/-- `centroidWeights` at any point. -/
@[simp]
theorem centroidWeights_apply (i : ι) : s.centroidWeights k i = (card s : k)⁻¹ :=
rfl
/-- `centroidWeights` equals a constant function. -/
theorem centroidWeights_eq_const : s.centroidWeights k = Function.const ι (card s : k)⁻¹ :=
rfl
variable {k}
/-- 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 : (card s : k) ≠ 0) :
∑ i ∈ s, s.centroidWeights k i = 1 := by simp [h]
variable (k)
/-- 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 : card s ≠ 0) :
∑ i ∈ s, s.centroidWeights k i = 1 := by
-- Porting note: `simp` cannot find `mul_inv_cancel` and does not use `norm_cast`
simp only [centroidWeights_apply, sum_const, nsmul_eq_mul, ne_eq, Nat.cast_eq_zero, card_eq_zero]
refine mul_inv_cancel ?_
norm_cast
/-- 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 : card 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 : (card ({i₁, i₂} : Finset ι) : k) ≠ 0 := by
rw [card_insert_of_not_mem (not_mem_singleton.2 h), card_singleton]
norm_num
exact nonzero_of_invertible _
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 : card 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 : card 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 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_total,
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.total_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
cases' hn with i1 hi1
let w1 : ι → k := Function.update (Function.const ι 0) i1 1
have hw1 : ∑ i ∈ s, w1 i = 1 := by
simp only [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_same _ _ _) fun _ _ hne =>
Function.update_noteq 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
-- Porting note: Rest was `simp [Pi.sub_apply, h, hw1]`,
-- but `Pi.sub_apply` transforms the goal into nonsense
change (Finset.sum s fun i => w i - w1 i) = 0
simp only [Finset.sum_sub_distrib, h, hw1, sub_self]
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 _))
variable (k)
/-- 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_total]
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_not_mem Finsupp.not_mem_support_iff.1]
simp only [Finsupp.mem_support_iff, ne_eq, Finset.mem_insert, true_or, not_true,
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.total_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
variable {k}
/-- 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
cases' hn with i0
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 [Finset.mem_insert, true_or, not_true, 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_same _ _ _) fun _ _ hne => Function.update_noteq hne _ _
refine ⟨s', w0 + w', ?_, ?_⟩
· -- Porting note: proof was `simp [Pi.add_apply, Finset.sum_add_distrib, hw0, h']`
simp only [Pi.add_apply, Finset.sum_add_distrib, hw0, h', add_zero]
· 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]
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 [Finset.sum_update_of_mem hj, Finset.insert_eq_of_mem hj]
· simp [Finset.sum_insert hj, Finset.sum_update_of_not_mem hj, hj]
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'
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 : (card 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 : card 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 : card 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
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'⟩
-- Porting note: needed to give `Prod.mk_vadd_mk` a hint
simp [LinearMap.sum_apply, Finset.weightedVSubOfPoint, vsub_vadd_eq_vsub_sub,
vadd_vsub_assoc,
add_sub, ← sub_add_eq_add_sub, smul_add, Finset.sum_add_distrib, Prod.mk_vadd_mk v]
end AffineMap
|
LinearAlgebra\AffineSpace\ContinuousAffineEquiv.lean | /-
Copyright (c) 2024 Michael Rothgang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Rothgang
-/
import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv
import Mathlib.Topology.Algebra.Module.Basic
/-!
# Continuous affine equivalences
In this file, we define continuous affine equivalences, affine equivalences
which are continuous with continuous inverse.
## Main definitions
* `ContinuousAffineEquiv.refl k P`: the identity map as a `ContinuousAffineEquiv`;
* `e.symm`: the inverse map of a `ContinuousAffineEquiv` as a `ContinuousAffineEquiv`;
* `e.trans e'`: composition of two `ContinuousAffineEquiv`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.
* `e.toHomeomorph`: the continuous affine equivalence `e` as a homeomorphism
* `ContinuousLinearEquiv.toContinuousAffineEquiv`: a continuous linear equivalence as a continuous
affine equivalence
* `ContinuousAffineEquiv.constVAdd`: `AffineEquiv.constVAdd` as a continuous affine equivalence
## TODO
- equip `ContinuousAffineEquiv k P P` with a `Group` structure,
with multiplication corresponding to composition in `AffineEquiv.group`.
-/
open Function
/-- A continuous affine equivalence, denoted `P₁ ≃ᵃL[k] P₂`, between two affine topological spaces
is an affine equivalence such that forward and inverse maps are continuous. -/
structure ContinuousAffineEquiv (k P₁ P₂ : Type*) {V₁ V₂ : Type*} [Ring k]
[AddCommGroup V₁] [Module k V₁] [AddTorsor V₁ P₁] [TopologicalSpace P₁]
[AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂] [TopologicalSpace P₂]
extends P₁ ≃ᵃ[k] P₂ where
continuous_toFun : Continuous toFun := by continuity
continuous_invFun : Continuous invFun := by continuity
@[inherit_doc]
notation:25 P₁ " ≃ᵃL[" k:25 "] " P₂:0 => ContinuousAffineEquiv k P₁ P₂
variable {k P₁ P₂ P₃ P₄ V₁ V₂ V₃ V₄ : Type*} [Ring k]
[AddCommGroup V₁] [Module k V₁] [AddTorsor V₁ P₁]
[AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂]
[AddCommGroup V₃] [Module k V₃] [AddTorsor V₃ P₃]
[AddCommGroup V₄] [Module k V₄] [AddTorsor V₄ P₄]
[TopologicalSpace P₁]
[TopologicalSpace P₂]
[TopologicalSpace P₃] [TopologicalSpace P₄]
namespace ContinuousAffineEquiv
-- Basic set-up: standard fields, coercions and ext lemmas
section Basic
/-- A continuous affine equivalence is a homeomorphism. -/
def toHomeomorph (e : P₁ ≃ᵃL[k] P₂) : P₁ ≃ₜ P₂ where
__ := e
theorem toAffineEquiv_injective : Injective (toAffineEquiv : (P₁ ≃ᵃL[k] P₂) → P₁ ≃ᵃ[k] P₂) := by
rintro ⟨e, econt, einv_cont⟩ ⟨e', e'cont, e'inv_cont⟩ H
congr
instance instEquivLike : EquivLike (P₁ ≃ᵃL[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 _ := toAffineEquiv_injective (DFunLike.coe_injective h)
instance : CoeFun (P₁ ≃ᵃL[k] P₂) fun _ ↦ P₁ → P₂ :=
DFunLike.hasCoeToFun
attribute [coe] ContinuousAffineEquiv.toAffineEquiv
/-- Coerce continuous affine equivalences to affine equivalences. -/
instance coe : Coe (P₁ ≃ᵃL[k] P₂) (P₁ ≃ᵃ[k] P₂) := ⟨toAffineEquiv⟩
theorem coe_injective : Function.Injective ((↑) : (P₁ ≃ᵃL[k] P₂) → P₁ ≃ᵃ[k] P₂) := by
intro e e' H
cases e
congr
instance instFunLike : FunLike (P₁ ≃ᵃL[k] P₂) P₁ P₂ where
coe f := f.toAffineEquiv
coe_injective' _ _ h := coe_injective (DFunLike.coe_injective h)
@[simp, norm_cast]
theorem coe_coe (e : P₁ ≃ᵃL[k] P₂) : ⇑(e : P₁ ≃ᵃ[k] P₂) = e :=
rfl
@[simp]
theorem coe_toEquiv (e : P₁ ≃ᵃL[k] P₂) : ⇑e.toEquiv = e :=
rfl
/-- See Note [custom simps projection].
We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def Simps.apply (e : P₁ ≃ᵃL[k] P₂) : P₁ → P₂ :=
e
/-- See Note [custom simps projection]. -/
def Simps.coe (e : P₁ ≃ᵃL[k] P₂) : P₁ ≃ᵃ[k] P₂ :=
e
initialize_simps_projections ContinuousLinearMap (toAffineEquiv_toFun → apply, toAffineEquiv → coe)
@[ext]
theorem ext {e e' : P₁ ≃ᵃL[k] P₂} (h : ∀ x, e x = e' x) : e = e' :=
DFunLike.ext _ _ h
@[continuity]
protected theorem continuous (e : P₁ ≃ᵃL[k] P₂) : Continuous e :=
e.2
end Basic
section ReflSymmTrans
variable (k P₁) in
/-- Identity map as a `ContinuousAffineEquiv`. -/
def refl : P₁ ≃ᵃL[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 refl_apply (x : P₁) : refl k P₁ x = x :=
rfl
@[simp]
theorem toAffineEquiv_refl : (refl k P₁).toAffineEquiv = AffineEquiv.refl k P₁ :=
rfl
@[simp]
theorem toEquiv_refl : (refl k P₁).toEquiv = Equiv.refl P₁ :=
rfl
/-- Inverse of a continuous affine equivalence as a continuous affine equivalence. -/
@[symm]
def symm (e : P₁ ≃ᵃL[k] P₂) : P₂ ≃ᵃL[k] P₁ where
toAffineEquiv := e.toAffineEquiv.symm
continuous_toFun := e.continuous_invFun
continuous_invFun := e.continuous_toFun
@[simp]
theorem symm_toAffineEquiv (e : P₁ ≃ᵃL[k] P₂) : e.toAffineEquiv.symm = e.symm.toAffineEquiv :=
rfl
@[simp]
theorem symm_toEquiv (e : P₁ ≃ᵃL[k] P₂) : e.toEquiv.symm = e.symm.toEquiv := rfl
@[simp]
theorem apply_symm_apply (e : P₁ ≃ᵃL[k] P₂) (p : P₂) : e (e.symm p) = p :=
e.toEquiv.apply_symm_apply p
@[simp]
theorem symm_apply_apply (e : P₁ ≃ᵃL[k] P₂) (p : P₁) : e.symm (e p) = p :=
e.toEquiv.symm_apply_apply p
theorem apply_eq_iff_eq_symm_apply (e : P₁ ≃ᵃL[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₁ ≃ᵃL[k] P₂) {p₁ p₂ : P₁} : e p₁ = e p₂ ↔ p₁ = p₂ :=
e.toEquiv.apply_eq_iff_eq
@[simp]
theorem symm_symm (e : P₁ ≃ᵃL[k] P₂) : e.symm.symm = e := by
ext x
rfl
theorem symm_symm_apply (e : P₁ ≃ᵃL[k] P₂) (x : P₁) : e.symm.symm x = e x :=
rfl
theorem symm_apply_eq (e : P₁ ≃ᵃL[k] P₂) {x y} : e.symm x = y ↔ x = e y :=
e.toAffineEquiv.symm_apply_eq
theorem eq_symm_apply (e : P₁ ≃ᵃL[k] P₂) {x y} : y = e.symm x ↔ e y = x :=
e.toAffineEquiv.eq_symm_apply
@[simp]
theorem image_symm (f : P₁ ≃ᵃL[k] P₂) (s : Set P₂) : f.symm '' s = f ⁻¹' s :=
f.symm.toEquiv.image_eq_preimage _
@[simp]
theorem preimage_symm (f : P₁ ≃ᵃL[k] P₂) (s : Set P₁) : f.symm ⁻¹' s = f '' s :=
(f.symm.image_symm _).symm
protected theorem bijective (e : P₁ ≃ᵃL[k] P₂) : Bijective e :=
e.toEquiv.bijective
protected theorem surjective (e : P₁ ≃ᵃL[k] P₂) : Surjective e :=
e.toEquiv.surjective
protected theorem injective (e : P₁ ≃ᵃL[k] P₂) : Injective e :=
e.toEquiv.injective
protected theorem image_eq_preimage (e : P₁ ≃ᵃL[k] P₂) (s : Set P₁) : e '' s = e.symm ⁻¹' s :=
e.toEquiv.image_eq_preimage s
protected theorem image_symm_eq_preimage (e : P₁ ≃ᵃL[k] P₂) (s : Set P₂) :
e.symm '' s = e ⁻¹' s := by
rw [e.symm.image_eq_preimage, e.symm_symm]
@[simp]
theorem image_preimage (e : P₁ ≃ᵃL[k] P₂) (s : Set P₂) : e '' (e ⁻¹' s) = s :=
e.surjective.image_preimage s
@[simp]
theorem preimage_image (e : P₁ ≃ᵃL[k] P₂) (s : Set P₁) : e ⁻¹' (e '' s) = s :=
e.injective.preimage_image s
theorem symm_image_image (e : P₁ ≃ᵃL[k] P₂) (s : Set P₁) : e.symm '' (e '' s) = s :=
e.toEquiv.symm_image_image s
theorem image_symm_image (e : P₁ ≃ᵃL[k] P₂) (s : Set P₂) : e '' (e.symm '' s) = s :=
e.symm.symm_image_image s
@[simp]
theorem refl_symm : (refl k P₁).symm = refl k P₁ :=
rfl
@[simp]
theorem symm_refl : (refl k P₁).symm = refl k P₁ :=
rfl
/-- Composition of two `ContinuousAffineEquiv`alences, applied left to right. -/
@[trans]
def trans (e : P₁ ≃ᵃL[k] P₂) (e' : P₂ ≃ᵃL[k] P₃) : P₁ ≃ᵃL[k] P₃ where
toAffineEquiv := e.toAffineEquiv.trans e'.toAffineEquiv
continuous_toFun := e'.continuous_toFun.comp (e.continuous_toFun)
continuous_invFun := e.continuous_invFun.comp (e'.continuous_invFun)
@[simp]
theorem coe_trans (e : P₁ ≃ᵃL[k] P₂) (e' : P₂ ≃ᵃL[k] P₃) : ⇑(e.trans e') = e' ∘ e :=
rfl
@[simp]
theorem trans_apply (e : P₁ ≃ᵃL[k] P₂) (e' : P₂ ≃ᵃL[k] P₃) (p : P₁) : e.trans e' p = e' (e p) :=
rfl
theorem trans_assoc (e₁ : P₁ ≃ᵃL[k] P₂) (e₂ : P₂ ≃ᵃL[k] P₃) (e₃ : P₃ ≃ᵃL[k] P₄) :
(e₁.trans e₂).trans e₃ = e₁.trans (e₂.trans e₃) :=
ext fun _ ↦ rfl
@[simp]
theorem trans_refl (e : P₁ ≃ᵃL[k] P₂) : e.trans (refl k P₂) = e :=
ext fun _ ↦ rfl
@[simp]
theorem refl_trans (e : P₁ ≃ᵃL[k] P₂) : (refl k P₁).trans e = e :=
ext fun _ ↦ rfl
@[simp]
theorem self_trans_symm (e : P₁ ≃ᵃL[k] P₂) : e.trans e.symm = refl k P₁ :=
ext e.symm_apply_apply
@[simp]
theorem symm_trans_self (e : P₁ ≃ᵃL[k] P₂) : e.symm.trans e = refl k P₂ :=
ext e.apply_symm_apply
end ReflSymmTrans
section
variable {E F : Type*} [AddCommGroup E] [Module k E] [TopologicalSpace E]
[AddCommGroup F] [Module k F] [TopologicalSpace F]
/-- Reinterpret a continuous linear equivalence between modules
as a continuous affine equivalence. -/
def _root_.ContinuousLinearEquiv.toContinuousAffineEquiv (L : E ≃L[k] F) : E ≃ᵃL[k] F where
toAffineEquiv := L.toAffineEquiv
continuous_toFun := L.continuous_toFun
continuous_invFun := L.continuous_invFun
@[simp]
theorem _root_.ContinuousLinearEquiv.coe_toContinuousAffineEquiv (e : E ≃L[k] F) :
⇑e.toContinuousAffineEquiv = e :=
rfl
variable (k P₁) in
/-- The map `p ↦ v +ᵥ p` as a continuous affine automorphism of an affine space
on which addition is continuous. -/
def constVAdd [ContinuousConstVAdd V₁ P₁] (v : V₁) : P₁ ≃ᵃL[k] P₁ where
toAffineEquiv := AffineEquiv.constVAdd k P₁ v
continuous_toFun := continuous_const_vadd v
continuous_invFun := continuous_const_vadd (-v)
lemma constVAdd_coe [ContinuousConstVAdd V₁ P₁] (v : V₁) :
(constVAdd k P₁ v).toAffineEquiv = .constVAdd k P₁ v := rfl
end
end ContinuousAffineEquiv
|
LinearAlgebra\AffineSpace\FiniteDimensional.lean | /-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Init.Core
import Mathlib.LinearAlgebra.AffineSpace.Basis
import Mathlib.LinearAlgebra.FiniteDimensional
/-!
# 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
section AffineSpace'
variable (k : Type*) {V : Type*} {P : Type*}
variable {ι : Type*}
open AffineSubspace FiniteDimensional 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 `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 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 `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 : Finset.card 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).card = 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 : (Finset.image (fun p : P => p -ᵥ p₁) ((Finset.image p s).erase p₁)).card = 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 : Finset.card 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]
cases' hn with i₁
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 ι ≤ FiniteDimensional.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.card ≤ t.card := 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_le_finrank_of_le 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.card < t.card := by
obtain rfl | hs' := s.eq_empty_or_nonempty
· simpa [card_pos] using hst
obtain rfl | ht' := t.eq_empty_or_nonempty
· simp [Set.subset_empty_iff] 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 : Finset.card s = finrank k sm + 1) :
vectorSpan k (s.image p : Set P) = sm :=
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 :=
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 : Finset.card 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
/-- 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₁ :=
(rank_le_of_submodule (vectorSpan k s₁) (vectorSpan k s₂) (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)
/-- 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
cases' hp with hp hp
· use 0
simp [hp]
· use 1
simp [hp]
variable {k}
/-- 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_emptyc_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
-- Porting note: Originally `by decide!`
fin_cases i₁ <;> fin_cases i₂ <;> fin_cases i₃
<;> simp (config := {decide := true}) only at h₁₂ h₁₃ h₂₃ ⊢
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
-- Porting note: Original proof used `conv_lhs` and `conv_rhs`, but these tactics timed out.
rw [← direction_affineSpan, ← affineSpan_insert_affineSpan]
symm
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 ?_
repeat apply Set.insert_subset_insert
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 ?_
simp [Set.insert_subset_insert]
variable (k)
/-- 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
variable {k}
/-- 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₁ :=
(rank_le_of_submodule (vectorSpan k s₁) (vectorSpan k s₂) (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 FiniteDimensional 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
have : FiniteDimensional k s.direction := hf
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)
/-- 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]
refine (finrank_vectorSpan_insert_le _ _).trans (add_le_add_right ?_ _)
rw [direction_affineSpan]
variable {k}
/-- 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
rw [coplanar_iff_finrank_le_two]
exact (finrank_vectorSpan_insert_le_set k s p).trans (add_le_add_right 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
FiniteDimensional.of_fintype_basis (b.basisOf i)
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 ι = FiniteDimensional.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 ι = FiniteDimensional.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
|
LinearAlgebra\AffineSpace\Independent.lean | /-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Data.Finset.Sort
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Sign
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. A bundled type `Simplex` is provided for finite
affinely independent families of points, with an abbreviation
`Triangle` for the case of three points.
## References
* https://en.wikipedia.org/wiki/Affine_space
-/
noncomputable section
open Finset Function
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 (config := { contextual := true }) [AffineIndependent, weightedVSub_vadd]
protected alias ⟨AffineIndependent.of_vadd, AffineIndependent.vadd⟩ := affineIndependent_vadd
/-- 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
intro x
rw [hfdef]
dsimp only
erw [dif_neg x.property, Subtype.coe_eta]
rw [hfg]
have hf : ∑ ι ∈ s2, f ι = 0 := by
rw [Finset.sum_insert
(Finset.not_mem_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_self _
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.not_mem_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
· rw [← Finset.mem_coe, Finset.coe_union] at hi
have h₁ : Set.indicator (↑s1) w1 i = 0 := by
simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff]
intro h
by_contra
exact (mt (@Set.mem_union_left _ i ↑s1 ↑s2) hi) h
have h₂ : Set.indicator (↑s2) w2 i = 0 := by
simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff]
intro h
by_contra
exact (mt (@Set.mem_union_right _ i ↑s2 ↑s1) hi) h
simp [h₁, h₂]
· 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_same _ _ _)
fun _ _ hne => Function.update_noteq 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, EmbeddingLike.apply_eq_iff_eq, exists_eq, dite_true]
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)
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
cases' isEmpty_or_nonempty ι with h h
· haveI := 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
cases' isEmpty_or_nonempty ι with h h
· haveI := 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
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [← e.affineIndependent_iff, this, affineIndependent_equiv]
end Composition
/-- 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
rw [Set.image_eq_range] at hp0s1 hp0s2
rw [mem_affineSpan_iff_eq_affineCombination, ←
Finset.eq_affineCombination_subset_iff_eq_affineCombination_subtype] at hp0s1 hp0s2
rcases hp0s1 with ⟨fs1, hfs1, w1, hw1, hp0s1⟩
rcases hp0s2 with ⟨fs2, hfs2, w2, hw2, hp0s2⟩
rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq] at ha
replace ha := ha fs1 fs2 w1 w2 hw1 hw2 (hp0s1 ▸ hp0s2)
have hnz : ∑ i ∈ fs1, w1 i ≠ 0 := hw1.symm ▸ one_ne_zero
rcases Finset.exists_ne_zero_of_sum_ne_zero hnz with ⟨i, hifs1, hinz⟩
simp_rw [← Set.indicator_of_mem (Finset.mem_coe.2 hifs1) w1, ha] at hinz
use i, hfs1 hifs1
exact hfs2 (Set.mem_of_indicator_ne_zero hinz)
/-- 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 => ?_
cases' ha.exists_mem_inter_of_exists_mem_inter_affineSpan hp0s1 hp0s2 with i hi
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.not_mem_affineSpan_diff [Nontrivial k] {p : ι → P}
(ha : AffineIndependent k p) (i : ι) (s : Set ι) : p i ∉ affineSpan k (p '' (s \ {i})) := by
simp [ha]
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 [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 [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
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_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_subset _ 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, coe_affineSpan]
exact ⟨mem_spanPoints k _ _ (Set.mem_insert p _), mem_spanPoints 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 norm_num⟩
have he' : ∀ i, i = i₁ := by
rintro ⟨i, hi⟩
ext
fin_cases i
· simp at hi
· simp only [Fin.val_one]
haveI : Unique { x // x ≠ (0 : Fin 2) } := ⟨⟨i₁⟩, he'⟩
apply linearIndependent_unique
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_not_mem_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
simp_rw [Classical.not_not] at hwm
-- Porting note: this `erw` used to be part of the `simp_rw`
erw [Finset.filter_eq'] at hwm
simp_rw [if_pos his.1, Finset.sum_singleton, hwmi, ← sub_eq_add_neg, sub_eq_zero] at hwm
exact 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)
/-- 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_not_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
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_not_mem_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 (config := {decide := true}) [hp₁, hp₂]
/-- 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_not_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 (1 : Fin 3) 2)]
convert affineIndependent_of_ne_of_mem_of_mem_of_not_mem hp₁p₃ hp₁ hp₃ hp₂ using 1
ext x
fin_cases x <;> rfl
/-- If distinct points `p₂` and `p₃` lie in `s` but `p₁` does not, the three points are affinely
independent. -/
theorem affineIndependent_of_ne_of_not_mem_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_not_mem hp₂p₃.symm hp₃ hp₂ hp₁ using 1
ext x
fin_cases x <;> rfl
end DivisionRing
section Ordered
variable {k : Type*} {V : Type*} {P : Type*} [LinearOrderedRing k] [AddCommGroup V]
variable [Module k V] [AffineSpace V P] {ι : Type*}
attribute [local instance] LinearOrderedRing.decidableLT
/-- 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
namespace Affine
variable (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V]
variable [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}
/-- 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⟩
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.card = 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.card = 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.card = 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 only [Affine.Simplex.mkOfPoint_points, Affine.Simplex.face_points]
-- Porting note: `simp` can't use the next lemma
rw [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.card = m + 1) : Set.range (s.face h).points = s.points '' ↑fs := by
rw [face_points', Set.range_comp, Finset.range_orderEmbOfFin]
/-- 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]
end Simplex
end Affine
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.card = 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₁.card = m₁ + 1) (h₂ : fs₂.card = 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, Function.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₁.card = m₁ + 1) (h₂ : fs₂.card = 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
|
LinearAlgebra\AffineSpace\Matrix.lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.LinearAlgebra.AffineSpace.Basis
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
/-!
# Matrix results for barycentric co-ordinates
Results about the matrix of barycentric co-ordinates for a family of points in an affine space, with
respect to some affine basis.
-/
open Affine Matrix
open Set
universe u₁ u₂ u₃ u₄
variable {ι : Type u₁} {k : Type u₂} {V : Type u₃} {P : Type u₄}
variable [AddCommGroup V] [AffineSpace V P]
namespace AffineBasis
section Ring
variable [Ring k] [Module k V] (b : AffineBasis ι k P)
/-- Given an affine basis `p`, and a family of points `q : ι' → P`, this is the matrix whose
rows are the barycentric coordinates of `q` with respect to `p`.
It is an affine equivalent of `Basis.toMatrix`. -/
noncomputable def toMatrix {ι' : Type*} (q : ι' → P) : Matrix ι' ι k :=
fun i j => b.coord j (q i)
@[simp]
theorem toMatrix_apply {ι' : Type*} (q : ι' → P) (i : ι') (j : ι) :
b.toMatrix q i j = b.coord j (q i) := rfl
@[simp]
theorem toMatrix_self [DecidableEq ι] : b.toMatrix b = (1 : Matrix ι ι k) := by
ext i j
rw [toMatrix_apply, coord_apply, Matrix.one_eq_pi_single, Pi.single_apply]
variable {ι' : Type*}
theorem toMatrix_row_sum_one [Fintype ι] (q : ι' → P) (i : ι') : ∑ j, b.toMatrix q i j = 1 := by
simp
/-- Given a family of points `p : ι' → P` and an affine basis `b`, if the matrix whose rows are the
coordinates of `p` with respect `b` has a right inverse, then `p` is affine independent. -/
theorem affineIndependent_of_toMatrix_right_inv [Fintype ι] [Finite ι'] [DecidableEq ι']
(p : ι' → P) {A : Matrix ι ι' k} (hA : b.toMatrix p * A = 1) : AffineIndependent k p := by
cases nonempty_fintype ι'
rw [affineIndependent_iff_eq_of_fintype_affineCombination_eq]
intro w₁ w₂ hw₁ hw₂ hweq
have hweq' : w₁ ᵥ* b.toMatrix p = w₂ ᵥ* b.toMatrix p := by
ext j
change (∑ i, w₁ i • b.coord j (p i)) = ∑ i, w₂ i • b.coord j (p i)
-- Porting note: Added `u` because `∘` was causing trouble
have u : (fun i => b.coord j (p i)) = b.coord j ∘ p := by simp only [(· ∘ ·)]
rw [← Finset.univ.affineCombination_eq_linear_combination _ _ hw₁,
← Finset.univ.affineCombination_eq_linear_combination _ _ hw₂, u,
← Finset.univ.map_affineCombination p w₁ hw₁, ← Finset.univ.map_affineCombination p w₂ hw₂,
hweq]
replace hweq' := congr_arg (fun w => w ᵥ* A) hweq'
simpa only [Matrix.vecMul_vecMul, hA, Matrix.vecMul_one] using hweq'
/-- Given a family of points `p : ι' → P` and an affine basis `b`, if the matrix whose rows are the
coordinates of `p` with respect `b` has a left inverse, then `p` spans the entire space. -/
theorem affineSpan_eq_top_of_toMatrix_left_inv [Finite ι] [Fintype ι'] [DecidableEq ι]
[Nontrivial k] (p : ι' → P) {A : Matrix ι ι' k} (hA : A * b.toMatrix p = 1) :
affineSpan k (range p) = ⊤ := by
cases nonempty_fintype ι
suffices ∀ i, b i ∈ affineSpan k (range p) by
rw [eq_top_iff, ← b.tot, affineSpan_le]
rintro q ⟨i, rfl⟩
exact this i
intro i
have hAi : ∑ j, A i j = 1 := by
calc
∑ j, A i j = ∑ j, A i j * ∑ l, b.toMatrix p j l := by simp
_ = ∑ j, ∑ l, A i j * b.toMatrix p j l := by simp_rw [Finset.mul_sum]
_ = ∑ l, ∑ j, A i j * b.toMatrix p j l := by rw [Finset.sum_comm]
_ = ∑ l, (A * b.toMatrix p) i l := rfl
_ = 1 := by simp [hA, Matrix.one_apply, Finset.filter_eq]
have hbi : b i = Finset.univ.affineCombination k p (A i) := by
apply b.ext_elem
intro j
rw [b.coord_apply, Finset.univ.map_affineCombination _ _ hAi,
Finset.univ.affineCombination_eq_linear_combination _ _ hAi]
change _ = (A * b.toMatrix p) i j
simp_rw [hA, Matrix.one_apply, @eq_comm _ i j]
rw [hbi]
exact affineCombination_mem_affineSpan hAi p
variable [Fintype ι] (b₂ : AffineBasis ι k P)
/-- A change of basis formula for barycentric coordinates.
See also `AffineBasis.toMatrix_inv_vecMul_toMatrix`. -/
@[simp]
theorem toMatrix_vecMul_coords (x : P) : b₂.coords x ᵥ* b.toMatrix b₂ = b.coords x := by
ext j
change _ = b.coord j x
conv_rhs => rw [← b₂.affineCombination_coord_eq_self x]
rw [Finset.map_affineCombination _ _ _ (b₂.sum_coord_apply_eq_one x)]
simp [Matrix.vecMul, Matrix.dotProduct, toMatrix_apply, coords]
variable [DecidableEq ι]
theorem toMatrix_mul_toMatrix : b.toMatrix b₂ * b₂.toMatrix b = 1 := by
ext l m
change (b.coords (b₂ l) ᵥ* b₂.toMatrix b) m = _
rw [toMatrix_vecMul_coords, coords_apply, ← toMatrix_apply, toMatrix_self]
theorem isUnit_toMatrix : IsUnit (b.toMatrix b₂) :=
⟨{ val := b.toMatrix b₂
inv := b₂.toMatrix b
val_inv := b.toMatrix_mul_toMatrix b₂
inv_val := b₂.toMatrix_mul_toMatrix b }, rfl⟩
theorem isUnit_toMatrix_iff [Nontrivial k] (p : ι → P) :
IsUnit (b.toMatrix p) ↔ AffineIndependent k p ∧ affineSpan k (range p) = ⊤ := by
constructor
· rintro ⟨⟨B, A, hA, hA'⟩, rfl : B = b.toMatrix p⟩
exact ⟨b.affineIndependent_of_toMatrix_right_inv p hA,
b.affineSpan_eq_top_of_toMatrix_left_inv p hA'⟩
· rintro ⟨h_tot, h_ind⟩
let b' : AffineBasis ι k P := ⟨p, h_tot, h_ind⟩
change IsUnit (b.toMatrix b')
exact b.isUnit_toMatrix b'
end Ring
section CommRing
variable [CommRing k] [Module k V] [DecidableEq ι] [Fintype ι]
variable (b b₂ : AffineBasis ι k P)
/-- A change of basis formula for barycentric coordinates.
See also `AffineBasis.toMatrix_vecMul_coords`. -/
@[simp]
theorem toMatrix_inv_vecMul_toMatrix (x : P) :
b.coords x ᵥ* (b.toMatrix b₂)⁻¹ = b₂.coords x := by
have hu := b.isUnit_toMatrix b₂
rw [Matrix.isUnit_iff_isUnit_det] at hu
rw [← b.toMatrix_vecMul_coords b₂, Matrix.vecMul_vecMul, Matrix.mul_nonsing_inv _ hu,
Matrix.vecMul_one]
/-- If we fix a background affine basis `b`, then for any other basis `b₂`, we can characterise
the barycentric coordinates provided by `b₂` in terms of determinants relative to `b`. -/
theorem det_smul_coords_eq_cramer_coords (x : P) :
(b.toMatrix b₂).det • b₂.coords x = (b.toMatrix b₂)ᵀ.cramer (b.coords x) := by
have hu := b.isUnit_toMatrix b₂
rw [Matrix.isUnit_iff_isUnit_det] at hu
rw [← b.toMatrix_inv_vecMul_toMatrix, Matrix.det_smul_inv_vecMul_eq_cramer_transpose _ _ hu]
end CommRing
end AffineBasis
|
LinearAlgebra\AffineSpace\Midpoint.lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv
/-!
# Midpoint of a segment
## Main definitions
* `midpoint R x y`: midpoint of the segment `[x, y]`. We define it for `x` and `y`
in a module over a ring `R` with invertible `2`.
* `AddMonoidHom.ofMapMidpoint`: construct an `AddMonoidHom` given a map `f` such that
`f` sends zero to zero and midpoints to midpoints.
## Main theorems
* `midpoint_eq_iff`: `z` is the midpoint of `[x, y]` if and only if `x + y = z + z`,
* `midpoint_unique`: `midpoint R x y` does not depend on `R`;
* `midpoint x y` is linear both in `x` and `y`;
* `pointReflection_midpoint_left`, `pointReflection_midpoint_right`:
`Equiv.pointReflection (midpoint R x y)` swaps `x` and `y`.
We do not mark most lemmas as `@[simp]` because it is hard to tell which side is simpler.
## Tags
midpoint, AddMonoidHom
-/
open AffineMap AffineEquiv
section
variable (R : Type*) {V V' P P' : Type*} [Ring R] [Invertible (2 : R)] [AddCommGroup V]
[Module R V] [AddTorsor V P] [AddCommGroup V'] [Module R V'] [AddTorsor V' P']
/-- `midpoint x y` is the midpoint of the segment `[x, y]`. -/
def midpoint (x y : P) : P :=
lineMap x y (⅟ 2 : R)
variable {R} {x y z : P}
@[simp]
theorem AffineMap.map_midpoint (f : P →ᵃ[R] P') (a b : P) :
f (midpoint R a b) = midpoint R (f a) (f b) :=
f.apply_lineMap a b _
@[simp]
theorem AffineEquiv.map_midpoint (f : P ≃ᵃ[R] P') (a b : P) :
f (midpoint R a b) = midpoint R (f a) (f b) :=
f.apply_lineMap a b _
theorem AffineEquiv.pointReflection_midpoint_left (x y : P) :
pointReflection R (midpoint R x y) x = y := by
rw [midpoint, pointReflection_apply, lineMap_apply, vadd_vsub, vadd_vadd, ← add_smul, ← two_mul,
mul_invOf_self, one_smul, vsub_vadd]
@[simp] -- Porting note: added variant with `Equiv.pointReflection` for `simp`
theorem Equiv.pointReflection_midpoint_left (x y : P) :
(Equiv.pointReflection (midpoint R x y)) x = y := by
rw [midpoint, pointReflection_apply, lineMap_apply, vadd_vsub, vadd_vadd, ← add_smul, ← two_mul,
mul_invOf_self, one_smul, vsub_vadd]
theorem midpoint_comm (x y : P) : midpoint R x y = midpoint R y x := by
rw [midpoint, ← lineMap_apply_one_sub, one_sub_invOf_two, midpoint]
theorem AffineEquiv.pointReflection_midpoint_right (x y : P) :
pointReflection R (midpoint R x y) y = x := by
rw [midpoint_comm, AffineEquiv.pointReflection_midpoint_left]
@[simp] -- Porting note: added variant with `Equiv.pointReflection` for `simp`
theorem Equiv.pointReflection_midpoint_right (x y : P) :
(Equiv.pointReflection (midpoint R x y)) y = x := by
rw [midpoint_comm, Equiv.pointReflection_midpoint_left]
theorem midpoint_vsub_midpoint (p₁ p₂ p₃ p₄ : P) :
midpoint R p₁ p₂ -ᵥ midpoint R p₃ p₄ = midpoint R (p₁ -ᵥ p₃) (p₂ -ᵥ p₄) :=
lineMap_vsub_lineMap _ _ _ _ _
theorem midpoint_vadd_midpoint (v v' : V) (p p' : P) :
midpoint R v v' +ᵥ midpoint R p p' = midpoint R (v +ᵥ p) (v' +ᵥ p') :=
lineMap_vadd_lineMap _ _ _ _ _
theorem midpoint_eq_iff {x y z : P} : midpoint R x y = z ↔ pointReflection R z x = y :=
eq_comm.trans
((injective_pointReflection_left_of_module R x).eq_iff'
(AffineEquiv.pointReflection_midpoint_left x y)).symm
@[simp]
theorem midpoint_pointReflection_left (x y : P) :
midpoint R (Equiv.pointReflection x y) y = x :=
midpoint_eq_iff.2 <| Equiv.pointReflection_involutive _ _
@[simp]
theorem midpoint_pointReflection_right (x y : P) :
midpoint R y (Equiv.pointReflection x y) = x :=
midpoint_eq_iff.2 rfl
@[simp]
theorem midpoint_vsub_left (p₁ p₂ : P) : midpoint R p₁ p₂ -ᵥ p₁ = (⅟ 2 : R) • (p₂ -ᵥ p₁) :=
lineMap_vsub_left _ _ _
@[simp]
theorem midpoint_vsub_right (p₁ p₂ : P) : midpoint R p₁ p₂ -ᵥ p₂ = (⅟ 2 : R) • (p₁ -ᵥ p₂) := by
rw [midpoint_comm, midpoint_vsub_left]
@[simp]
theorem left_vsub_midpoint (p₁ p₂ : P) : p₁ -ᵥ midpoint R p₁ p₂ = (⅟ 2 : R) • (p₁ -ᵥ p₂) :=
left_vsub_lineMap _ _ _
@[simp]
theorem right_vsub_midpoint (p₁ p₂ : P) : p₂ -ᵥ midpoint R p₁ p₂ = (⅟ 2 : R) • (p₂ -ᵥ p₁) := by
rw [midpoint_comm, left_vsub_midpoint]
theorem midpoint_vsub (p₁ p₂ p : P) :
midpoint R p₁ p₂ -ᵥ p = (⅟ 2 : R) • (p₁ -ᵥ p) + (⅟ 2 : R) • (p₂ -ᵥ p) := by
rw [← vsub_sub_vsub_cancel_right p₁ p p₂, smul_sub, sub_eq_add_neg, ← smul_neg,
neg_vsub_eq_vsub_rev, add_assoc, invOf_two_smul_add_invOf_two_smul, ← vadd_vsub_assoc,
midpoint_comm, midpoint, lineMap_apply]
theorem vsub_midpoint (p₁ p₂ p : P) :
p -ᵥ midpoint R p₁ p₂ = (⅟ 2 : R) • (p -ᵥ p₁) + (⅟ 2 : R) • (p -ᵥ p₂) := by
rw [← neg_vsub_eq_vsub_rev, midpoint_vsub, neg_add, ← smul_neg, ← smul_neg, neg_vsub_eq_vsub_rev,
neg_vsub_eq_vsub_rev]
@[simp]
theorem midpoint_sub_left (v₁ v₂ : V) : midpoint R v₁ v₂ - v₁ = (⅟ 2 : R) • (v₂ - v₁) :=
midpoint_vsub_left v₁ v₂
@[simp]
theorem midpoint_sub_right (v₁ v₂ : V) : midpoint R v₁ v₂ - v₂ = (⅟ 2 : R) • (v₁ - v₂) :=
midpoint_vsub_right v₁ v₂
@[simp]
theorem left_sub_midpoint (v₁ v₂ : V) : v₁ - midpoint R v₁ v₂ = (⅟ 2 : R) • (v₁ - v₂) :=
left_vsub_midpoint v₁ v₂
@[simp]
theorem right_sub_midpoint (v₁ v₂ : V) : v₂ - midpoint R v₁ v₂ = (⅟ 2 : R) • (v₂ - v₁) :=
right_vsub_midpoint v₁ v₂
variable (R)
@[simp]
theorem midpoint_eq_left_iff {x y : P} : midpoint R x y = x ↔ x = y := by
rw [midpoint_eq_iff, pointReflection_self]
@[simp]
theorem left_eq_midpoint_iff {x y : P} : x = midpoint R x y ↔ x = y := by
rw [eq_comm, midpoint_eq_left_iff]
@[simp]
theorem midpoint_eq_right_iff {x y : P} : midpoint R x y = y ↔ x = y := by
rw [midpoint_comm, midpoint_eq_left_iff, eq_comm]
@[simp]
theorem right_eq_midpoint_iff {x y : P} : y = midpoint R x y ↔ x = y := by
rw [eq_comm, midpoint_eq_right_iff]
theorem midpoint_eq_midpoint_iff_vsub_eq_vsub {x x' y y' : P} :
midpoint R x y = midpoint R x' y' ↔ x -ᵥ x' = y' -ᵥ y := by
rw [← @vsub_eq_zero_iff_eq V, midpoint_vsub_midpoint, midpoint_eq_iff, pointReflection_apply,
vsub_eq_sub, zero_sub, vadd_eq_add, add_zero, neg_eq_iff_eq_neg, neg_vsub_eq_vsub_rev]
theorem midpoint_eq_iff' {x y z : P} : midpoint R x y = z ↔ Equiv.pointReflection z x = y :=
midpoint_eq_iff
/-- `midpoint` does not depend on the ring `R`. -/
theorem midpoint_unique (R' : Type*) [Ring R'] [Invertible (2 : R')] [Module R' V] (x y : P) :
midpoint R x y = midpoint R' x y :=
(midpoint_eq_iff' R).2 <| (midpoint_eq_iff' R').1 rfl
@[simp]
theorem midpoint_self (x : P) : midpoint R x x = x :=
lineMap_same_apply _ _
@[simp]
theorem midpoint_add_self (x y : V) : midpoint R x y + midpoint R x y = x + y :=
calc
midpoint R x y +ᵥ midpoint R x y = midpoint R x y +ᵥ midpoint R y x := by rw [midpoint_comm]
_ = x + y := by rw [midpoint_vadd_midpoint, vadd_eq_add, vadd_eq_add, add_comm, midpoint_self]
theorem midpoint_zero_add (x y : V) : midpoint R 0 (x + y) = midpoint R x y :=
(midpoint_eq_midpoint_iff_vsub_eq_vsub R).2 <| by simp [sub_add_eq_sub_sub_swap]
theorem midpoint_eq_smul_add (x y : V) : midpoint R x y = (⅟ 2 : R) • (x + y) := by
rw [midpoint_eq_iff, pointReflection_apply, vsub_eq_sub, vadd_eq_add, sub_add_eq_add_sub, ←
two_smul R, smul_smul, mul_invOf_self, one_smul, add_sub_cancel_left]
@[simp]
theorem midpoint_self_neg (x : V) : midpoint R x (-x) = 0 := by
rw [midpoint_eq_smul_add, add_neg_self, smul_zero]
@[simp]
theorem midpoint_neg_self (x : V) : midpoint R (-x) x = 0 := by simpa using midpoint_self_neg R (-x)
@[simp]
theorem midpoint_sub_add (x y : V) : midpoint R (x - y) (x + y) = x := by
rw [sub_eq_add_neg, ← vadd_eq_add, ← vadd_eq_add, ← midpoint_vadd_midpoint]; simp
@[simp]
theorem midpoint_add_sub (x y : V) : midpoint R (x + y) (x - y) = x := by
rw [midpoint_comm]; simp
end
namespace AddMonoidHom
variable (R R' : Type*) {E F : Type*} [Ring R] [Invertible (2 : R)] [AddCommGroup E] [Module R E]
[Ring R'] [Invertible (2 : R')] [AddCommGroup F] [Module R' F]
/-- A map `f : E → F` sending zero to zero and midpoints to midpoints is an `AddMonoidHom`. -/
def ofMapMidpoint (f : E → F) (h0 : f 0 = 0)
(hm : ∀ x y, f (midpoint R x y) = midpoint R' (f x) (f y)) : E →+ F where
toFun := f
map_zero' := h0
map_add' x y :=
calc
f (x + y) = f 0 + f (x + y) := by rw [h0, zero_add]
_ = midpoint R' (f 0) (f (x + y)) + midpoint R' (f 0) (f (x + y)) :=
(midpoint_add_self _ _ _).symm
_ = f (midpoint R x y) + f (midpoint R x y) := by rw [← hm, midpoint_zero_add]
_ = f x + f y := by rw [hm, midpoint_add_self]
@[simp]
theorem coe_ofMapMidpoint (f : E → F) (h0 : f 0 = 0)
(hm : ∀ x y, f (midpoint R x y) = midpoint R' (f x) (f y)) :
⇑(ofMapMidpoint R R' f h0 hm) = f :=
rfl
end AddMonoidHom
|
LinearAlgebra\AffineSpace\MidpointZero.lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
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*} [Field 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
|
LinearAlgebra\AffineSpace\Ordered.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Algebra.CharP.Invertible
import Mathlib.Algebra.Order.Invertible
import Mathlib.Algebra.Order.Module.OrderedSMul
import Mathlib.Algebra.Order.Group.Instances
import Mathlib.LinearAlgebra.AffineSpace.Slope
import Mathlib.LinearAlgebra.AffineSpace.Midpoint
import Mathlib.Tactic.FieldSimp
/-!
# 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 [OrderedRing k] [OrderedAddCommGroup E] [Module k E] [OrderedSMul 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]
exact add_le_add_right (smul_le_smul_of_nonneg_left ha (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]
exact add_lt_add_right (smul_lt_smul_of_pos_left ha (sub_pos.2 hr)) _
theorem lineMap_mono_right (hb : b ≤ b') (hr : 0 ≤ r) : lineMap a b r ≤ lineMap a b' r := by
simp only [lineMap_apply_module]
exact add_le_add_left (smul_le_smul_of_nonneg_left hb hr) _
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]
exact add_lt_add_left (smul_lt_smul_of_pos_left hb hr) _
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₀)
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 [LinearOrderedRing k] [OrderedAddCommGroup E] [Module k E] [OrderedSMul k E]
[Invertible (2 : k)] {a a' b b' : E} {r r' : k}
theorem midpoint_le_midpoint (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 [LinearOrderedField k] [OrderedAddCommGroup E]
variable [Module k E] [OrderedSMul 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 <| inv_lt_one one_lt_two
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 <| inv_lt_one one_lt_two
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
/-- 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
/-- 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
|
LinearAlgebra\AffineSpace\Pointwise.lean | /-
Copyright (c) 2022 Hanting Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hanting Zhang
-/
import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace
/-! # Pointwise instances on `AffineSubspace`s
This file provides the additive action `AffineSubspace.pointwiseAddAction` in the
`Pointwise` locale.
-/
open Affine Pointwise
open Set
variable {k : Type*} [Ring k]
variable {V P V₁ P₁ V₂ P₂ : Type*}
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₂]
namespace AffineSubspace
/-- 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) where
vadd x S := S.map (AffineEquiv.constVAdd k P x)
zero_vadd p := ((congr_arg fun f => p.map f) <| AffineMap.ext <| zero_vadd _).trans p.map_id
add_vadd _ _ p :=
((congr_arg fun f => p.map f) <| AffineMap.ext <| add_vadd _ _).trans (p.map_map _ _).symm
scoped[Pointwise] attribute [instance] AffineSubspace.pointwiseAddAction
open Pointwise
theorem pointwise_vadd_eq_map (v : V) (s : AffineSubspace k P) :
v +ᵥ s = s.map (AffineEquiv.constVAdd k P v) :=
rfl
@[simp]
theorem coe_pointwise_vadd (v : V) (s : AffineSubspace k P) :
((v +ᵥ s : AffineSubspace k P) : Set P) = v +ᵥ (s : Set P) :=
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, map_top, 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
erw [pointwise_vadd_eq_map, pointwise_vadd_eq_map, map_map, map_map]
congr 1
ext
exact f.map_vadd _ _
end AffineSubspace
|
LinearAlgebra\AffineSpace\Restrict.lean | /-
Copyright (c) 2022 Paul Reichert. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul Reichert
-/
import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace
/-!
# 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₂]
-- not an instance because it loops with `Nonempty`
theorem 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⟩⟩⟩
-- Porting note: removed "local nolint fails_quickly" attribute
attribute [local instance] AffineSubspace.nonempty_map AffineSubspace.toAddTorsor
/-- 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, Subtype.coe_mk, 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, Subtype.coe_mk, 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⟩
|
LinearAlgebra\AffineSpace\Slope.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.LinearAlgebra.AffineSpace.AffineMap
import Mathlib.Tactic.FieldSimp
/-!
# 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
/-- `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
field_simp [sub_ne_zero.2 h.symm, ← sub_div_sub_smul_slope_add_sub_div_sub_smul_slope f a b c,
lineMap_apply_module]
/-- `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]
|
LinearAlgebra\Alternating\Basic.lean | /-
Copyright (c) 2020 Zhangir Azerbayev. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Zhangir Azerbayev
-/
import Mathlib.GroupTheory.Perm.Sign
import Mathlib.Data.Fintype.Perm
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' := fun f g h ↦ by
rcases f with ⟨⟨_, _, _⟩, _⟩
rcases g with ⟨⟨_, _, _⟩, _⟩
congr
-- shortcut instance
instance coeFun : CoeFun (M [⋀^ι]→ₗ[R] N) fun _ => (ι → M) → N :=
⟨DFunLike.coe⟩
initialize_simps_projections AlternatingMap (toFun → apply)
@[simp]
theorem toFun_eq_coe : f.toFun = f :=
rfl
-- Porting note: changed statement to reflect new `mk` signature
@[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] -- @[simp] -- Porting note (#10618): simp can prove this
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 coe : 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
-- Porting note: changed statement to reflect new `mk` signature.
-- Porting note: removed `simp`
-- @[simp]
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_add [DecidableEq ι] (i : ι) (x y : M) :
f (update v i (x + y)) = f (update v i x) + f (update v i y) :=
f.toMultilinearMap.map_add' v i x y
@[simp]
theorem map_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_sub v' i x y
@[simp]
theorem map_neg [DecidableEq ι] (i : ι) (x : M') : g' (update v' i (-x)) = -g' (update v' i x) :=
g'.toMultilinearMap.map_neg v' i x
@[simp]
theorem map_smul [DecidableEq ι] (i : ι) (r : R) (x : M) :
f (update v i (r • x)) = r • f (update v i x) :=
f.toMultilinearMap.map_smul' v i r x
@[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 smul : 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 isCentralScalar [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 add : Add (M [⋀^ι]→ₗ[R] N) :=
⟨fun 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 zero : Zero (M [⋀^ι]→ₗ[R] N) :=
⟨{ (0 : MultilinearMap R (fun _ : ι => M) N) with
map_eq_zero_of_eq' := fun v i j _ _ => 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 inhabited : Inhabited (M [⋀^ι]→ₗ[R] N) :=
⟨0⟩
instance addCommMonoid : AddCommMonoid (M [⋀^ι]→ₗ[R] N) :=
coe_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => coeFn_smul _ _
instance neg : 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 sub : 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 addCommGroup : AddCommGroup (M [⋀^ι]→ₗ[R] N') :=
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 distribMulAction : 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 module : Module S (M [⋀^ι]→ₗ[R] N) where
add_smul _ _ _ := ext fun _ => add_smul _ _ _
zero_smul _ := ext fun _ => zero_smul _ _
instance noZeroSMulDivisors [NoZeroSMulDivisors S N] :
NoZeroSMulDivisors S (M [⋀^ι]→ₗ[R] N) :=
coe_injective.noZeroSMulDivisors _ rfl coeFn_smul
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
left_inv _ := rfl
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 (config := .asFn)]
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 {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₂) : (M [⋀^ι]→ₗ[R] N) →+ (M [⋀^ι]→ₗ[R] N₂) where
toFun f :=
{ g.compMultilinearMap (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] }
map_zero' := by
ext
simp
map_add' a b := by
ext
simp
@[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
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
-- Porting note: Was `simp_rw [.., ← Pi.zero_def, map_zero, zero_apply]`.
simp_rw [compLinearMap_apply, LinearMap.zero_apply, ← Pi.zero_def, zero_apply]
exact map_zero f
/-- 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
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. -/
@[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_same, Function.update_noteq 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_same, Function.update_noteq hij, Function.update_same]) 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
-- Porting note: `apply` → `induction'`
induction' σ using Equiv.Perm.swap_induction_on' with s x y hxy hI
· simp
· -- Porting note: `← Function.comp.assoc` & `-Equiv.Perm.sign_swap'` are required.
simpa [← Function.comp.assoc, g.map_swap (v ∘ s) hxy,
Equiv.Perm.sign_swap hxy, -Equiv.Perm.sign_swap'] using hI
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]
right_inv m := by
ext
simp [Function.comp]
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]
right_inv m := by ext; simp [Function.comp]
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_smul, Function.update_eq_self, smul_eq_zero] at this
exact Or.resolve_left this hz
-- Porting note: Was `conv at h in .. => ..`.
rw [← (funext fun x => ite_self (c := i = x) (d := Classical.decEq ι i x) (g x • v x))] at h
rw [Finset.sum_ite, Finset.filter_eq, Finset.filter_ne, if_pos hi, Finset.sum_singleton,
add_eq_zero_iff_eq_neg] at h
rw [h, f.map_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_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 * σ)
-- Porting note: `-Equiv.Perm.sign_swap'` is required.
(fun σ _ => by simp [Perm.sign_swap i_ne_j, apply_swap_eq_self hv, -Equiv.Perm.sign_swap'])
(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 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
classical
refine AlternatingMap.coe_multilinearMap_injective (Basis.ext_multilinear 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
/-! ### Currying -/
section Currying
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₂'']
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]
def curryLeft {n : ℕ} (f : M'' [⋀^Fin n.succ]→ₗ[R'] N'') :
M'' →ₗ[R'] M'' [⋀^Fin n]→ₗ[R'] N'' where
toFun m :=
{ f.toMultilinearMap.curryLeft m with
toFun := fun v => f (Matrix.vecCons m v)
map_eq_zero_of_eq' := fun v i j hv hij =>
f.map_eq_zero_of_eq _ (by
rwa [Matrix.cons_val_succ, Matrix.cons_val_succ]) ((Fin.succ_injective _).ne hij) }
map_add' m₁ m₂ := ext fun v => f.map_vecCons_add _ _ _
map_smul' r m := ext fun v => f.map_vecCons_smul _ _ _
@[simp]
theorem curryLeft_zero {n : ℕ} : curryLeft (0 : M'' [⋀^Fin n.succ]→ₗ[R'] N'') = 0 :=
rfl
@[simp]
theorem curryLeft_add {n : ℕ} (f g : M'' [⋀^Fin n.succ]→ₗ[R'] N'') :
curryLeft (f + g) = curryLeft f + curryLeft g :=
rfl
@[simp]
theorem curryLeft_smul {n : ℕ} (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 {n : ℕ} :
(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 {n : ℕ} (f : M'' [⋀^Fin n.succ.succ]→ₗ[R'] N'') (m : M'') :
(f.curryLeft m).curryLeft m = 0 :=
ext fun x => f.map_eq_zero_of_eq _ (by simp) Fin.zero_ne_one
@[simp]
theorem curryLeft_compAlternatingMap {n : ℕ} (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 {n : ℕ} (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 <| by
refine Fin.cases ?_ ?_
· rfl
· simp
/-- The space of constant maps is equivalent to the space of maps that are alternating with respect
to an empty family. -/
@[simps]
def constLinearEquivOfIsEmpty [IsEmpty ι] : N'' ≃ₗ[R'] (M'' [⋀^ι]→ₗ[R'] N'') where
toFun := AlternatingMap.constOfIsEmpty R' M'' ι
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun f := f 0
left_inv _ := rfl
right_inv f := ext fun _ => AlternatingMap.congr_arg f <| Subsingleton.elim _ _
end AlternatingMap
end Currying
|
LinearAlgebra\Alternating\DomCoprod.lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.Alternating.Basic
import Mathlib.LinearAlgebra.Multilinear.TensorProduct
import Mathlib.GroupTheory.GroupAction.Quotient
/-!
# 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.
-/
suppress_compilation
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']
simp only [Sum.map_inr, Perm.sumCongrHom_apply, Perm.sumCongr_apply, Sum.map_inl,
Function.comp_apply, Perm.coe_mul]
-- Porting note (#10691): was `rw`.
erw [← a.map_congr_perm fun i => v (σ₁ _), ← b.map_congr_perm fun i => v (σ₁ _)]
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, Units.val_neg,
MultilinearMap.smul_apply, MultilinearMap.neg_apply, MultilinearMap.domDomCongr_apply,
MultilinearMap.domCoprod_apply]
convert add_right_neg (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σ
cases' hi : σ⁻¹ i with val val <;> cases' hj : σ⁻¹ j with val_1 val_1 <;>
rw [Perm.inv_eq_iff_eq] at hi hj <;> substs hi hj <;> revert val val_1
-- Porting note: `on_goal` is not available in `case _ | _ =>`, so the proof gets tedious.
-- the term pairs with and cancels another term
case inl.inr =>
intro i' j' _ _ hσ
obtain ⟨⟨sl, sr⟩, hσ⟩ := QuotientGroup.leftRel_apply.mp (Quotient.exact' hσ)
replace hσ := Equiv.congr_fun hσ (Sum.inl i')
dsimp only at hσ
rw [smul_eq_mul, ← mul_swap_eq_swap_mul, mul_inv_rev, swap_inv, inv_mul_cancel_right] at hσ
simp at hσ
case inr.inl =>
intro i' j' _ _ hσ
obtain ⟨⟨sl, sr⟩, hσ⟩ := QuotientGroup.leftRel_apply.mp (Quotient.exact' hσ)
replace hσ := Equiv.congr_fun hσ (Sum.inr i')
dsimp only at hσ
rw [smul_eq_mul, ← mul_swap_eq_swap_mul, mul_inv_rev, swap_inv, inv_mul_cancel_right] at hσ
simp at hσ
-- the term does not pair but is zero
case inr.inr =>
intro i' j' hv hij _
convert smul_zero (M := ℤˣ) (A := N₁ ⊗[R'] N₂) _
convert TensorProduct.tmul_zero (R := R') (M := N₁) N₂ _
exact AlternatingMap.map_eq_zero_of_eq _ _ hv fun hij' => hij (hij' ▸ rfl)
case inl.inl =>
intro i' j' hv hij _
convert smul_zero (M := ℤˣ) (A := N₁ ⊗[R'] N₂) _
convert TensorProduct.zero_tmul (R := R') N₁ (N := N₂) _
exact AlternatingMap.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
dsimp only
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
/-- 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 σ
refine Quotient.inductionOn' σ fun σ => ?_
-- unfold the quotient mess left by `Finset.sum_partition`
-- Porting note: Was `conv in .. => ..`.
erw
[@Finset.filter_congr _ _ (fun a => @Quotient.decidableEq _ _
(QuotientGroup.leftRelDecidable (MonoidHom.range (Perm.sumCongrHom ιa ιb)))
(Quotient.mk (QuotientGroup.leftRel (MonoidHom.range (Perm.sumCongrHom ιa ιb))) a)
(Quotient.mk'' σ)) _ (s := Finset.univ)
fun x _ => QuotientGroup.eq (s := MonoidHom.range (Perm.sumCongrHom ιa ιb)) (a := x) (b := σ)]
-- eliminate a multiplication
rw [← Finset.map_univ_equiv (Equiv.mulLeft σ), Finset.filter_map, Finset.sum_map]
simp_rw [Equiv.coe_toEmbedding, Equiv.coe_mulLeft, (· ∘ ·), mul_inv_rev, inv_mul_cancel_right,
Subgroup.inv_mem_iff, MonoidHom.mem_range, Finset.univ_filter_exists,
Finset.sum_image Perm.sumCongrHom_injective.injOn]
-- now we're ready to clean up the RHS, pulling out the summation
rw [domCoprod.summand_mk'', MultilinearMap.domCoprod_alternization_coe, ← Finset.sum_product',
Finset.univ_product_univ, ← MultilinearMap.domDomCongrEquiv_apply, _root_.map_sum,
Finset.smul_sum]
congr 1
ext1 ⟨al, ar⟩
dsimp only
-- pull out the pair of smuls on the RHS, by rewriting to `_ →ₗ[ℤ] _` and back
rw [← AddEquiv.coe_toAddMonoidHom, ← AddMonoidHom.coe_toIntLinearMap, LinearMap.map_smul_of_tower,
LinearMap.map_smul_of_tower, AddMonoidHom.coe_toIntLinearMap, AddEquiv.coe_toAddMonoidHom,
MultilinearMap.domDomCongrEquiv_apply]
-- pick up the pieces
rw [MultilinearMap.domDomCongr_mul, Perm.sign_mul, Perm.sumCongrHom_apply,
MultilinearMap.domCoprod_domDomCongr_sumCongr, Perm.sign_sumCongr, mul_smul, mul_smul]
/-- 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']
|
LinearAlgebra\Basis\Bilinear.lean | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.LinearAlgebra.Basis
import Mathlib.LinearAlgebra.BilinearMap
/-!
# Lemmas about bilinear maps with a basis over each argument
-/
namespace LinearMap
variable {ι₁ ι₂ : Type*}
variable {R R₂ S S₂ M N P Rₗ : Type*}
variable {Mₗ Nₗ Pₗ : Type*}
-- Could weaken [CommSemiring Rₗ] to [SMulCommClass Rₗ Rₗ Pₗ], but might impact performance
variable [Semiring R] [Semiring S] [Semiring R₂] [Semiring S₂] [CommSemiring Rₗ]
section AddCommMonoid
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P]
variable [AddCommMonoid Mₗ] [AddCommMonoid Nₗ] [AddCommMonoid Pₗ]
variable [Module R M] [Module S N] [Module R₂ P] [Module S₂ P]
variable [Module Rₗ Mₗ] [Module Rₗ Nₗ] [Module Rₗ Pₗ]
variable [SMulCommClass S₂ R₂ P]
variable {ρ₁₂ : R →+* R₂} {σ₁₂ : S →+* S₂}
variable (b₁ : Basis ι₁ R M) (b₂ : Basis ι₂ S N) (b₁' : Basis ι₁ Rₗ Mₗ) (b₂' : Basis ι₂ Rₗ Nₗ)
/-- Two bilinear maps are equal when they are equal on all basis vectors. -/
theorem ext_basis {B B' : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P} (h : ∀ i j, B (b₁ i) (b₂ j) = B' (b₁ i) (b₂ j)) :
B = B' :=
b₁.ext fun i => b₂.ext fun j => h i j
/-- Write out `B x y` as a sum over `B (b i) (b j)` if `b` is a basis.
Version for semi-bilinear maps, see `sum_repr_mul_repr_mul` for the bilinear version. -/
theorem sum_repr_mul_repr_mulₛₗ {B : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P} (x y) :
((b₁.repr x).sum fun i xi => (b₂.repr y).sum fun j yj => ρ₁₂ xi • σ₁₂ yj • B (b₁ i) (b₂ j)) =
B x y := by
conv_rhs => rw [← b₁.total_repr x, ← b₂.total_repr y]
simp_rw [Finsupp.total_apply, Finsupp.sum, map_sum₂, map_sum, LinearMap.map_smulₛₗ₂,
LinearMap.map_smulₛₗ]
/-- Write out `B x y` as a sum over `B (b i) (b j)` if `b` is a basis.
Version for bilinear maps, see `sum_repr_mul_repr_mulₛₗ` for the semi-bilinear version. -/
theorem sum_repr_mul_repr_mul {B : Mₗ →ₗ[Rₗ] Nₗ →ₗ[Rₗ] Pₗ} (x y) :
((b₁'.repr x).sum fun i xi => (b₂'.repr y).sum fun j yj => xi • yj • B (b₁' i) (b₂' j)) =
B x y := by
conv_rhs => rw [← b₁'.total_repr x, ← b₂'.total_repr y]
simp_rw [Finsupp.total_apply, Finsupp.sum, map_sum₂, map_sum, LinearMap.map_smul₂,
LinearMap.map_smul]
end AddCommMonoid
end LinearMap
|
LinearAlgebra\Basis\Flag.lean | /-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Patrick Massot
-/
import Mathlib.LinearAlgebra.Basis
import Mathlib.LinearAlgebra.Dual
import Mathlib.Data.Fin.FlagRange
/-!
# Flag of submodules defined by a basis
In this file we define `Basis.flag b k`, where `b : Basis (Fin n) R M`, `k : Fin (n + 1)`,
to be the subspace spanned by the first `k` vectors of the basis `b`.
We also prove some lemmas about this definition.
-/
open Set Submodule
namespace Basis
section Semiring
variable {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] {n : ℕ}
/-- The subspace spanned by the first `k` vectors of the basis `b`. -/
def flag (b : Basis (Fin n) R M) (k : Fin (n + 1)) : Submodule R M :=
.span R <| b '' {i | i.castSucc < k}
@[simp]
theorem flag_zero (b : Basis (Fin n) R M) : b.flag 0 = ⊥ := by simp [flag]
@[simp]
theorem flag_last (b : Basis (Fin n) R M) : b.flag (.last n) = ⊤ := by
simp [flag, Fin.castSucc_lt_last]
theorem flag_le_iff (b : Basis (Fin n) R M) {k p} :
b.flag k ≤ p ↔ ∀ i : Fin n, i.castSucc < k → b i ∈ p :=
span_le.trans forall_mem_image
theorem flag_succ (b : Basis (Fin n) R M) (k : Fin n) :
b.flag k.succ = (R ∙ b k) ⊔ b.flag k.castSucc := by
simp only [flag, Fin.castSucc_lt_castSucc_iff]
simp [Fin.castSucc_lt_iff_succ_le, le_iff_eq_or_lt, setOf_or, image_insert_eq, span_insert]
theorem self_mem_flag (b : Basis (Fin n) R M) {i : Fin n} {k : Fin (n + 1)} (h : i.castSucc < k) :
b i ∈ b.flag k :=
subset_span <| mem_image_of_mem _ h
@[simp]
theorem self_mem_flag_iff [Nontrivial R] (b : Basis (Fin n) R M) {i : Fin n} {k : Fin (n + 1)} :
b i ∈ b.flag k ↔ i.castSucc < k :=
b.self_mem_span_image
@[mono]
theorem flag_mono (b : Basis (Fin n) R M) : Monotone b.flag :=
Fin.monotone_iff_le_succ.2 fun k ↦ by rw [flag_succ]; exact le_sup_right
theorem isChain_range_flag (b : Basis (Fin n) R M) : IsChain (· ≤ ·) (range b.flag) :=
b.flag_mono.isChain_range
@[mono]
theorem flag_strictMono [Nontrivial R] (b : Basis (Fin n) R M) : StrictMono b.flag :=
Fin.strictMono_iff_lt_succ.2 fun _ ↦ by simp [flag_succ]
end Semiring
section CommRing
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {n : ℕ}
@[simp]
theorem flag_le_ker_coord_iff [Nontrivial R] (b : Basis (Fin n) R M) {k : Fin (n + 1)} {l : Fin n} :
b.flag k ≤ LinearMap.ker (b.coord l) ↔ k ≤ l.castSucc := by
simp [flag_le_iff, Finsupp.single_apply_eq_zero, imp_false, imp_not_comm]
theorem flag_le_ker_coord (b : Basis (Fin n) R M) {k : Fin (n + 1)} {l : Fin n}
(h : k ≤ l.castSucc) : b.flag k ≤ LinearMap.ker (b.coord l) := by
nontriviality R
exact b.flag_le_ker_coord_iff.2 h
theorem flag_le_ker_dual (b : Basis (Fin n) R M) (k : Fin n) :
b.flag k.castSucc ≤ LinearMap.ker (b.dualBasis k) := by
nontriviality R
rw [coe_dualBasis, b.flag_le_ker_coord_iff]
end CommRing
section DivisionRing
variable {K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] {n : ℕ}
theorem flag_covBy (b : Basis (Fin n) K V) (i : Fin n) :
b.flag i.castSucc ⋖ b.flag i.succ := by
rw [flag_succ]
apply covBy_span_singleton_sup
simp
theorem flag_wcovBy (b : Basis (Fin n) K V) (i : Fin n) :
b.flag i.castSucc ⩿ b.flag i.succ :=
(b.flag_covBy i).wcovBy
/-- Range of `Basis.flag` as a `Flag`. -/
@[simps!]
def toFlag (b : Basis (Fin n) K V) : Flag (Submodule K V) :=
.rangeFin b.flag b.flag_zero b.flag_last b.flag_wcovBy
@[simp]
theorem mem_toFlag (b : Basis (Fin n) K V) {p : Submodule K V} : p ∈ b.toFlag ↔ ∃ k, b.flag k = p :=
Iff.rfl
theorem isMaxChain_range_flag (b : Basis (Fin n) K V) : IsMaxChain (· ≤ ·) (range b.flag) :=
b.toFlag.maxChain
end DivisionRing
end Basis
|
LinearAlgebra\Basis\VectorSpace.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Alexander Bentkamp
-/
import Mathlib.LinearAlgebra.Basis
import Mathlib.LinearAlgebra.FreeModule.Basic
import Mathlib.LinearAlgebra.LinearPMap
import Mathlib.LinearAlgebra.Projection
/-!
# Bases in a vector space
This file provides results for bases of a vector space.
Some of these results should be merged with the results on free modules.
We state these results in a separate file to the results on modules to avoid an
import cycle.
## Main statements
* `Basis.ofVectorSpace` states that every vector space has a basis.
* `Module.Free.of_divisionRing` states that every vector space is a free module.
## Tags
basis, bases
-/
open Function Set Submodule
variable {ι : Type*} {ι' : Type*} {K : Type*} {V : Type*} {V' : Type*}
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [AddCommGroup V'] [Module K V] [Module K V']
variable {v : ι → V} {s t : Set V} {x y z : V}
open Submodule
namespace Basis
section ExistsBasis
/-- If `s` is a linear independent set of vectors, we can extend it to a basis. -/
noncomputable def extend (hs : LinearIndependent K ((↑) : s → V)) :
Basis (hs.extend (subset_univ s)) K V :=
Basis.mk
(@LinearIndependent.restrict_of_comp_subtype _ _ _ id _ _ _ _ (hs.linearIndependent_extend _))
(SetLike.coe_subset_coe.mp <| by simpa using hs.subset_span_extend (subset_univ s))
theorem extend_apply_self (hs : LinearIndependent K ((↑) : s → V)) (x : hs.extend _) :
Basis.extend hs x = x :=
Basis.mk_apply _ _ _
@[simp]
theorem coe_extend (hs : LinearIndependent K ((↑) : s → V)) : ⇑(Basis.extend hs) = ((↑) : _ → _) :=
funext (extend_apply_self hs)
theorem range_extend (hs : LinearIndependent K ((↑) : s → V)) :
range (Basis.extend hs) = hs.extend (subset_univ _) := by
rw [coe_extend, Subtype.range_coe_subtype, setOf_mem_eq]
-- Porting note: adding this to make the statement of `subExtend` more readable
/-- Auxiliary definition: the index for the new basis vectors in `Basis.sumExtend`.
The specific value of this definition should be considered an implementation detail.
-/
def sumExtendIndex (hs : LinearIndependent K v) : Set V :=
LinearIndependent.extend hs.to_subtype_range (subset_univ _) \ range v
/-- If `v` is a linear independent family of vectors, extend it to a basis indexed by a sum type. -/
noncomputable def sumExtend (hs : LinearIndependent K v) : Basis (ι ⊕ sumExtendIndex hs) K V :=
let s := Set.range v
let e : ι ≃ s := Equiv.ofInjective v hs.injective
let b := hs.to_subtype_range.extend (subset_univ (Set.range v))
(Basis.extend hs.to_subtype_range).reindex <|
Equiv.symm <|
calc
ι ⊕ (b \ s : Set V) ≃ s ⊕ (b \ s : Set V) := Equiv.sumCongr e (Equiv.refl _)
_ ≃ b :=
haveI := Classical.decPred (· ∈ s)
Equiv.Set.sumDiffSubset (hs.to_subtype_range.subset_extend _)
theorem subset_extend {s : Set V} (hs : LinearIndependent K ((↑) : s → V)) :
s ⊆ hs.extend (Set.subset_univ _) :=
hs.subset_extend _
section
variable (K V)
/-- A set used to index `Basis.ofVectorSpace`. -/
noncomputable def ofVectorSpaceIndex : Set V :=
(linearIndependent_empty K V).extend (subset_univ _)
/-- Each vector space has a basis. -/
noncomputable def ofVectorSpace : Basis (ofVectorSpaceIndex K V) K V :=
Basis.extend (linearIndependent_empty K V)
instance (priority := 100) _root_.Module.Free.of_divisionRing : Module.Free K V :=
Module.Free.of_basis (ofVectorSpace K V)
theorem ofVectorSpace_apply_self (x : ofVectorSpaceIndex K V) : ofVectorSpace K V x = x := by
unfold ofVectorSpace
exact Basis.mk_apply _ _ _
@[simp]
theorem coe_ofVectorSpace : ⇑(ofVectorSpace K V) = ((↑) : _ → _ ) :=
funext fun x => ofVectorSpace_apply_self K V x
theorem ofVectorSpaceIndex.linearIndependent :
LinearIndependent K ((↑) : ofVectorSpaceIndex K V → V) := by
convert (ofVectorSpace K V).linearIndependent
ext x
rw [ofVectorSpace_apply_self]
theorem range_ofVectorSpace : range (ofVectorSpace K V) = ofVectorSpaceIndex K V :=
range_extend _
theorem exists_basis : ∃ s : Set V, Nonempty (Basis s K V) :=
⟨ofVectorSpaceIndex K V, ⟨ofVectorSpace K V⟩⟩
end
end ExistsBasis
end Basis
open Fintype
variable (K V)
theorem VectorSpace.card_fintype [Fintype K] [Fintype V] : ∃ n : ℕ, card V = card K ^ n := by
classical
exact ⟨card (Basis.ofVectorSpaceIndex K V), Module.card_fintype (Basis.ofVectorSpace K V)⟩
section AtomsOfSubmoduleLattice
variable {K V}
/-- For a module over a division ring, the span of a nonzero element is an atom of the
lattice of submodules. -/
theorem nonzero_span_atom (v : V) (hv : v ≠ 0) : IsAtom (span K {v} : Submodule K V) := by
constructor
· rw [Submodule.ne_bot_iff]
exact ⟨v, ⟨mem_span_singleton_self v, hv⟩⟩
· intro T hT
by_contra h
apply hT.2
change span K {v} ≤ T
simp_rw [span_singleton_le_iff_mem, ← Ne.eq_def, Submodule.ne_bot_iff] at *
rcases h with ⟨s, ⟨hs, hz⟩⟩
rcases mem_span_singleton.1 (hT.1 hs) with ⟨a, rfl⟩
rcases eq_or_ne a 0 with rfl | h
· simp only [zero_smul, ne_eq, not_true] at hz
· rwa [T.smul_mem_iff h] at hs
/-- The atoms of the lattice of submodules of a module over a division ring are the
submodules equal to the span of a nonzero element of the module. -/
theorem atom_iff_nonzero_span (W : Submodule K V) :
IsAtom W ↔ ∃ v ≠ 0, W = span K {v} := by
refine ⟨fun h => ?_, fun h => ?_⟩
· cases' h with hbot h
rcases (Submodule.ne_bot_iff W).1 hbot with ⟨v, ⟨hW, hv⟩⟩
refine ⟨v, ⟨hv, ?_⟩⟩
by_contra heq
specialize h (span K {v})
rw [span_singleton_eq_bot, lt_iff_le_and_ne] at h
exact hv (h ⟨(span_singleton_le_iff_mem v W).2 hW, Ne.symm heq⟩)
· rcases h with ⟨v, ⟨hv, rfl⟩⟩
exact nonzero_span_atom v hv
/-- The lattice of submodules of a module over a division ring is atomistic. -/
instance : IsAtomistic (Submodule K V) where
eq_sSup_atoms W := by
refine ⟨_, submodule_eq_sSup_le_nonzero_spans W, ?_⟩
rintro _ ⟨w, ⟨_, ⟨hw, rfl⟩⟩⟩
exact nonzero_span_atom w hw
end AtomsOfSubmoduleLattice
variable {K V}
theorem LinearMap.exists_leftInverse_of_injective (f : V →ₗ[K] V') (hf_inj : LinearMap.ker f = ⊥) :
∃ g : V' →ₗ[K] V, g.comp f = LinearMap.id := by
let B := Basis.ofVectorSpaceIndex K V
let hB := Basis.ofVectorSpace K V
have hB₀ : _ := hB.linearIndependent.to_subtype_range
have : LinearIndependent K (fun x => x : f '' B → V') := by
have h₁ : LinearIndependent K ((↑) : ↥(f '' Set.range (Basis.ofVectorSpace K V)) → V') :=
LinearIndependent.image_subtype (f := f) hB₀ (show Disjoint _ _ by simp [hf_inj])
rwa [Basis.range_ofVectorSpace K V] at h₁
let C := this.extend (subset_univ _)
have BC := this.subset_extend (subset_univ _)
let hC := Basis.extend this
haveI Vinh : Inhabited V := ⟨0⟩
refine ⟨(hC.constr ℕ : _ → _) (C.restrict (invFun f)), hB.ext fun b => ?_⟩
rw [image_subset_iff] at BC
have fb_eq : f b = hC ⟨f b, BC b.2⟩ := by
change f b = Basis.extend this _
simp_rw [Basis.extend_apply_self]
dsimp []
rw [Basis.ofVectorSpace_apply_self, fb_eq, hC.constr_basis]
exact leftInverse_invFun (LinearMap.ker_eq_bot.1 hf_inj) _
theorem Submodule.exists_isCompl (p : Submodule K V) : ∃ q : Submodule K V, IsCompl p q :=
let ⟨f, hf⟩ := p.subtype.exists_leftInverse_of_injective p.ker_subtype
⟨LinearMap.ker f, LinearMap.isCompl_of_proj <| LinearMap.ext_iff.1 hf⟩
instance Submodule.complementedLattice : ComplementedLattice (Submodule K V) :=
⟨Submodule.exists_isCompl⟩
theorem LinearMap.exists_rightInverse_of_surjective (f : V →ₗ[K] V') (hf_surj : range f = ⊤) :
∃ g : V' →ₗ[K] V, f.comp g = LinearMap.id := by
let C := Basis.ofVectorSpaceIndex K V'
let hC := Basis.ofVectorSpace K V'
haveI : Inhabited V := ⟨0⟩
refine ⟨(hC.constr ℕ : _ → _) (C.restrict (invFun f)), hC.ext fun c => ?_⟩
rw [LinearMap.comp_apply, hC.constr_basis]
simp [hC, rightInverse_invFun (LinearMap.range_eq_top.1 hf_surj) c]
/-- Any linear map `f : p →ₗ[K] V'` defined on a subspace `p` can be extended to the whole
space. -/
theorem LinearMap.exists_extend {p : Submodule K V} (f : p →ₗ[K] V') :
∃ g : V →ₗ[K] V', g.comp p.subtype = f :=
let ⟨g, hg⟩ := p.subtype.exists_leftInverse_of_injective p.ker_subtype
⟨f.comp g, by rw [LinearMap.comp_assoc, hg, f.comp_id]⟩
open Submodule LinearMap
/-- If `p < ⊤` is a subspace of a vector space `V`, then there exists a nonzero linear map
`f : V →ₗ[K] K` such that `p ≤ ker f`. -/
theorem Submodule.exists_le_ker_of_lt_top (p : Submodule K V) (hp : p < ⊤) :
∃ (f : V →ₗ[K] K), f ≠ 0 ∧ p ≤ ker f := by
rcases SetLike.exists_of_lt hp with ⟨v, -, hpv⟩; clear hp
rcases (LinearPMap.supSpanSingleton ⟨p, 0⟩ v (1 : K) hpv).toFun.exists_extend with ⟨f, hf⟩
refine ⟨f, ?_, ?_⟩
· rintro rfl
rw [LinearMap.zero_comp] at hf
have := LinearPMap.supSpanSingleton_apply_mk ⟨p, 0⟩ v (1 : K) hpv 0 p.zero_mem 1
simpa using (LinearMap.congr_fun hf _).trans this
· refine fun x hx => mem_ker.2 ?_
have := LinearPMap.supSpanSingleton_apply_mk ⟨p, 0⟩ v (1 : K) hpv x hx 0
simpa using (LinearMap.congr_fun hf _).trans this
theorem quotient_prod_linearEquiv (p : Submodule K V) : Nonempty (((V ⧸ p) × p) ≃ₗ[K] V) :=
let ⟨q, hq⟩ := p.exists_isCompl
Nonempty.intro <|
((quotientEquivOfIsCompl p q hq).prod (LinearEquiv.refl _ _)).trans
(prodEquivOfIsCompl q p hq.symm)
end DivisionRing
|
LinearAlgebra\BilinearForm\Basic.lean | /-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andreas Swerdlow, Kexing Ying
-/
import Mathlib.Algebra.Algebra.Tower
import Mathlib.LinearAlgebra.BilinearMap
/-!
# Bilinear form
This file defines a bilinear form over a module. Basic ideas
such as orthogonality are also introduced, as well as reflexive,
symmetric, non-degenerate and alternating bilinear forms. Adjoints of
linear maps with respect to a bilinear form are also introduced.
A bilinear form on an `R`-(semi)module `M`, is a function from `M × M` to `R`,
that is linear in both arguments. Comments will typically abbreviate
"(semi)module" as just "module", but the definitions should be as general as
possible.
The result that there exists an orthogonal basis with respect to a symmetric,
nondegenerate bilinear form can be found in `QuadraticForm.lean` with
`exists_orthogonal_basis`.
## Notations
Given any term `B` of type `BilinForm`, due to a coercion, can use
the notation `B x y` to refer to the function field, ie. `B x y = B.bilin x y`.
In this file we use the following type variables:
- `M`, `M'`, ... are modules over the commutative semiring `R`,
- `M₁`, `M₁'`, ... are modules over the commutative ring `R₁`,
- `V`, ... is a vector space over the field `K`.
## References
* <https://en.wikipedia.org/wiki/Bilinear_form>
## Tags
Bilinear form,
-/
export LinearMap (BilinForm)
open LinearMap (BilinForm)
universe u v w
variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M]
variable {S : Type*} [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M]
variable {R₁ : Type*} {M₁ : Type*} [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁]
variable {V : Type*} {K : Type*} [Field K] [AddCommGroup V] [Module K V]
variable {B : BilinForm R M} {B₁ : BilinForm R₁ M₁}
namespace LinearMap
namespace BilinForm
@[deprecated (since := "2024-04-14")]
theorem coeFn_congr : ∀ {x x' y y' : M}, x = x' → y = y' → B x y = B x' y'
| _, _, _, _, rfl, rfl => rfl
theorem add_left (x y z : M) : B (x + y) z = B x z + B y z := map_add₂ _ _ _ _
theorem smul_left (a : R) (x y : M) : B (a • x) y = a * B x y := map_smul₂ _ _ _ _
theorem add_right (x y z : M) : B x (y + z) = B x y + B x z := map_add _ _ _
theorem smul_right (a : R) (x y : M) : B x (a • y) = a * B x y := map_smul _ _ _
theorem zero_left (x : M) : B 0 x = 0 := map_zero₂ _ _
theorem zero_right (x : M) : B x 0 = 0 := map_zero _
theorem neg_left (x y : M₁) : B₁ (-x) y = -B₁ x y := map_neg₂ _ _ _
theorem neg_right (x y : M₁) : B₁ x (-y) = -B₁ x y := map_neg _ _
theorem sub_left (x y z : M₁) : B₁ (x - y) z = B₁ x z - B₁ y z := map_sub₂ _ _ _ _
theorem sub_right (x y z : M₁) : B₁ x (y - z) = B₁ x y - B₁ x z := map_sub _ _ _
lemma smul_left_of_tower (r : S) (x y : M) : B (r • x) y = r • B x y := by
rw [← IsScalarTower.algebraMap_smul R r, smul_left, Algebra.smul_def]
lemma smul_right_of_tower (r : S) (x y : M) : B x (r • y) = r • B x y := by
rw [← IsScalarTower.algebraMap_smul R r, smul_right, Algebra.smul_def]
variable {D : BilinForm R M} {D₁ : BilinForm R₁ M₁}
-- TODO: instantiate `FunLike`
theorem coe_injective : Function.Injective ((fun B x y => B x y) : BilinForm R M → M → M → R) :=
fun B D h => by
ext x y
apply congrFun₂ h
@[ext]
theorem ext (H : ∀ x y : M, B x y = D x y) : B = D := ext₂ H
theorem congr_fun (h : B = D) (x y : M) : B x y = D x y := congr_fun₂ h _ _
@[deprecated (since := "2024-04-14")]
theorem coe_zero : ⇑(0 : BilinForm R M) = 0 :=
rfl
@[simp]
theorem zero_apply (x y : M) : (0 : BilinForm R M) x y = 0 :=
rfl
variable (B D B₁ D₁)
@[deprecated (since := "2024-04-14")]
theorem coe_add : ⇑(B + D) = B + D :=
rfl
@[simp]
theorem add_apply (x y : M) : (B + D) x y = B x y + D x y :=
rfl
@[deprecated (since := "2024-04-14")]
theorem coe_neg : ⇑(-B₁) = -B₁ :=
rfl
@[simp]
theorem neg_apply (x y : M₁) : (-B₁) x y = -B₁ x y :=
rfl
@[deprecated (since := "2024-04-14")]
theorem coe_sub : ⇑(B₁ - D₁) = B₁ - D₁ :=
rfl
@[simp]
theorem sub_apply (x y : M₁) : (B₁ - D₁) x y = B₁ x y - D₁ x y :=
rfl
/-- `coeFn` as an `AddMonoidHom` -/
def coeFnAddMonoidHom : BilinForm R M →+ M → M → R where
toFun := fun B x y => B x y
map_zero' := rfl
map_add' _ _ := rfl
section flip
/-- Auxiliary construction for the flip of a bilinear form, obtained by exchanging the left and
right arguments. This version is a `LinearMap`; it is later upgraded to a `LinearEquiv`
in `flipHom`. -/
def flipHomAux : (BilinForm R M) →ₗ[R] (BilinForm R M) where
toFun A := A.flip
map_add' A₁ A₂ := by
ext
simp only [LinearMap.flip_apply, LinearMap.add_apply]
map_smul' c A := by
ext
simp only [LinearMap.flip_apply, LinearMap.smul_apply, RingHom.id_apply]
theorem flip_flip_aux (A : BilinForm R M) :
flipHomAux (M := M) (flipHomAux (M := M) A) = A := by
ext A
simp [flipHomAux]
/-- The flip of a bilinear form, obtained by exchanging the left and right arguments. -/
def flipHom : BilinForm R M ≃ₗ[R] BilinForm R M :=
{ flipHomAux with
invFun := flipHomAux (M := M)
left_inv := flip_flip_aux
right_inv := flip_flip_aux }
@[simp]
theorem flip_apply (A : BilinForm R M) (x y : M) : flipHom A x y = A y x :=
rfl
theorem flip_flip :
flipHom.trans flipHom = LinearEquiv.refl R (BilinForm R M) := by
ext A
simp
/-- The `flip` of a bilinear form over a commutative ring, obtained by exchanging the left and
right arguments. -/
abbrev flip (B : BilinForm R M) :=
flipHom B
end flip
/-- The restriction of a bilinear form on a submodule. -/
@[simps! apply]
def restrict (B : BilinForm R M) (W : Submodule R M) : BilinForm R W :=
LinearMap.domRestrict₁₂ B W W
end BilinForm
end LinearMap
|
LinearAlgebra\BilinearForm\DualLattice.lean | /-
Copyright (c) 2018 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.LinearAlgebra.BilinearForm.Properties
/-!
# Dual submodule with respect to a bilinear form.
## Main definitions and results
- `BilinForm.dualSubmodule`: The dual submodule with respect to a bilinear form.
- `BilinForm.dualSubmodule_span_of_basis`: The dual of a lattice is spanned by the dual basis.
## TODO
Properly develop the material in the context of lattices.
-/
open LinearMap (BilinForm)
variable {R S M} [CommRing R] [Field S] [AddCommGroup M]
variable [Algebra R S] [Module R M] [Module S M] [IsScalarTower R S M]
namespace LinearMap
namespace BilinForm
variable (B : BilinForm S M)
/-- The dual submodule of a submodule with respect to a bilinear form. -/
def dualSubmodule (N : Submodule R M) : Submodule R M where
carrier := { x | ∀ y ∈ N, B x y ∈ (1 : Submodule R S) }
add_mem' {a b} ha hb y hy := by simpa using add_mem (ha y hy) (hb y hy)
zero_mem' y _ := by rw [B.zero_left]; exact zero_mem _
smul_mem' r a ha y hy := by
convert (1 : Submodule R S).smul_mem r (ha y hy)
rw [← IsScalarTower.algebraMap_smul S r a]
simp only [algebraMap_smul, map_smul_of_tower, LinearMap.smul_apply]
lemma mem_dualSubmodule {N : Submodule R M} {x} :
x ∈ B.dualSubmodule N ↔ ∀ y ∈ N, B x y ∈ (1 : Submodule R S) := Iff.rfl
lemma le_flip_dualSubmodule {N₁ N₂ : Submodule R M} :
N₁ ≤ B.flip.dualSubmodule N₂ ↔ N₂ ≤ B.dualSubmodule N₁ := by
show (∀ (x : M), x ∈ N₁ → _) ↔ ∀ (x : M), x ∈ N₂ → _
simp only [mem_dualSubmodule, Submodule.mem_one, flip_apply]
exact forall₂_swap
/-- The natural paring of `B.dualSubmodule N` and `N`.
This is bundled as a bilinear map in `BilinForm.dualSubmoduleToDual`. -/
noncomputable
def dualSubmoduleParing {N : Submodule R M} (x : B.dualSubmodule N) (y : N) : R :=
(x.prop y y.prop).choose
@[simp]
lemma dualSubmoduleParing_spec {N : Submodule R M} (x : B.dualSubmodule N) (y : N) :
algebraMap R S (B.dualSubmoduleParing x y) = B x y :=
(x.prop y y.prop).choose_spec
/-- The natural paring of `B.dualSubmodule N` and `N`. -/
-- TODO: Show that this is perfect when `N` is a lattice and `B` is nondegenerate.
@[simps]
noncomputable
def dualSubmoduleToDual [NoZeroSMulDivisors R S] (N : Submodule R M) :
B.dualSubmodule N →ₗ[R] Module.Dual R N :=
{ toFun := fun x ↦
{ toFun := B.dualSubmoduleParing x
map_add' := fun x y ↦ NoZeroSMulDivisors.algebraMap_injective R S (by simp)
map_smul' := fun r m ↦ NoZeroSMulDivisors.algebraMap_injective R S
(by simp [← Algebra.smul_def]) }
map_add' := fun x y ↦ LinearMap.ext fun z ↦ NoZeroSMulDivisors.algebraMap_injective R S
(by simp)
map_smul' := fun r x ↦ LinearMap.ext fun y ↦ NoZeroSMulDivisors.algebraMap_injective R S
(by simp [← Algebra.smul_def]) }
lemma dualSubmoduleToDual_injective (hB : B.Nondegenerate) [NoZeroSMulDivisors R S]
(N : Submodule R M) (hN : Submodule.span S (N : Set M) = ⊤) :
Function.Injective (B.dualSubmoduleToDual N) := by
intro x y e
ext
apply LinearMap.ker_eq_bot.mp hB.ker_eq_bot
apply LinearMap.ext_on hN
intro z hz
simpa using congr_arg (algebraMap R S) (LinearMap.congr_fun e ⟨z, hz⟩)
lemma dualSubmodule_span_of_basis {ι} [Finite ι] [DecidableEq ι]
(hB : B.Nondegenerate) (b : Basis ι S M) :
B.dualSubmodule (Submodule.span R (Set.range b)) =
Submodule.span R (Set.range <| B.dualBasis hB b) := by
cases nonempty_fintype ι
apply le_antisymm
· intro x hx
rw [← (B.dualBasis hB b).sum_repr x]
apply sum_mem
rintro i -
obtain ⟨r, hr⟩ := hx (b i) (Submodule.subset_span ⟨_, rfl⟩)
simp only [dualBasis_repr_apply, ← hr, Algebra.linearMap_apply, algebraMap_smul]
apply Submodule.smul_mem
exact Submodule.subset_span ⟨_, rfl⟩
· rw [Submodule.span_le]
rintro _ ⟨i, rfl⟩ y hy
obtain ⟨f, rfl⟩ := (mem_span_range_iff_exists_fun _).mp hy
simp only [map_sum, map_smul]
apply sum_mem
rintro j -
rw [← IsScalarTower.algebraMap_smul S (f j), map_smul]
simp_rw [apply_dualBasis_left]
rw [smul_eq_mul, mul_ite, mul_one, mul_zero, ← (algebraMap R S).map_zero, ← apply_ite]
exact ⟨_, rfl⟩
lemma dualSubmodule_dualSubmodule_flip_of_basis {ι : Type*} [Finite ι]
(hB : B.Nondegenerate) (b : Basis ι S M) :
B.dualSubmodule (B.flip.dualSubmodule (Submodule.span R (Set.range b))) =
Submodule.span R (Set.range b) := by
classical
letI := FiniteDimensional.of_fintype_basis b
rw [dualSubmodule_span_of_basis _ hB.flip, dualSubmodule_span_of_basis B hB,
dualBasis_dualBasis_flip B hB]
lemma dualSubmodule_flip_dualSubmodule_of_basis {ι : Type*} [Finite ι]
(hB : B.Nondegenerate) (b : Basis ι S M) :
B.flip.dualSubmodule (B.dualSubmodule (Submodule.span R (Set.range b))) =
Submodule.span R (Set.range b) := by
classical
letI := FiniteDimensional.of_fintype_basis b
rw [dualSubmodule_span_of_basis B hB, dualSubmodule_span_of_basis _ hB.flip,
dualBasis_flip_dualBasis B hB]
lemma dualSubmodule_dualSubmodule_of_basis
{ι} [Finite ι] (hB : B.Nondegenerate) (hB' : B.IsSymm) (b : Basis ι S M) :
B.dualSubmodule (B.dualSubmodule (Submodule.span R (Set.range b))) =
Submodule.span R (Set.range b) := by
classical
letI := FiniteDimensional.of_fintype_basis b
rw [dualSubmodule_span_of_basis B hB, dualSubmodule_span_of_basis B hB,
dualBasis_dualBasis B hB hB']
end BilinForm
end LinearMap
|
LinearAlgebra\BilinearForm\Hom.lean | /-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andreas Swerdlow, Kexing Ying
-/
import Mathlib.LinearAlgebra.BilinearMap
import Mathlib.LinearAlgebra.BilinearForm.Basic
import Mathlib.LinearAlgebra.Basis
import Mathlib.Algebra.Algebra.Bilinear
/-!
# Bilinear form and linear maps
This file describes the relation between bilinear forms and linear maps.
## TODO
A lot of this file is now redundant following the replacement of the dedicated `_root_.BilinForm`
structure with `LinearMap.BilinForm`, which is just an alias for `M →ₗ[R] M →ₗ[R] R`. For example
`LinearMap.BilinForm.toLinHom` is now just the identity map. This redundant code should be removed.
## Notations
Given any term `B` of type `BilinForm`, due to a coercion, can use
the notation `B x y` to refer to the function field, ie. `B x y = B.bilin x y`.
In this file we use the following type variables:
- `M`, `M'`, ... are modules over the commutative semiring `R`,
- `M₁`, `M₁'`, ... are modules over the commutative ring `R₁`,
- `V`, ... is a vector space over the field `K`.
## References
* <https://en.wikipedia.org/wiki/Bilinear_form>
## Tags
Bilinear form,
-/
open LinearMap (BilinForm)
universe u v w
variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M]
variable {R₁ : Type*} {M₁ : Type*} [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁]
variable {V : Type*} {K : Type*} [Field K] [AddCommGroup V] [Module K V]
variable {B : BilinForm R M} {B₁ : BilinForm R₁ M₁}
namespace LinearMap
namespace BilinForm
section ToLin'
/-- Auxiliary definition to define `toLinHom`; see below. -/
def toLinHomAux₁ (A : BilinForm R M) (x : M) : M →ₗ[R] R := A x
/-- Auxiliary definition to define `toLinHom`; see below. -/
@[deprecated (since := "2024-04-26")]
def toLinHomAux₂ (A : BilinForm R M) : M →ₗ[R] M →ₗ[R] R := A
/-- The linear map obtained from a `BilinForm` by fixing the left co-ordinate and evaluating in
the right. -/
@[deprecated (since := "2024-04-26")]
def toLinHom : BilinForm R M →ₗ[R] M →ₗ[R] M →ₗ[R] R := LinearMap.id
set_option linter.deprecated false in
@[deprecated (since := "2024-04-26")]
theorem toLin'_apply (A : BilinForm R M) (x : M) : toLinHom (M := M) A x = A x :=
rfl
variable (B)
theorem sum_left {α} (t : Finset α) (g : α → M) (w : M) :
B (∑ i ∈ t, g i) w = ∑ i ∈ t, B (g i) w :=
B.map_sum₂ t g w
variable (w : M)
theorem sum_right {α} (t : Finset α) (w : M) (g : α → M) :
B w (∑ i ∈ t, g i) = ∑ i ∈ t, B w (g i) := map_sum _ _ _
theorem sum_apply {α} (t : Finset α) (B : α → BilinForm R M) (v w : M) :
(∑ i ∈ t, B i) v w = ∑ i ∈ t, B i v w := by
simp only [coeFn_sum, Finset.sum_apply]
variable {B}
/-- The linear map obtained from a `BilinForm` by fixing the right co-ordinate and evaluating in
the left. -/
def toLinHomFlip : BilinForm R M →ₗ[R] M →ₗ[R] M →ₗ[R] R :=
flipHom.toLinearMap
theorem toLin'Flip_apply (A : BilinForm R M) (x : M) : toLinHomFlip (M := M) A x = fun y => A y x :=
rfl
end ToLin'
end BilinForm
end LinearMap
section EquivLin
/-- A map with two arguments that is linear in both is a bilinear form.
This is an auxiliary definition for the full linear equivalence `LinearMap.toBilin`.
-/
def LinearMap.toBilinAux (f : M →ₗ[R] M →ₗ[R] R) : BilinForm R M := f
set_option linter.deprecated false in
/-- Bilinear forms are linearly equivalent to maps with two arguments that are linear in both. -/
@[deprecated (since := "2024-04-26")]
def LinearMap.BilinForm.toLin : BilinForm R M ≃ₗ[R] M →ₗ[R] M →ₗ[R] R :=
{ BilinForm.toLinHom with
invFun := LinearMap.toBilinAux
left_inv := fun _ => rfl
right_inv := fun _ => rfl }
set_option linter.deprecated false in
/-- A map with two arguments that is linear in both is linearly equivalent to bilinear form. -/
@[deprecated (since := "2024-04-26")]
def LinearMap.toBilin : (M →ₗ[R] M →ₗ[R] R) ≃ₗ[R] BilinForm R M :=
BilinForm.toLin.symm
@[deprecated (since := "2024-04-26")]
theorem LinearMap.toBilinAux_eq (f : M →ₗ[R] M →ₗ[R] R) :
LinearMap.toBilinAux f = f :=
rfl
set_option linter.deprecated false in
@[deprecated (since := "2024-04-26")]
theorem LinearMap.toBilin_symm :
(LinearMap.toBilin.symm : BilinForm R M ≃ₗ[R] _) = BilinForm.toLin :=
rfl
set_option linter.deprecated false in
@[deprecated (since := "2024-04-26")]
theorem BilinForm.toLin_symm :
(BilinForm.toLin.symm : _ ≃ₗ[R] BilinForm R M) = LinearMap.toBilin :=
LinearMap.toBilin.symm_symm
set_option linter.deprecated false in
@[deprecated (since := "2024-04-26")]
theorem LinearMap.toBilin_apply (f : M →ₗ[R] M →ₗ[R] R) (x y : M) :
toBilin f x y = f x y :=
rfl
set_option linter.deprecated false in
@[deprecated (since := "2024-04-26")]
theorem BilinForm.toLin_apply (x : M) : BilinForm.toLin B x = B x :=
rfl
end EquivLin
namespace LinearMap
variable {R' : Type*} [CommSemiring R'] [Algebra R' R] [Module R' M] [IsScalarTower R' R M]
/-- Apply a linear map on the output of a bilinear form. -/
@[simps!]
def compBilinForm (f : R →ₗ[R'] R') (B : BilinForm R M) : BilinForm R' M :=
compr₂ (restrictScalars₁₂ R' R' B) f
end LinearMap
namespace LinearMap
namespace BilinForm
section Comp
variable {M' : Type w} [AddCommMonoid M'] [Module R M']
/-- Apply a linear map on the left and right argument of a bilinear form. -/
def comp (B : BilinForm R M') (l r : M →ₗ[R] M') : BilinForm R M := B.compl₁₂ l r
/-- Apply a linear map to the left argument of a bilinear form. -/
def compLeft (B : BilinForm R M) (f : M →ₗ[R] M) : BilinForm R M :=
B.comp f LinearMap.id
/-- Apply a linear map to the right argument of a bilinear form. -/
def compRight (B : BilinForm R M) (f : M →ₗ[R] M) : BilinForm R M :=
B.comp LinearMap.id f
theorem comp_comp {M'' : Type*} [AddCommMonoid M''] [Module R M''] (B : BilinForm R M'')
(l r : M →ₗ[R] M') (l' r' : M' →ₗ[R] M'') :
(B.comp l' r').comp l r = B.comp (l'.comp l) (r'.comp r) :=
rfl
@[simp]
theorem compLeft_compRight (B : BilinForm R M) (l r : M →ₗ[R] M) :
(B.compLeft l).compRight r = B.comp l r :=
rfl
@[simp]
theorem compRight_compLeft (B : BilinForm R M) (l r : M →ₗ[R] M) :
(B.compRight r).compLeft l = B.comp l r :=
rfl
@[simp]
theorem comp_apply (B : BilinForm R M') (l r : M →ₗ[R] M') (v w) : B.comp l r v w = B (l v) (r w) :=
rfl
@[simp]
theorem compLeft_apply (B : BilinForm R M) (f : M →ₗ[R] M) (v w) : B.compLeft f v w = B (f v) w :=
rfl
@[simp]
theorem compRight_apply (B : BilinForm R M) (f : M →ₗ[R] M) (v w) : B.compRight f v w = B v (f w) :=
rfl
@[simp]
theorem comp_id_left (B : BilinForm R M) (r : M →ₗ[R] M) :
B.comp LinearMap.id r = B.compRight r := by
ext
rfl
@[simp]
theorem comp_id_right (B : BilinForm R M) (l : M →ₗ[R] M) :
B.comp l LinearMap.id = B.compLeft l := by
ext
rfl
@[simp]
theorem compLeft_id (B : BilinForm R M) : B.compLeft LinearMap.id = B := by
ext
rfl
@[simp]
theorem compRight_id (B : BilinForm R M) : B.compRight LinearMap.id = B := by
ext
rfl
-- Shortcut for `comp_id_{left,right}` followed by `comp{Right,Left}_id`,
-- Needs higher priority to be applied
@[simp high]
theorem comp_id_id (B : BilinForm R M) : B.comp LinearMap.id LinearMap.id = B := by
ext
rfl
theorem comp_inj (B₁ B₂ : BilinForm R M') {l r : M →ₗ[R] M'} (hₗ : Function.Surjective l)
(hᵣ : Function.Surjective r) : B₁.comp l r = B₂.comp l r ↔ B₁ = B₂ := by
constructor <;> intro h
· -- B₁.comp l r = B₂.comp l r → B₁ = B₂
ext x y
cases' hₗ x with x' hx
subst hx
cases' hᵣ y with y' hy
subst hy
rw [← comp_apply, ← comp_apply, h]
· -- B₁ = B₂ → B₁.comp l r = B₂.comp l r
rw [h]
end Comp
variable {M' M'' : Type*}
variable [AddCommMonoid M'] [AddCommMonoid M''] [Module R M'] [Module R M'']
section congr
/-- Apply a linear equivalence on the arguments of a bilinear form. -/
def congr (e : M ≃ₗ[R] M') : BilinForm R M ≃ₗ[R] BilinForm R M' where
toFun B := B.comp e.symm e.symm
invFun B := B.comp e e
left_inv B := ext₂ fun x => by
simp only [comp_apply, LinearEquiv.coe_coe, LinearEquiv.symm_apply_apply, forall_const]
right_inv B := ext₂ fun x => by
simp only [comp_apply, LinearEquiv.coe_coe, LinearEquiv.apply_symm_apply, forall_const]
map_add' B B' := ext₂ fun x y => rfl
map_smul' B B' := ext₂ fun x y => rfl
@[simp]
theorem congr_apply (e : M ≃ₗ[R] M') (B : BilinForm R M) (x y : M') :
congr e B x y = B (e.symm x) (e.symm y) :=
rfl
@[simp]
theorem congr_symm (e : M ≃ₗ[R] M') : (congr e).symm = congr e.symm := by
ext
simp only [congr_apply, LinearEquiv.symm_symm]
rfl
@[simp]
theorem congr_refl : congr (LinearEquiv.refl R M) = LinearEquiv.refl R _ :=
LinearEquiv.ext fun _ => ext₂ fun _ _ => rfl
theorem congr_trans (e : M ≃ₗ[R] M') (f : M' ≃ₗ[R] M'') :
(congr e).trans (congr f) = congr (e.trans f) :=
rfl
theorem congr_congr (e : M' ≃ₗ[R] M'') (f : M ≃ₗ[R] M') (B : BilinForm R M) :
congr e (congr f B) = congr (f.trans e) B :=
rfl
theorem congr_comp (e : M ≃ₗ[R] M') (B : BilinForm R M) (l r : M'' →ₗ[R] M') :
(congr e B).comp l r =
B.comp (LinearMap.comp (e.symm : M' →ₗ[R] M) l)
(LinearMap.comp (e.symm : M' →ₗ[R] M) r) :=
rfl
theorem comp_congr (e : M' ≃ₗ[R] M'') (B : BilinForm R M) (l r : M' →ₗ[R] M) :
congr e (B.comp l r) =
B.comp (l.comp (e.symm : M'' →ₗ[R] M')) (r.comp (e.symm : M'' →ₗ[R] M')) :=
rfl
end congr
section LinMulLin
/-- `linMulLin f g` is the bilinear form mapping `x` and `y` to `f x * g y` -/
def linMulLin (f g : M →ₗ[R] R) : BilinForm R M := (LinearMap.mul R R).compl₁₂ f g
variable {f g : M →ₗ[R] R}
@[simp]
theorem linMulLin_apply (x y) : linMulLin f g x y = f x * g y :=
rfl
@[simp]
theorem linMulLin_comp (l r : M' →ₗ[R] M) :
(linMulLin f g).comp l r = linMulLin (f.comp l) (g.comp r) :=
rfl
@[simp]
theorem linMulLin_compLeft (l : M →ₗ[R] M) :
(linMulLin f g).compLeft l = linMulLin (f.comp l) g :=
rfl
@[simp]
theorem linMulLin_compRight (r : M →ₗ[R] M) :
(linMulLin f g).compRight r = linMulLin f (g.comp r) :=
rfl
end LinMulLin
section Basis
variable {F₂ : BilinForm R M}
variable {ι : Type*} (b : Basis ι R M)
/-- Two bilinear forms are equal when they are equal on all basis vectors. -/
theorem ext_basis (h : ∀ i j, B (b i) (b j) = F₂ (b i) (b j)) : B = F₂ :=
b.ext fun i => b.ext fun j => h i j
/-- Write out `B x y` as a sum over `B (b i) (b j)` if `b` is a basis. -/
theorem sum_repr_mul_repr_mul (x y : M) :
((b.repr x).sum fun i xi => (b.repr y).sum fun j yj => xi • yj • B (b i) (b j)) = B x y := by
conv_rhs => rw [← b.total_repr x, ← b.total_repr y]
simp_rw [Finsupp.total_apply, Finsupp.sum, sum_left, sum_right, smul_left, smul_right,
smul_eq_mul]
end Basis
end BilinForm
end LinearMap
|
LinearAlgebra\BilinearForm\Orthogonal.lean | /-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andreas Swerdlow, Kexing Ying
-/
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.LinearAlgebra.BilinearForm.Properties
/-!
# Bilinear form
This file defines orthogonal bilinear forms.
## Notations
Given any term `B` of type `BilinForm`, due to a coercion, can use
the notation `B x y` to refer to the function field, ie. `B x y = B.bilin x y`.
In this file we use the following type variables:
- `M`, `M'`, ... are modules over the commutative semiring `R`,
- `M₁`, `M₁'`, ... are modules over the commutative ring `R₁`,
- `V`, ... is a vector space over the field `K`.
## References
* <https://en.wikipedia.org/wiki/Bilinear_form>
## Tags
Bilinear form,
-/
open LinearMap (BilinForm)
universe u v w
variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M]
variable {R₁ : Type*} {M₁ : Type*} [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁]
variable {V : Type*} {K : Type*} [Field K] [AddCommGroup V] [Module K V]
variable {B : BilinForm R M} {B₁ : BilinForm R₁ M₁}
namespace LinearMap
namespace BilinForm
/-- The proposition that two elements of a bilinear form space are orthogonal. For orthogonality
of an indexed set of elements, use `BilinForm.iIsOrtho`. -/
def IsOrtho (B : BilinForm R M) (x y : M) : Prop :=
B x y = 0
theorem isOrtho_def {B : BilinForm R M} {x y : M} : B.IsOrtho x y ↔ B x y = 0 :=
Iff.rfl
theorem isOrtho_zero_left (x : M) : IsOrtho B (0 : M) x := LinearMap.isOrtho_zero_left B x
theorem isOrtho_zero_right (x : M) : IsOrtho B x (0 : M) :=
zero_right x
theorem ne_zero_of_not_isOrtho_self {B : BilinForm K V} (x : V) (hx₁ : ¬B.IsOrtho x x) : x ≠ 0 :=
fun hx₂ => hx₁ (hx₂.symm ▸ isOrtho_zero_left _)
theorem IsRefl.ortho_comm (H : B.IsRefl) {x y : M} : IsOrtho B x y ↔ IsOrtho B y x :=
⟨eq_zero H, eq_zero H⟩
theorem IsAlt.ortho_comm (H : B₁.IsAlt) {x y : M₁} : IsOrtho B₁ x y ↔ IsOrtho B₁ y x :=
LinearMap.IsAlt.ortho_comm H
theorem IsSymm.ortho_comm (H : B.IsSymm) {x y : M} : IsOrtho B x y ↔ IsOrtho B y x :=
LinearMap.IsSymm.ortho_comm H
/-- A set of vectors `v` is orthogonal with respect to some bilinear form `B` if and only
if for all `i ≠ j`, `B (v i) (v j) = 0`. For orthogonality between two elements, use
`BilinForm.IsOrtho` -/
def iIsOrtho {n : Type w} (B : BilinForm R M) (v : n → M) : Prop :=
B.IsOrthoᵢ v
theorem iIsOrtho_def {n : Type w} {B : BilinForm R M} {v : n → M} :
B.iIsOrtho v ↔ ∀ i j : n, i ≠ j → B (v i) (v j) = 0 :=
Iff.rfl
section
variable {R₄ M₄ : Type*} [CommRing R₄] [IsDomain R₄]
variable [AddCommGroup M₄] [Module R₄ M₄] {G : BilinForm R₄ M₄}
@[simp]
theorem isOrtho_smul_left {x y : M₄} {a : R₄} (ha : a ≠ 0) :
IsOrtho G (a • x) y ↔ IsOrtho G x y := by
dsimp only [IsOrtho]
rw [map_smul]
simp only [LinearMap.smul_apply, smul_eq_mul, mul_eq_zero, or_iff_right_iff_imp]
exact fun a ↦ (ha a).elim
@[simp]
theorem isOrtho_smul_right {x y : M₄} {a : R₄} (ha : a ≠ 0) :
IsOrtho G x (a • y) ↔ IsOrtho G x y := by
dsimp only [IsOrtho]
rw [map_smul]
simp only [smul_eq_mul, mul_eq_zero, or_iff_right_iff_imp]
exact fun a ↦ (ha a).elim
/-- A set of orthogonal vectors `v` with respect to some bilinear form `B` is linearly independent
if for all `i`, `B (v i) (v i) ≠ 0`. -/
theorem linearIndependent_of_iIsOrtho {n : Type w} {B : BilinForm K V} {v : n → V}
(hv₁ : B.iIsOrtho v) (hv₂ : ∀ i, ¬B.IsOrtho (v i) (v i)) : LinearIndependent K v := by
classical
rw [linearIndependent_iff']
intro s w hs i hi
have : B (s.sum fun i : n => w i • v i) (v i) = 0 := by rw [hs, zero_left]
have hsum : (s.sum fun j : n => w j * B (v j) (v i)) = w i * B (v i) (v i) := by
apply Finset.sum_eq_single_of_mem i hi
intro j _ hij
rw [iIsOrtho_def.1 hv₁ _ _ hij, mul_zero]
simp_rw [sum_left, smul_left, hsum] at this
exact eq_zero_of_ne_zero_of_mul_right_eq_zero (hv₂ i) this
end
section Orthogonal
/-- The orthogonal complement of a submodule `N` with respect to some bilinear form is the set of
elements `x` which are orthogonal to all elements of `N`; i.e., for all `y` in `N`, `B x y = 0`.
Note that for general (neither symmetric nor antisymmetric) bilinear forms this definition has a
chirality; in addition to this "left" orthogonal complement one could define a "right" orthogonal
complement for which, for all `y` in `N`, `B y x = 0`. This variant definition is not currently
provided in mathlib. -/
def orthogonal (B : BilinForm R M) (N : Submodule R M) : Submodule R M where
carrier := { m | ∀ n ∈ N, IsOrtho B n m }
zero_mem' x _ := isOrtho_zero_right x
add_mem' {x y} hx hy n hn := by
rw [IsOrtho, add_right, show B n x = 0 from hx n hn, show B n y = 0 from hy n hn, zero_add]
smul_mem' c x hx n hn := by
rw [IsOrtho, smul_right, show B n x = 0 from hx n hn, mul_zero]
variable {N L : Submodule R M}
@[simp]
theorem mem_orthogonal_iff {N : Submodule R M} {m : M} :
m ∈ B.orthogonal N ↔ ∀ n ∈ N, IsOrtho B n m :=
Iff.rfl
@[simp] lemma orthogonal_bot : B.orthogonal ⊥ = ⊤ := by ext; simp [IsOrtho]
theorem orthogonal_le (h : N ≤ L) : B.orthogonal L ≤ B.orthogonal N := fun _ hn l hl => hn l (h hl)
theorem le_orthogonal_orthogonal (b : B.IsRefl) : N ≤ B.orthogonal (B.orthogonal N) :=
fun n hn _ hm => b _ _ (hm n hn)
lemma orthogonal_top (hB : B.Nondegenerate) (hB₀ : B.IsRefl) :
B.orthogonal ⊤ = ⊥ :=
(Submodule.eq_bot_iff _).mpr fun _ hx ↦ hB _ fun y ↦ hB₀ _ _ <| hx y Submodule.mem_top
-- ↓ This lemma only applies in fields as we require `a * b = 0 → a = 0 ∨ b = 0`
theorem span_singleton_inf_orthogonal_eq_bot {B : BilinForm K V} {x : V} (hx : ¬B.IsOrtho x x) :
(K ∙ x) ⊓ B.orthogonal (K ∙ x) = ⊥ := by
rw [← Finset.coe_singleton]
refine eq_bot_iff.2 fun y h => ?_
rcases mem_span_finset.1 h.1 with ⟨μ, rfl⟩
have := h.2 x ?_
· rw [Finset.sum_singleton] at this ⊢
suffices hμzero : μ x = 0 by rw [hμzero, zero_smul, Submodule.mem_bot]
change B x (μ x • x) = 0 at this
rw [smul_right] at this
exact eq_zero_of_ne_zero_of_mul_right_eq_zero hx this
· rw [Submodule.mem_span]
exact fun _ hp => hp <| Finset.mem_singleton_self _
-- ↓ This lemma only applies in fields since we use the `mul_eq_zero`
theorem orthogonal_span_singleton_eq_toLin_ker {B : BilinForm K V} (x : V) :
B.orthogonal (K ∙ x) = LinearMap.ker (LinearMap.BilinForm.toLinHomAux₁ B x) := by
ext y
simp_rw [mem_orthogonal_iff, LinearMap.mem_ker, Submodule.mem_span_singleton]
constructor
· exact fun h => h x ⟨1, one_smul _ _⟩
· rintro h _ ⟨z, rfl⟩
rw [IsOrtho, smul_left, mul_eq_zero]
exact Or.intro_right _ h
theorem span_singleton_sup_orthogonal_eq_top {B : BilinForm K V} {x : V} (hx : ¬B.IsOrtho x x) :
(K ∙ x) ⊔ B.orthogonal (K ∙ x) = ⊤ := by
rw [orthogonal_span_singleton_eq_toLin_ker]
exact LinearMap.span_singleton_sup_ker_eq_top _ hx
/-- Given a bilinear form `B` and some `x` such that `B x x ≠ 0`, the span of the singleton of `x`
is complement to its orthogonal complement. -/
theorem isCompl_span_singleton_orthogonal {B : BilinForm K V} {x : V} (hx : ¬B.IsOrtho x x) :
IsCompl (K ∙ x) (B.orthogonal <| K ∙ x) :=
{ disjoint := disjoint_iff.2 <| span_singleton_inf_orthogonal_eq_bot hx
codisjoint := codisjoint_iff.2 <| span_singleton_sup_orthogonal_eq_top hx }
end Orthogonal
variable {M₂' : Type*}
variable [AddCommMonoid M₂'] [Module R M₂']
/-- The restriction of a reflexive bilinear form `B` onto a submodule `W` is
nondegenerate if `Disjoint W (B.orthogonal W)`. -/
theorem nondegenerate_restrict_of_disjoint_orthogonal (B : BilinForm R₁ M₁) (b : B.IsRefl)
{W : Submodule R₁ M₁} (hW : Disjoint W (B.orthogonal W)) : (B.restrict W).Nondegenerate := by
rintro ⟨x, hx⟩ b₁
rw [Submodule.mk_eq_zero, ← Submodule.mem_bot R₁]
refine hW.le_bot ⟨hx, fun y hy => ?_⟩
specialize b₁ ⟨y, hy⟩
simp only [restrict_apply, domRestrict_apply] at b₁
exact isOrtho_def.mpr (b x y b₁)
@[deprecated (since := "2024-05-30")]
alias nondegenerateRestrictOfDisjointOrthogonal := nondegenerate_restrict_of_disjoint_orthogonal
/-- An orthogonal basis with respect to a nondegenerate bilinear form has no self-orthogonal
elements. -/
theorem iIsOrtho.not_isOrtho_basis_self_of_nondegenerate {n : Type w} [Nontrivial R]
{B : BilinForm R M} {v : Basis n R M} (h : B.iIsOrtho v) (hB : B.Nondegenerate) (i : n) :
¬B.IsOrtho (v i) (v i) := by
intro ho
refine v.ne_zero i (hB (v i) fun m => ?_)
obtain ⟨vi, rfl⟩ := v.repr.symm.surjective m
rw [Basis.repr_symm_apply, Finsupp.total_apply, Finsupp.sum, sum_right]
apply Finset.sum_eq_zero
rintro j -
rw [smul_right]
convert mul_zero (vi j) using 2
obtain rfl | hij := eq_or_ne i j
· exact ho
· exact h hij
/-- Given an orthogonal basis with respect to a bilinear form, the bilinear form is nondegenerate
iff the basis has no elements which are self-orthogonal. -/
theorem iIsOrtho.nondegenerate_iff_not_isOrtho_basis_self {n : Type w} [Nontrivial R]
[NoZeroDivisors R] (B : BilinForm R M) (v : Basis n R M) (hO : B.iIsOrtho v) :
B.Nondegenerate ↔ ∀ i, ¬B.IsOrtho (v i) (v i) := by
refine ⟨hO.not_isOrtho_basis_self_of_nondegenerate, fun ho m hB => ?_⟩
obtain ⟨vi, rfl⟩ := v.repr.symm.surjective m
rw [LinearEquiv.map_eq_zero_iff]
ext i
rw [Finsupp.zero_apply]
specialize hB (v i)
simp_rw [Basis.repr_symm_apply, Finsupp.total_apply, Finsupp.sum, sum_left, smul_left] at hB
rw [Finset.sum_eq_single i] at hB
· exact eq_zero_of_ne_zero_of_mul_right_eq_zero (ho i) hB
· intro j _ hij
convert mul_zero (vi j) using 2
exact hO hij
· intro hi
convert zero_mul (M₀ := R) _ using 2
exact Finsupp.not_mem_support_iff.mp hi
section
theorem toLin_restrict_ker_eq_inf_orthogonal (B : BilinForm K V) (W : Subspace K V) (b : B.IsRefl) :
(B.domRestrict W).ker.map W.subtype = (W ⊓ B.orthogonal ⊤ : Subspace K V) := by
ext x; constructor <;> intro hx
· rcases hx with ⟨⟨x, hx⟩, hker, rfl⟩
erw [LinearMap.mem_ker] at hker
constructor
· simp [hx]
· intro y _
rw [IsOrtho, b]
change (B.domRestrict W) ⟨x, hx⟩ y = 0
rw [hker]
rfl
· simp_rw [Submodule.mem_map, LinearMap.mem_ker]
refine ⟨⟨x, hx.1⟩, ?_, rfl⟩
ext y
change B x y = 0
rw [b]
exact hx.2 _ Submodule.mem_top
theorem toLin_restrict_range_dualCoannihilator_eq_orthogonal (B : BilinForm K V)
(W : Subspace K V) : (B.domRestrict W).range.dualCoannihilator = B.orthogonal W := by
ext x; constructor <;> rw [mem_orthogonal_iff] <;> intro hx
· intro y hy
rw [Submodule.mem_dualCoannihilator] at hx
exact hx (B.domRestrict W ⟨y, hy⟩) ⟨⟨y, hy⟩, rfl⟩
· rw [Submodule.mem_dualCoannihilator]
rintro _ ⟨⟨w, hw⟩, rfl⟩
exact hx w hw
lemma ker_restrict_eq_of_codisjoint {p q : Submodule R M} (hpq : Codisjoint p q)
{B : LinearMap.BilinForm R M} (hB : ∀ x ∈ p, ∀ y ∈ q, B x y = 0) :
LinearMap.ker (B.restrict p) = (LinearMap.ker B).comap p.subtype := by
ext ⟨z, hz⟩
simp only [LinearMap.mem_ker, Submodule.mem_comap, Submodule.coeSubtype]
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· ext w
obtain ⟨x, hx, y, hy, rfl⟩ := Submodule.exists_add_eq_of_codisjoint hpq w
simpa [hB z hz y hy] using LinearMap.congr_fun h ⟨x, hx⟩
· ext ⟨x, hx⟩
simpa using LinearMap.congr_fun h x
variable [FiniteDimensional K V]
open FiniteDimensional Submodule
variable {B : BilinForm K V}
theorem finrank_add_finrank_orthogonal (b₁ : B.IsRefl) (W : Submodule K V) :
finrank K W + finrank K (B.orthogonal W) =
finrank K V + finrank K (W ⊓ B.orthogonal ⊤ : Subspace K V) := by
rw [← toLin_restrict_ker_eq_inf_orthogonal _ _ b₁, ←
toLin_restrict_range_dualCoannihilator_eq_orthogonal _ _, finrank_map_subtype_eq]
conv_rhs =>
rw [← @Subspace.finrank_add_finrank_dualCoannihilator_eq K V _ _ _ _
(LinearMap.range (B.domRestrict W)),
add_comm, ← add_assoc, add_comm (finrank K (LinearMap.ker (B.domRestrict W))),
LinearMap.finrank_range_add_finrank_ker]
lemma finrank_orthogonal (hB : B.Nondegenerate) (hB₀ : B.IsRefl) (W : Submodule K V) :
finrank K (B.orthogonal W) = finrank K V - finrank K W := by
have := finrank_add_finrank_orthogonal hB₀ (W := W)
rw [B.orthogonal_top hB hB₀, inf_bot_eq, finrank_bot, add_zero] at this
have : finrank K W ≤ finrank K V := finrank_le W
omega
lemma orthogonal_orthogonal (hB : B.Nondegenerate) (hB₀ : B.IsRefl) (W : Submodule K V) :
B.orthogonal (B.orthogonal W) = W := by
apply (eq_of_le_of_finrank_le (LinearMap.BilinForm.le_orthogonal_orthogonal hB₀) _).symm
simp only [finrank_orthogonal hB hB₀]
have : finrank K W ≤ finrank K V := finrank_le W
omega
variable {W : Submodule K V}
lemma isCompl_orthogonal_iff_disjoint (hB₀ : B.IsRefl) :
IsCompl W (B.orthogonal W) ↔ Disjoint W (B.orthogonal W) := by
refine ⟨IsCompl.disjoint, fun h ↦ ⟨h, ?_⟩⟩
rw [codisjoint_iff]
apply (eq_top_of_finrank_eq <| (finrank_le _).antisymm _)
calc
finrank K V ≤ finrank K V + finrank K ↥(W ⊓ B.orthogonal ⊤) := le_self_add
_ ≤ finrank K ↥(W ⊔ B.orthogonal W) + finrank K ↥(W ⊓ B.orthogonal W) := ?_
_ ≤ finrank K ↥(W ⊔ B.orthogonal W) := by simp [h.eq_bot]
rw [finrank_sup_add_finrank_inf_eq, finrank_add_finrank_orthogonal hB₀ W]
/-- A subspace is complement to its orthogonal complement with respect to some
reflexive bilinear form if that bilinear form restricted on to the subspace is nondegenerate. -/
theorem isCompl_orthogonal_of_restrict_nondegenerate
(b₁ : B.IsRefl) (b₂ : (B.restrict W).Nondegenerate) : IsCompl W (B.orthogonal W) := by
have : W ⊓ B.orthogonal W = ⊥ := by
rw [eq_bot_iff]
intro x hx
obtain ⟨hx₁, hx₂⟩ := mem_inf.1 hx
refine Subtype.mk_eq_mk.1 (b₂ ⟨x, hx₁⟩ ?_)
rintro ⟨n, hn⟩
simp only [restrict_apply, domRestrict_apply]
exact b₁ n x (b₁ x n (b₁ n x (hx₂ n hn)))
refine IsCompl.of_eq this (eq_top_of_finrank_eq <| (finrank_le _).antisymm ?_)
conv_rhs => rw [← add_zero (finrank K _)]
rw [← finrank_bot K V, ← this, finrank_sup_add_finrank_inf_eq,
finrank_add_finrank_orthogonal b₁]
exact le_self_add
@[deprecated (since := "2024-05-24")]
alias restrict_nondegenerate_of_isCompl_orthogonal := isCompl_orthogonal_of_restrict_nondegenerate
/-- A subspace is complement to its orthogonal complement with respect to some reflexive bilinear
form if and only if that bilinear form restricted on to the subspace is nondegenerate. -/
theorem restrict_nondegenerate_iff_isCompl_orthogonal
(b₁ : B.IsRefl) : (B.restrict W).Nondegenerate ↔ IsCompl W (B.orthogonal W) :=
⟨fun b₂ => isCompl_orthogonal_of_restrict_nondegenerate b₁ b₂, fun h =>
B.nondegenerate_restrict_of_disjoint_orthogonal b₁ h.1⟩
lemma orthogonal_eq_top_iff (b₁ : B.IsRefl) (b₂ : (B.restrict W).Nondegenerate) :
B.orthogonal W = ⊤ ↔ W = ⊥ := by
refine ⟨fun h ↦ ?_, fun h ↦ by simp [h]⟩
have := (B.isCompl_orthogonal_of_restrict_nondegenerate b₁ b₂).inf_eq_bot
rwa [h, inf_top_eq] at this
lemma eq_top_of_restrict_nondegenerate_of_orthogonal_eq_bot
(b₁ : B.IsRefl) (b₂ : (B.restrict W).Nondegenerate) (b₃ : B.orthogonal W = ⊥) :
W = ⊤ := by
have := (B.isCompl_orthogonal_of_restrict_nondegenerate b₁ b₂).sup_eq_top
rwa [b₃, sup_bot_eq] at this
lemma orthogonal_eq_bot_iff
(b₁ : B.IsRefl) (b₂ : (B.restrict W).Nondegenerate) (b₃ : B.Nondegenerate) :
B.orthogonal W = ⊥ ↔ W = ⊤ := by
refine ⟨eq_top_of_restrict_nondegenerate_of_orthogonal_eq_bot b₁ b₂, fun h ↦ ?_⟩
rw [h, eq_bot_iff]
exact fun x hx ↦ b₃ x fun y ↦ b₁ y x <| by simpa using hx y
lemma inf_orthogonal_self_le_ker_restrict (b₁ : B.IsRefl) :
W ⊓ B.orthogonal W ≤ (LinearMap.ker <| B.restrict W).map W.subtype := by
rintro v ⟨hv : v ∈ W, hv' : v ∈ B.orthogonal W⟩
simp only [Submodule.mem_map, mem_ker, restrict_apply, Submodule.coeSubtype, Subtype.exists,
exists_and_left, exists_prop, exists_eq_right_right]
refine ⟨?_, hv⟩
ext ⟨w, hw⟩
exact b₁ w v <| hv' w hw
end
/-! We note that we cannot use `BilinForm.restrict_nondegenerate_iff_isCompl_orthogonal` for the
lemma below since the below lemma does not require `V` to be finite dimensional. However,
`BilinForm.restrict_nondegenerate_iff_isCompl_orthogonal` does not require `B` to be nondegenerate
on the whole space. -/
/-- The restriction of a reflexive, non-degenerate bilinear form on the orthogonal complement of
the span of a singleton is also non-degenerate. -/
theorem restrict_nondegenerate_orthogonal_spanSingleton (B : BilinForm K V) (b₁ : B.Nondegenerate)
(b₂ : B.IsRefl) {x : V} (hx : ¬B.IsOrtho x x) :
Nondegenerate <| B.restrict <| B.orthogonal (K ∙ x) := by
refine fun m hm => Submodule.coe_eq_zero.1 (b₁ m.1 fun n => ?_)
have : n ∈ (K ∙ x) ⊔ B.orthogonal (K ∙ x) :=
(span_singleton_sup_orthogonal_eq_top hx).symm ▸ Submodule.mem_top
rcases Submodule.mem_sup.1 this with ⟨y, hy, z, hz, rfl⟩
specialize hm ⟨z, hz⟩
rw [restrict] at hm
erw [add_right, show B m.1 y = 0 by rw [b₂]; exact m.2 y hy, hm, add_zero]
@[deprecated (since := "2024-05-30")]
alias restrictNondegenerateOrthogonalSpanSingleton :=
restrict_nondegenerate_orthogonal_spanSingleton
end BilinForm
end LinearMap
|
LinearAlgebra\BilinearForm\Properties.lean | /-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andreas Swerdlow, Kexing Ying
-/
import Mathlib.LinearAlgebra.BilinearForm.Hom
import Mathlib.LinearAlgebra.Dual
/-!
# Bilinear form
This file defines various properties of bilinear forms, including reflexivity, symmetry,
alternativity, adjoint, and non-degeneracy.
For orthogonality, see `LinearAlgebra/BilinearForm/Orthogonal.lean`.
## Notations
Given any term `B` of type `BilinForm`, due to a coercion, can use
the notation `B x y` to refer to the function field, ie. `B x y = B.bilin x y`.
In this file we use the following type variables:
- `M`, `M'`, ... are modules over the commutative semiring `R`,
- `M₁`, `M₁'`, ... are modules over the commutative ring `R₁`,
- `V`, ... is a vector space over the field `K`.
## References
* <https://en.wikipedia.org/wiki/Bilinear_form>
## Tags
Bilinear form,
-/
open LinearMap (BilinForm)
universe u v w
variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M]
variable {R₁ : Type*} {M₁ : Type*} [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁]
variable {V : Type*} {K : Type*} [Field K] [AddCommGroup V] [Module K V]
variable {M' M'' : Type*}
variable [AddCommMonoid M'] [AddCommMonoid M''] [Module R M'] [Module R M'']
variable {B : BilinForm R M} {B₁ : BilinForm R₁ M₁}
namespace LinearMap
namespace BilinForm
/-! ### Reflexivity, symmetry, and alternativity -/
/-- The proposition that a bilinear form is reflexive -/
def IsRefl (B : BilinForm R M) : Prop := LinearMap.IsRefl B
namespace IsRefl
theorem eq_zero (H : B.IsRefl) : ∀ {x y : M}, B x y = 0 → B y x = 0 := fun {x y} => H x y
protected theorem neg {B : BilinForm R₁ M₁} (hB : B.IsRefl) : (-B).IsRefl := fun x y =>
neg_eq_zero.mpr ∘ hB x y ∘ neg_eq_zero.mp
protected theorem smul {α} [CommSemiring α] [Module α R] [SMulCommClass R α R]
[NoZeroSMulDivisors α R] (a : α) {B : BilinForm R M} (hB : B.IsRefl) :
(a • B).IsRefl := fun _ _ h =>
(smul_eq_zero.mp h).elim (fun ha => smul_eq_zero_of_left ha _) fun hBz =>
smul_eq_zero_of_right _ (hB _ _ hBz)
protected theorem groupSMul {α} [Group α] [DistribMulAction α R] [SMulCommClass R α R] (a : α)
{B : BilinForm R M} (hB : B.IsRefl) : (a • B).IsRefl := fun x y =>
(smul_eq_zero_iff_eq _).mpr ∘ hB x y ∘ (smul_eq_zero_iff_eq _).mp
end IsRefl
@[simp]
theorem isRefl_zero : (0 : BilinForm R M).IsRefl := fun _ _ _ => rfl
@[simp]
theorem isRefl_neg {B : BilinForm R₁ M₁} : (-B).IsRefl ↔ B.IsRefl :=
⟨fun h => neg_neg B ▸ h.neg, IsRefl.neg⟩
/-- The proposition that a bilinear form is symmetric -/
def IsSymm (B : BilinForm R M) : Prop := LinearMap.IsSymm B
namespace IsSymm
protected theorem eq (H : B.IsSymm) (x y : M) : B x y = B y x :=
H x y
theorem isRefl (H : B.IsSymm) : B.IsRefl := fun x y H1 => H x y ▸ H1
protected theorem add {B₁ B₂ : BilinForm R M} (hB₁ : B₁.IsSymm) (hB₂ : B₂.IsSymm) :
(B₁ + B₂).IsSymm := fun x y => (congr_arg₂ (· + ·) (hB₁ x y) (hB₂ x y) : _)
protected theorem sub {B₁ B₂ : BilinForm R₁ M₁} (hB₁ : B₁.IsSymm) (hB₂ : B₂.IsSymm) :
(B₁ - B₂).IsSymm := fun x y => (congr_arg₂ Sub.sub (hB₁ x y) (hB₂ x y) : _)
protected theorem neg {B : BilinForm R₁ M₁} (hB : B.IsSymm) : (-B).IsSymm := fun x y =>
congr_arg Neg.neg (hB x y)
protected theorem smul {α} [Monoid α] [DistribMulAction α R] [SMulCommClass R α R] (a : α)
{B : BilinForm R M} (hB : B.IsSymm) : (a • B).IsSymm := fun x y =>
congr_arg (a • ·) (hB x y)
/-- The restriction of a symmetric bilinear form on a submodule is also symmetric. -/
theorem restrict {B : BilinForm R M} (b : B.IsSymm) (W : Submodule R M) :
(B.restrict W).IsSymm := fun x y => b x y
end IsSymm
@[simp]
theorem isSymm_zero : (0 : BilinForm R M).IsSymm := fun _ _ => rfl
@[simp]
theorem isSymm_neg {B : BilinForm R₁ M₁} : (-B).IsSymm ↔ B.IsSymm :=
⟨fun h => neg_neg B ▸ h.neg, IsSymm.neg⟩
variable (R₂) in
theorem isSymm_iff_flip : B.IsSymm ↔ flipHom B = B :=
(forall₂_congr fun _ _ => by exact eq_comm).trans BilinForm.ext_iff.symm
/-- The proposition that a bilinear form is alternating -/
def IsAlt (B : BilinForm R M) : Prop := LinearMap.IsAlt B
namespace IsAlt
theorem self_eq_zero (H : B.IsAlt) (x : M) : B x x = 0 := LinearMap.IsAlt.self_eq_zero H x
theorem neg_eq (H : B₁.IsAlt) (x y : M₁) : -B₁ x y = B₁ y x := LinearMap.IsAlt.neg H x y
theorem isRefl (H : B₁.IsAlt) : B₁.IsRefl := LinearMap.IsAlt.isRefl H
theorem eq_of_add_add_eq_zero [IsCancelAdd R] {a b c : M} (H : B.IsAlt) (hAdd : a + b + c = 0) :
B a b = B b c := LinearMap.IsAlt.eq_of_add_add_eq_zero H hAdd
protected theorem add {B₁ B₂ : BilinForm R M} (hB₁ : B₁.IsAlt) (hB₂ : B₂.IsAlt) : (B₁ + B₂).IsAlt :=
fun x => (congr_arg₂ (· + ·) (hB₁ x) (hB₂ x) : _).trans <| add_zero _
protected theorem sub {B₁ B₂ : BilinForm R₁ M₁} (hB₁ : B₁.IsAlt) (hB₂ : B₂.IsAlt) :
(B₁ - B₂).IsAlt := fun x => (congr_arg₂ Sub.sub (hB₁ x) (hB₂ x)).trans <| sub_zero _
protected theorem neg {B : BilinForm R₁ M₁} (hB : B.IsAlt) : (-B).IsAlt := fun x =>
neg_eq_zero.mpr <| hB x
protected theorem smul {α} [Monoid α] [DistribMulAction α R] [SMulCommClass R α R] (a : α)
{B : BilinForm R M} (hB : B.IsAlt) : (a • B).IsAlt := fun x =>
(congr_arg (a • ·) (hB x)).trans <| smul_zero _
end IsAlt
@[simp]
theorem isAlt_zero : (0 : BilinForm R M).IsAlt := fun _ => rfl
@[simp]
theorem isAlt_neg {B : BilinForm R₁ M₁} : (-B).IsAlt ↔ B.IsAlt :=
⟨fun h => neg_neg B ▸ h.neg, IsAlt.neg⟩
/-! ### Linear adjoints -/
section LinearAdjoints
variable (B) (F : BilinForm R M)
variable {M' : Type*} [AddCommMonoid M'] [Module R M']
variable (B' : BilinForm R M') (f f' : M →ₗ[R] M') (g g' : M' →ₗ[R] M)
/-- Given a pair of modules equipped with bilinear forms, this is the condition for a pair of
maps between them to be mutually adjoint. -/
def IsAdjointPair :=
∀ ⦃x y⦄, B' (f x) y = B x (g y)
variable {B B' f f' g g'}
theorem IsAdjointPair.eq (h : IsAdjointPair B B' f g) : ∀ {x y}, B' (f x) y = B x (g y) :=
@h
theorem isAdjointPair_iff_compLeft_eq_compRight (f g : Module.End R M) :
IsAdjointPair B F f g ↔ F.compLeft f = B.compRight g := by
constructor <;> intro h
· ext x
simp only [compLeft_apply, compRight_apply]
apply h
· intro x y
rw [← compLeft_apply, ← compRight_apply]
rw [h]
theorem isAdjointPair_zero : IsAdjointPair B B' 0 0 := fun x y => by
simp only [BilinForm.zero_left, BilinForm.zero_right, LinearMap.zero_apply]
theorem isAdjointPair_id : IsAdjointPair B B 1 1 := fun _ _ => rfl
theorem IsAdjointPair.add (h : IsAdjointPair B B' f g) (h' : IsAdjointPair B B' f' g') :
IsAdjointPair B B' (f + f') (g + g') := fun x y => by
rw [LinearMap.add_apply, LinearMap.add_apply, add_left, add_right, h, h']
variable {M₁' : Type*} [AddCommGroup M₁'] [Module R₁ M₁']
variable {B₁' : BilinForm R₁ M₁'} {f₁ f₁' : M₁ →ₗ[R₁] M₁'} {g₁ g₁' : M₁' →ₗ[R₁] M₁}
theorem IsAdjointPair.sub (h : IsAdjointPair B₁ B₁' f₁ g₁) (h' : IsAdjointPair B₁ B₁' f₁' g₁') :
IsAdjointPair B₁ B₁' (f₁ - f₁') (g₁ - g₁') := fun x y => by
rw [LinearMap.sub_apply, LinearMap.sub_apply, sub_left, sub_right, h, h']
variable {B₂' : BilinForm R M'} {f₂ f₂' : M →ₗ[R] M'} {g₂ g₂' : M' →ₗ[R] M}
theorem IsAdjointPair.smul (c : R) (h : IsAdjointPair B B₂' f₂ g₂) :
IsAdjointPair B B₂' (c • f₂) (c • g₂) := fun x y => by
rw [LinearMap.smul_apply, LinearMap.smul_apply, smul_left, smul_right, h]
variable {M'' : Type*} [AddCommMonoid M''] [Module R M'']
variable (B'' : BilinForm R M'')
theorem IsAdjointPair.comp {f' : M' →ₗ[R] M''} {g' : M'' →ₗ[R] M'} (h : IsAdjointPair B B' f g)
(h' : IsAdjointPair B' B'' f' g') : IsAdjointPair B B'' (f'.comp f) (g.comp g') := fun x y => by
rw [LinearMap.comp_apply, LinearMap.comp_apply, h', h]
theorem IsAdjointPair.mul {f g f' g' : Module.End R M} (h : IsAdjointPair B B f g)
(h' : IsAdjointPair B B f' g') : IsAdjointPair B B (f * f') (g' * g) := fun x y => by
rw [LinearMap.mul_apply, LinearMap.mul_apply, h, h']
variable (B B' B₁ B₂) (F₂ : BilinForm R M)
/-- The condition for an endomorphism to be "self-adjoint" with respect to a pair of bilinear forms
on the underlying module. In the case that these two forms are identical, this is the usual concept
of self adjointness. In the case that one of the forms is the negation of the other, this is the
usual concept of skew adjointness. -/
def IsPairSelfAdjoint (f : Module.End R M) :=
IsAdjointPair B F f f
/-- The set of pair-self-adjoint endomorphisms are a submodule of the type of all endomorphisms. -/
def isPairSelfAdjointSubmodule : Submodule R (Module.End R M) where
carrier := { f | IsPairSelfAdjoint B₂ F₂ f }
zero_mem' := isAdjointPair_zero
add_mem' hf hg := hf.add hg
smul_mem' c _ h := h.smul c
@[simp]
theorem mem_isPairSelfAdjointSubmodule (f : Module.End R M) :
f ∈ isPairSelfAdjointSubmodule B₂ F₂ ↔ IsPairSelfAdjoint B₂ F₂ f := Iff.rfl
theorem isPairSelfAdjoint_equiv (e : M' ≃ₗ[R] M) (f : Module.End R M) :
IsPairSelfAdjoint B₂ F₂ f ↔
IsPairSelfAdjoint (B₂.comp ↑e ↑e) (F₂.comp ↑e ↑e) (e.symm.conj f) := by
have hₗ : (F₂.comp ↑e ↑e).compLeft (e.symm.conj f) = (F₂.compLeft f).comp ↑e ↑e := by
ext
simp [LinearEquiv.symm_conj_apply]
have hᵣ : (B₂.comp ↑e ↑e).compRight (e.symm.conj f) = (B₂.compRight f).comp ↑e ↑e := by
ext
simp [LinearEquiv.conj_apply]
have he : Function.Surjective (⇑(↑e : M' →ₗ[R] M) : M' → M) := e.surjective
show BilinForm.IsAdjointPair _ _ _ _ ↔ BilinForm.IsAdjointPair _ _ _ _
rw [isAdjointPair_iff_compLeft_eq_compRight, isAdjointPair_iff_compLeft_eq_compRight, hᵣ,
hₗ, comp_inj _ _ he he]
/-- An endomorphism of a module is self-adjoint with respect to a bilinear form if it serves as an
adjoint for itself. -/
def IsSelfAdjoint (f : Module.End R M) :=
IsAdjointPair B B f f
/-- An endomorphism of a module is skew-adjoint with respect to a bilinear form if its negation
serves as an adjoint. -/
def IsSkewAdjoint (f : Module.End R₁ M₁) :=
IsAdjointPair B₁ B₁ f (-f)
theorem isSkewAdjoint_iff_neg_self_adjoint (f : Module.End R₁ M₁) :
B₁.IsSkewAdjoint f ↔ IsAdjointPair (-B₁) B₁ f f :=
show (∀ x y, B₁ (f x) y = B₁ x ((-f) y)) ↔ ∀ x y, B₁ (f x) y = (-B₁) x (f y) by
simp only [LinearMap.neg_apply, BilinForm.neg_apply, BilinForm.neg_right]
/-- The set of self-adjoint endomorphisms of a module with bilinear form is a submodule. (In fact
it is a Jordan subalgebra.) -/
def selfAdjointSubmodule :=
isPairSelfAdjointSubmodule B B
@[simp]
theorem mem_selfAdjointSubmodule (f : Module.End R M) :
f ∈ B.selfAdjointSubmodule ↔ B.IsSelfAdjoint f :=
Iff.rfl
/-- The set of skew-adjoint endomorphisms of a module with bilinear form is a submodule. (In fact
it is a Lie subalgebra.) -/
def skewAdjointSubmodule :=
isPairSelfAdjointSubmodule (-B₁) B₁
@[simp]
theorem mem_skewAdjointSubmodule (f : Module.End R₁ M₁) :
f ∈ B₁.skewAdjointSubmodule ↔ B₁.IsSkewAdjoint f := by
rw [isSkewAdjoint_iff_neg_self_adjoint]
exact Iff.rfl
end LinearAdjoints
end BilinForm
namespace BilinForm
/-- A nondegenerate bilinear form is a bilinear form such that the only element that is orthogonal
to every other element is `0`; i.e., for all nonzero `m` in `M`, there exists `n` in `M` with
`B m n ≠ 0`.
Note that for general (neither symmetric nor antisymmetric) bilinear forms this definition has a
chirality; in addition to this "left" nondegeneracy condition one could define a "right"
nondegeneracy condition that in the situation described, `B n m ≠ 0`. This variant definition is
not currently provided in mathlib. In finite dimension either definition implies the other. -/
def Nondegenerate (B : BilinForm R M) : Prop :=
∀ m : M, (∀ n : M, B m n = 0) → m = 0
section
variable (R M)
/-- In a non-trivial module, zero is not non-degenerate. -/
theorem not_nondegenerate_zero [Nontrivial M] : ¬(0 : BilinForm R M).Nondegenerate :=
let ⟨m, hm⟩ := exists_ne (0 : M)
fun h => hm (h m fun _ => rfl)
end
variable {M' : Type*}
variable [AddCommMonoid M'] [Module R M']
theorem Nondegenerate.ne_zero [Nontrivial M] {B : BilinForm R M} (h : B.Nondegenerate) : B ≠ 0 :=
fun h0 => not_nondegenerate_zero R M <| h0 ▸ h
theorem Nondegenerate.congr {B : BilinForm R M} (e : M ≃ₗ[R] M') (h : B.Nondegenerate) :
(congr e B).Nondegenerate := fun m hm =>
e.symm.map_eq_zero_iff.1 <|
h (e.symm m) fun n => (congr_arg _ (e.symm_apply_apply n).symm).trans (hm (e n))
@[simp]
theorem nondegenerate_congr_iff {B : BilinForm R M} (e : M ≃ₗ[R] M') :
(congr e B).Nondegenerate ↔ B.Nondegenerate :=
⟨fun h => by
convert h.congr e.symm
rw [congr_congr, e.self_trans_symm, congr_refl, LinearEquiv.refl_apply], Nondegenerate.congr e⟩
/-- A bilinear form is nondegenerate if and only if it has a trivial kernel. -/
theorem nondegenerate_iff_ker_eq_bot {B : BilinForm R M} :
B.Nondegenerate ↔ LinearMap.ker B = ⊥ := by
rw [LinearMap.ker_eq_bot']
constructor <;> intro h
· refine fun m hm => h _ fun x => ?_
rw [hm]
rfl
· intro m hm
apply h
ext x
exact hm x
theorem Nondegenerate.ker_eq_bot {B : BilinForm R M} (h : B.Nondegenerate) :
LinearMap.ker B = ⊥ := nondegenerate_iff_ker_eq_bot.mp h
theorem compLeft_injective (B : BilinForm R₁ M₁) (b : B.Nondegenerate) :
Function.Injective B.compLeft := fun φ ψ h => by
ext w
refine eq_of_sub_eq_zero (b _ ?_)
intro v
rw [sub_left, ← compLeft_apply, ← compLeft_apply, ← h, sub_self]
theorem isAdjointPair_unique_of_nondegenerate (B : BilinForm R₁ M₁) (b : B.Nondegenerate)
(φ ψ₁ ψ₂ : M₁ →ₗ[R₁] M₁) (hψ₁ : IsAdjointPair B B ψ₁ φ) (hψ₂ : IsAdjointPair B B ψ₂ φ) :
ψ₁ = ψ₂ :=
B.compLeft_injective b <| ext fun v w => by rw [compLeft_apply, compLeft_apply, hψ₁, hψ₂]
section FiniteDimensional
variable [FiniteDimensional K V]
/-- Given a nondegenerate bilinear form `B` on a finite-dimensional vector space, `B.toDual` is
the linear equivalence between a vector space and its dual. -/
noncomputable def toDual (B : BilinForm K V) (b : B.Nondegenerate) : V ≃ₗ[K] Module.Dual K V :=
B.linearEquivOfInjective (LinearMap.ker_eq_bot.mp <| b.ker_eq_bot)
Subspace.dual_finrank_eq.symm
theorem toDual_def {B : BilinForm K V} (b : B.SeparatingLeft) {m n : V} : B.toDual b m n = B m n :=
rfl
@[simp]
lemma apply_toDual_symm_apply {B : BilinForm K V} {hB : B.Nondegenerate}
(f : Module.Dual K V) (v : V) :
B ((B.toDual hB).symm f) v = f v := by
change B.toDual hB ((B.toDual hB).symm f) v = f v
simp only [LinearEquiv.apply_symm_apply]
lemma Nondegenerate.flip {B : BilinForm K V} (hB : B.Nondegenerate) :
B.flip.Nondegenerate := by
intro x hx
apply (Module.evalEquiv K V).injective
ext f
obtain ⟨y, rfl⟩ := (B.toDual hB).surjective f
simpa using hx y
lemma nonDegenerateFlip_iff {B : BilinForm K V} :
B.flip.Nondegenerate ↔ B.Nondegenerate := ⟨Nondegenerate.flip, Nondegenerate.flip⟩
end FiniteDimensional
section DualBasis
variable {ι : Type*} [DecidableEq ι] [Finite ι]
/-- The `B`-dual basis `B.dualBasis hB b` to a finite basis `b` satisfies
`B (B.dualBasis hB b i) (b j) = B (b i) (B.dualBasis hB b j) = if i = j then 1 else 0`,
where `B` is a nondegenerate (symmetric) bilinear form and `b` is a finite basis. -/
noncomputable def dualBasis (B : BilinForm K V) (hB : B.Nondegenerate) (b : Basis ι K V) :
Basis ι K V :=
haveI := FiniteDimensional.of_fintype_basis b
b.dualBasis.map (B.toDual hB).symm
@[simp]
theorem dualBasis_repr_apply
(B : BilinForm K V) (hB : B.Nondegenerate) (b : Basis ι K V) (x i) :
(B.dualBasis hB b).repr x i = B x (b i) := by
rw [dualBasis, Basis.map_repr, LinearEquiv.symm_symm, LinearEquiv.trans_apply,
Basis.dualBasis_repr]
rfl
theorem apply_dualBasis_left (B : BilinForm K V) (hB : B.Nondegenerate) (b : Basis ι K V) (i j) :
B (B.dualBasis hB b i) (b j) = if j = i then 1 else 0 := by
have := FiniteDimensional.of_fintype_basis b
rw [dualBasis, Basis.map_apply, Basis.coe_dualBasis, ← toDual_def hB,
LinearEquiv.apply_symm_apply, Basis.coord_apply, Basis.repr_self, Finsupp.single_apply]
theorem apply_dualBasis_right (B : BilinForm K V) (hB : B.Nondegenerate) (sym : B.IsSymm)
(b : Basis ι K V) (i j) : B (b i) (B.dualBasis hB b j) = if i = j then 1 else 0 := by
rw [sym.eq, apply_dualBasis_left]
@[simp]
lemma dualBasis_dualBasis_flip [FiniteDimensional K V]
(B : BilinForm K V) (hB : B.Nondegenerate) {ι : Type*}
[Finite ι] [DecidableEq ι] (b : Basis ι K V) :
B.dualBasis hB (B.flip.dualBasis hB.flip b) = b := by
ext i
refine LinearMap.ker_eq_bot.mp hB.ker_eq_bot ((B.flip.dualBasis hB.flip b).ext (fun j ↦ ?_))
simp_rw [apply_dualBasis_left, ← B.flip_apply, apply_dualBasis_left, @eq_comm _ i j]
@[simp]
lemma dualBasis_flip_dualBasis (B : BilinForm K V) (hB : B.Nondegenerate) {ι}
[Finite ι] [DecidableEq ι] [FiniteDimensional K V] (b : Basis ι K V) :
B.flip.dualBasis hB.flip (B.dualBasis hB b) = b :=
dualBasis_dualBasis_flip _ hB.flip b
@[simp]
lemma dualBasis_dualBasis (B : BilinForm K V) (hB : B.Nondegenerate) (hB' : B.IsSymm) {ι}
[Finite ι] [DecidableEq ι] [FiniteDimensional K V] (b : Basis ι K V) :
B.dualBasis hB (B.dualBasis hB b) = b := by
convert dualBasis_dualBasis_flip _ hB.flip b
rwa [eq_comm, ← isSymm_iff_flip]
end DualBasis
section LinearAdjoints
variable [FiniteDimensional K V]
/-- Given bilinear forms `B₁, B₂` where `B₂` is nondegenerate, `symmCompOfNondegenerate`
is the linear map `B₂ ∘ B₁`. -/
noncomputable def symmCompOfNondegenerate (B₁ B₂ : BilinForm K V) (b₂ : B₂.Nondegenerate) :
V →ₗ[K] V :=
(B₂.toDual b₂).symm.toLinearMap.comp B₁
theorem comp_symmCompOfNondegenerate_apply (B₁ : BilinForm K V) {B₂ : BilinForm K V}
(b₂ : B₂.Nondegenerate) (v : V) :
B₂ (B₁.symmCompOfNondegenerate B₂ b₂ v) = B₁ v := by
erw [symmCompOfNondegenerate]
simp only [coe_comp, LinearEquiv.coe_coe, Function.comp_apply, DFunLike.coe_fn_eq]
erw [LinearEquiv.apply_symm_apply (B₂.toDual b₂)]
@[simp]
theorem symmCompOfNondegenerate_left_apply (B₁ : BilinForm K V) {B₂ : BilinForm K V}
(b₂ : B₂.Nondegenerate) (v w : V) : B₂ (symmCompOfNondegenerate B₁ B₂ b₂ w) v = B₁ w v := by
conv_lhs => rw [comp_symmCompOfNondegenerate_apply]
/-- Given the nondegenerate bilinear form `B` and the linear map `φ`,
`leftAdjointOfNondegenerate` provides the left adjoint of `φ` with respect to `B`.
The lemma proving this property is `BilinForm.isAdjointPairLeftAdjointOfNondegenerate`. -/
noncomputable def leftAdjointOfNondegenerate (B : BilinForm K V) (b : B.Nondegenerate)
(φ : V →ₗ[K] V) : V →ₗ[K] V :=
symmCompOfNondegenerate (B.compRight φ) B b
theorem isAdjointPairLeftAdjointOfNondegenerate (B : BilinForm K V) (b : B.Nondegenerate)
(φ : V →ₗ[K] V) : IsAdjointPair B B (B.leftAdjointOfNondegenerate b φ) φ := fun x y =>
(B.compRight φ).symmCompOfNondegenerate_left_apply b y x
/-- Given the nondegenerate bilinear form `B`, the linear map `φ` has a unique left adjoint given by
`BilinForm.leftAdjointOfNondegenerate`. -/
theorem isAdjointPair_iff_eq_of_nondegenerate (B : BilinForm K V) (b : B.Nondegenerate)
(ψ φ : V →ₗ[K] V) : IsAdjointPair B B ψ φ ↔ ψ = B.leftAdjointOfNondegenerate b φ :=
⟨fun h =>
B.isAdjointPair_unique_of_nondegenerate b φ ψ _ h
(isAdjointPairLeftAdjointOfNondegenerate _ _ _),
fun h => h.symm ▸ isAdjointPairLeftAdjointOfNondegenerate _ _ _⟩
end LinearAdjoints
end BilinForm
end LinearMap
|
LinearAlgebra\BilinearForm\TensorProduct.lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.Dual
import Mathlib.LinearAlgebra.TensorProduct.Tower
/-!
# The bilinear form on a tensor product
## Main definitions
* `LinearMap.BilinMap.tensorDistrib (B₁ ⊗ₜ B₂)`: the bilinear form on `M₁ ⊗ M₂` constructed by
applying `B₁` on `M₁` and `B₂` on `M₂`.
* `LinearMap.BilinMap.tensorDistribEquiv`: `BilinForm.tensorDistrib` as an equivalence on finite
free modules.
-/
suppress_compilation
universe u v w uι uR uA uM₁ uM₂
variable {ι : Type uι} {R : Type uR} {A : Type uA} {M₁ : Type uM₁} {M₂ : Type uM₂}
open TensorProduct
namespace LinearMap
namespace BilinMap
open LinearMap (BilinMap)
open LinearMap (BilinForm)
section CommSemiring
variable [CommSemiring R] [CommSemiring A]
variable [AddCommMonoid M₁] [AddCommMonoid M₂]
variable [Algebra R A] [Module R M₁] [Module A M₁]
variable [SMulCommClass R A M₁] [SMulCommClass A R M₁] [IsScalarTower R A M₁]
variable [Module R M₂]
variable (R A) in
/-- The tensor product of two bilinear forms injects into bilinear forms on tensor products.
Note this is heterobasic; the bilinear form on the left can take values in an (commutative) algebra
over the ring in which the right bilinear form is valued. -/
def tensorDistrib : BilinForm A M₁ ⊗[R] BilinForm R M₂ →ₗ[A] BilinForm A (M₁ ⊗[R] M₂) :=
((TensorProduct.AlgebraTensorModule.tensorTensorTensorComm R A M₁ M₂ M₁ M₂).dualMap
≪≫ₗ (TensorProduct.lift.equiv A (M₁ ⊗[R] M₂) (M₁ ⊗[R] M₂) A).symm).toLinearMap
∘ₗ TensorProduct.AlgebraTensorModule.dualDistrib R _ _ _
∘ₗ (TensorProduct.AlgebraTensorModule.congr
(TensorProduct.lift.equiv A M₁ M₁ A)
(TensorProduct.lift.equiv R _ _ _)).toLinearMap
-- TODO: make the RHS `MulOpposite.op (B₂ m₂ m₂') • B₁ m₁ m₁'` so that this has a nicer defeq for
-- `R = A` of `B₁ m₁ m₁' * B₂ m₂ m₂'`, as it did before the generalization in #6306.
@[simp]
theorem tensorDistrib_tmul (B₁ : BilinForm A M₁) (B₂ : BilinForm R M₂) (m₁ : M₁) (m₂ : M₂)
(m₁' : M₁) (m₂' : M₂) :
tensorDistrib R A (B₁ ⊗ₜ B₂) (m₁ ⊗ₜ m₂) (m₁' ⊗ₜ m₂')
= B₂ m₂ m₂' • B₁ m₁ m₁' :=
rfl
/-- The tensor product of two bilinear forms, a shorthand for dot notation. -/
protected abbrev tmul (B₁ : BilinMap A M₁ A) (B₂ : BilinMap R M₂ R) : BilinMap A (M₁ ⊗[R] M₂) A :=
tensorDistrib R A (B₁ ⊗ₜ[R] B₂)
attribute [local ext] TensorProduct.ext in
/-- A tensor product of symmetric bilinear forms is symmetric. -/
lemma _root_.LinearMap.IsSymm.tmul {B₁ : BilinMap A M₁ A} {B₂ : BilinMap R M₂ R}
(hB₁ : B₁.IsSymm) (hB₂ : B₂.IsSymm) : (B₁.tmul B₂).IsSymm := by
rw [LinearMap.isSymm_iff_eq_flip]
ext x₁ x₂ y₁ y₂
exact congr_arg₂ (HSMul.hSMul) (hB₂ x₂ y₂) (hB₁ x₁ y₁)
variable (A) in
/-- The base change of a bilinear form. -/
protected def baseChange (B : BilinMap R M₂ R) : BilinForm A (A ⊗[R] M₂) :=
BilinMap.tmul (R := R) (A := A) (M₁ := A) (M₂ := M₂) (LinearMap.mul A A) B
@[simp]
theorem baseChange_tmul (B₂ : BilinMap R M₂ R) (a : A) (m₂ : M₂)
(a' : A) (m₂' : M₂) :
B₂.baseChange A (a ⊗ₜ m₂) (a' ⊗ₜ m₂') = (B₂ m₂ m₂') • (a * a') :=
rfl
variable (A) in
/-- The base change of a symmetric bilinear form is symmetric. -/
lemma IsSymm.baseChange {B₂ : BilinForm R M₂} (hB₂ : B₂.IsSymm) : (B₂.baseChange A).IsSymm :=
IsSymm.tmul mul_comm hB₂
end CommSemiring
section CommRing
variable [CommRing R]
variable [AddCommGroup M₁] [AddCommGroup M₂]
variable [Module R M₁] [Module R M₂]
variable [Module.Free R M₁] [Module.Finite R M₁]
variable [Module.Free R M₂] [Module.Finite R M₂]
variable [Nontrivial R]
variable (R) in
/-- `tensorDistrib` as an equivalence. -/
noncomputable def tensorDistribEquiv :
BilinForm R M₁ ⊗[R] BilinForm R M₂ ≃ₗ[R] BilinForm R (M₁ ⊗[R] M₂) :=
-- the same `LinearEquiv`s as from `tensorDistrib`,
-- but with the inner linear map also as an equiv
TensorProduct.congr (TensorProduct.lift.equiv R _ _ _) (TensorProduct.lift.equiv R _ _ _) ≪≫ₗ
TensorProduct.dualDistribEquiv R (M₁ ⊗ M₁) (M₂ ⊗ M₂) ≪≫ₗ
(TensorProduct.tensorTensorTensorComm R _ _ _ _).dualMap ≪≫ₗ
(TensorProduct.lift.equiv R _ _ _).symm
@[simp]
theorem tensorDistribEquiv_tmul (B₁ : BilinForm R M₁) (B₂ : BilinForm R M₂) (m₁ : M₁) (m₂ : M₂)
(m₁' : M₁) (m₂' : M₂) :
tensorDistribEquiv R (M₁ := M₁) (M₂ := M₂) (B₁ ⊗ₜ[R] B₂) (m₁ ⊗ₜ m₂) (m₁' ⊗ₜ m₂')
= B₁ m₁ m₁' * B₂ m₂ m₂' :=
rfl
variable (R M₁ M₂) in
-- TODO: make this `rfl`
@[simp]
theorem tensorDistribEquiv_toLinearMap :
(tensorDistribEquiv R (M₁ := M₁) (M₂ := M₂)).toLinearMap = tensorDistrib R R := by
ext B₁ B₂ : 3
ext
exact mul_comm _ _
@[simp]
theorem tensorDistribEquiv_apply (B : BilinForm R M₁ ⊗ BilinForm R M₂) :
tensorDistribEquiv R (M₁ := M₁) (M₂ := M₂) B = tensorDistrib R R B :=
DFunLike.congr_fun (tensorDistribEquiv_toLinearMap R M₁ M₂) B
end CommRing
end BilinMap
end LinearMap
|
LinearAlgebra\Charpoly\Basic.lean | /-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
import Mathlib.FieldTheory.Minpoly.Field
/-!
# Characteristic polynomial
We define the characteristic polynomial of `f : M →ₗ[R] M`, where `M` is a finite and
free `R`-module. The proof that `f.charpoly` is the characteristic polynomial of the matrix of `f`
in any basis is in `LinearAlgebra/Charpoly/ToMatrix`.
## Main definition
* `LinearMap.charpoly f` : the characteristic polynomial of `f : M →ₗ[R] M`.
-/
universe u v w
variable {R : Type u} {M : Type v} [CommRing R] [Nontrivial R]
variable [AddCommGroup M] [Module R M] [Module.Free R M] [Module.Finite R M] (f : M →ₗ[R] M)
open Matrix Polynomial
noncomputable section
open Module.Free Polynomial Matrix
namespace LinearMap
section Basic
/-- The characteristic polynomial of `f : M →ₗ[R] M`. -/
def charpoly : R[X] :=
(toMatrix (chooseBasis R M) (chooseBasis R M) f).charpoly
theorem charpoly_def : f.charpoly = (toMatrix (chooseBasis R M) (chooseBasis R M) f).charpoly :=
rfl
end Basic
section Coeff
theorem charpoly_monic : f.charpoly.Monic :=
Matrix.charpoly_monic _
open FiniteDimensional in
lemma charpoly_natDegree [StrongRankCondition R] : natDegree (charpoly f) = finrank R M := by
rw [charpoly, Matrix.charpoly_natDegree_eq_dim, finrank_eq_card_chooseBasisIndex]
end Coeff
section CayleyHamilton
/-- The **Cayley-Hamilton Theorem**, that the characteristic polynomial of a linear map, applied
to the linear map itself, is zero.
See `Matrix.aeval_self_charpoly` for the equivalent statement about matrices. -/
theorem aeval_self_charpoly : aeval f f.charpoly = 0 := by
apply (LinearEquiv.map_eq_zero_iff (algEquivMatrix (chooseBasis R M)).toLinearEquiv).1
rw [AlgEquiv.toLinearEquiv_apply, ← AlgEquiv.coe_algHom, ← Polynomial.aeval_algHom_apply _ _ _,
charpoly_def]
exact Matrix.aeval_self_charpoly _
theorem isIntegral : IsIntegral R f :=
⟨f.charpoly, ⟨charpoly_monic f, aeval_self_charpoly f⟩⟩
theorem minpoly_dvd_charpoly {K : Type u} {M : Type v} [Field K] [AddCommGroup M] [Module K M]
[FiniteDimensional K M] (f : M →ₗ[K] M) : minpoly K f ∣ f.charpoly :=
minpoly.dvd _ _ (aeval_self_charpoly f)
/-- Any endomorphism polynomial `p` is equivalent under evaluation to `p %ₘ f.charpoly`; that is,
`p` is equivalent to a polynomial with degree less than the dimension of the module. -/
theorem aeval_eq_aeval_mod_charpoly (p : R[X]) : aeval f p = aeval f (p %ₘ f.charpoly) :=
(aeval_modByMonic_eq_self_of_root f.charpoly_monic f.aeval_self_charpoly).symm
/-- Any endomorphism power can be computed as the sum of endomorphism powers less than the
dimension of the module. -/
theorem pow_eq_aeval_mod_charpoly (k : ℕ) : f ^ k = aeval f (X ^ k %ₘ f.charpoly) := by
rw [← aeval_eq_aeval_mod_charpoly, map_pow, aeval_X]
variable {f}
theorem minpoly_coeff_zero_of_injective (hf : Function.Injective f) :
(minpoly R f).coeff 0 ≠ 0 := by
intro h
obtain ⟨P, hP⟩ := X_dvd_iff.2 h
have hdegP : P.degree < (minpoly R f).degree := by
rw [hP, mul_comm]
refine degree_lt_degree_mul_X fun h => ?_
rw [h, mul_zero] at hP
exact minpoly.ne_zero (isIntegral f) hP
have hPmonic : P.Monic := by
suffices (minpoly R f).Monic by
rwa [Monic.def, hP, mul_comm, leadingCoeff_mul_X, ← Monic.def] at this
exact minpoly.monic (isIntegral f)
have hzero : aeval f (minpoly R f) = 0 := minpoly.aeval _ _
simp only [hP, mul_eq_comp, LinearMap.ext_iff, hf, aeval_X, map_eq_zero_iff, coe_comp,
_root_.map_mul, zero_apply, Function.comp_apply] at hzero
exact not_le.2 hdegP (minpoly.min _ _ hPmonic (LinearMap.ext hzero))
end CayleyHamilton
end LinearMap
|
LinearAlgebra\Charpoly\ToMatrix.lean | /-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.LinearAlgebra.Charpoly.Basic
import Mathlib.LinearAlgebra.Matrix.Basis
/-!
# Characteristic polynomial
## Main result
* `LinearMap.charpoly_toMatrix f` : `charpoly f` is the characteristic polynomial of the matrix
of `f` in any basis.
-/
universe u v w
variable {R M M₁ M₂ : Type*} [CommRing R] [Nontrivial R]
variable [AddCommGroup M] [Module R M] [Module.Free R M] [Module.Finite R M]
variable [AddCommGroup M₁] [Module R M₁] [Module.Finite R M₁] [Module.Free R M₁]
variable [AddCommGroup M₂] [Module R M₂] [Module.Finite R M₂] [Module.Free R M₂]
variable (f : M →ₗ[R] M)
open Matrix
noncomputable section
open Module.Free Polynomial Matrix
namespace LinearMap
section Basic
/- These attribute tweaks save ~ 2000 heartbeats in `LinearMap.charpoly_toMatrix`. -/
attribute [-instance] instCoeOutOfCoeSort
attribute [local instance 2000] RingHomClass.toNonUnitalRingHomClass
attribute [local instance 2000] NonUnitalRingHomClass.toMulHomClass
/-- `charpoly f` is the characteristic polynomial of the matrix of `f` in any basis. -/
@[simp]
theorem charpoly_toMatrix {ι : Type w} [DecidableEq ι] [Fintype ι] (b : Basis ι R M) :
(toMatrix b b f).charpoly = f.charpoly := by
let A := toMatrix b b f
let b' := chooseBasis R M
let ι' := ChooseBasisIndex R M
let A' := toMatrix b' b' f
let e := Basis.indexEquiv b b'
let φ := reindexLinearEquiv R R e e
let φ₁ := reindexLinearEquiv R R e (Equiv.refl ι')
let φ₂ := reindexLinearEquiv R R (Equiv.refl ι') (Equiv.refl ι')
let φ₃ := reindexLinearEquiv R R (Equiv.refl ι') e
let P := b.toMatrix b'
let Q := b'.toMatrix b
have hPQ : C.mapMatrix (φ₁ P) * C.mapMatrix (φ₃ Q) = 1 := by
rw [RingHom.mapMatrix_apply, RingHom.mapMatrix_apply, ← Matrix.map_mul,
reindexLinearEquiv_mul R R, Basis.toMatrix_mul_toMatrix_flip,
reindexLinearEquiv_one, ← RingHom.mapMatrix_apply, RingHom.map_one]
calc
A.charpoly = (reindex e e A).charpoly := (charpoly_reindex _ _).symm
_ = det (scalar ι' X - C.mapMatrix (φ A)) := rfl
_ = det (scalar ι' X - C.mapMatrix (φ (P * A' * Q))) := by
rw [basis_toMatrix_mul_linearMap_toMatrix_mul_basis_toMatrix]
_ = det (scalar ι' X - C.mapMatrix (φ₁ P * φ₂ A' * φ₃ Q)) := by
rw [reindexLinearEquiv_mul, reindexLinearEquiv_mul]
_ = det (scalar ι' X - C.mapMatrix (φ₁ P) * C.mapMatrix A' * C.mapMatrix (φ₃ Q)) := by simp [φ₂]
_ = det (scalar ι' X * C.mapMatrix (φ₁ P) * C.mapMatrix (φ₃ Q) -
C.mapMatrix (φ₁ P) * C.mapMatrix A' * C.mapMatrix (φ₃ Q)) := by
rw [Matrix.mul_assoc ((scalar ι') X), hPQ, Matrix.mul_one]
_ = det (C.mapMatrix (φ₁ P) * scalar ι' X * C.mapMatrix (φ₃ Q) -
C.mapMatrix (φ₁ P) * C.mapMatrix A' * C.mapMatrix (φ₃ Q)) := by
rw [scalar_commute _ commute_X]
_ = det (C.mapMatrix (φ₁ P) * (scalar ι' X - C.mapMatrix A') * C.mapMatrix (φ₃ Q)) := by
rw [← Matrix.sub_mul, ← Matrix.mul_sub]
_ = det (C.mapMatrix (φ₁ P)) * det (scalar ι' X - C.mapMatrix A') * det (C.mapMatrix (φ₃ Q)) :=
by rw [det_mul, det_mul]
_ = det (C.mapMatrix (φ₁ P)) * det (C.mapMatrix (φ₃ Q)) * det (scalar ι' X - C.mapMatrix A') :=
by ring
_ = det (scalar ι' X - C.mapMatrix A') := by
rw [← det_mul, hPQ, det_one, one_mul]
_ = f.charpoly := rfl
lemma charpoly_prodMap (f₁ : M₁ →ₗ[R] M₁) (f₂ : M₂ →ₗ[R] M₂) :
(f₁.prodMap f₂).charpoly = f₁.charpoly * f₂.charpoly := by
let b₁ := chooseBasis R M₁
let b₂ := chooseBasis R M₂
let b := b₁.prod b₂
rw [← charpoly_toMatrix f₁ b₁, ← charpoly_toMatrix f₂ b₂, ← charpoly_toMatrix (f₁.prodMap f₂) b,
toMatrix_prodMap b₁ b₂ f₁ f₂, Matrix.charpoly_fromBlocks_zero₁₂]
end Basic
end LinearMap
@[simp]
lemma LinearEquiv.charpoly_conj (e : M₁ ≃ₗ[R] M₂) (φ : Module.End R M₁) :
(e.conj φ).charpoly = φ.charpoly := by
let b := chooseBasis R M₁
rw [← LinearMap.charpoly_toMatrix φ b, ← LinearMap.charpoly_toMatrix (e.conj φ) (b.map e)]
congr 1
ext i j : 1
simp [Matrix.charmatrix, LinearMap.toMatrix, Matrix.diagonal, LinearEquiv.conj_apply]
|
LinearAlgebra\CliffordAlgebra\BaseChange.lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.QuadraticForm.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] [Module A V] [IsScalarTower R A V]
variable [Invertible (2 : R)]
open scoped TensorProduct
namespace CliffordAlgebra
variable (A)
/-- Auxiliary construction: note this is really just a heterobasic `CliffordAlgebra.map`. -/
-- `noncomputable` is a performance workaround for mathlib4#7103
noncomputable 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. -/
-- `noncomputable` is a performance workaround for mathlib4#7103
noncomputable 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
show 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
show 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. -/
-- `noncomputable` is a performance workaround for mathlib4#7103
noncomputable 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
intros v w
rw [← TensorProduct.tmul_add, CliffordAlgebra.ι_mul_ι_add_swap,
QuadraticForm.polarBilin_baseChange, LinearMap.BilinMap.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
show 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
show 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
change toBaseChange A Q (ofBaseChange A Q (1 ⊗ₜ[R] ι Q v)) = 1 ⊗ₜ[R] ι Q v
rw [ofBaseChange_tmul_ι, toBaseChange_ι]
@[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
show 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!]
-- `noncomputable` is a performance workaround for mathlib4#7103
noncomputable 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
|
LinearAlgebra\CliffordAlgebra\Basic.lean | /-
Copyright (c) 2020 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Utensil Song
-/
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)
variable {n : ℕ}
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)
namespace CliffordAlgebra
-- Porting note: Expanded `deriving Inhabited, Semiring, Algebra`
instance instInhabited : Inhabited (CliffordAlgebra Q) := RingQuot.instInhabited _
instance instRing : Ring (CliffordAlgebra Q) := RingQuot.instRing _
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` #10906
example : (Semiring.toNatAlgebra : Algebra ℕ (CliffordAlgebra Q)) = instAlgebra' _ := rfl
-- but doesn't work at `reducible_and_instances` #10906
example : (Ring.toIntAlgebra _ : Algebra ℤ (CliffordAlgebra Q)) = instAlgebra' _ := rfl
-- shortcut instance, as the other instance is slow
instance instAlgebra : Algebra R (CliffordAlgebra Q) := instAlgebra' _
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)
/-- 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
-- Porting note: removed `simp only` proof which gets stuck simplifying `LinearMap.comp_apply`
exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ x)
right_inv F :=
-- Porting note: replaced with proof derived from the one for `TensorAlgebra`
RingQuot.ringQuot_ext' _ _ _ <|
TensorAlgebra.hom_ext <|
LinearMap.ext fun x => by
exact
(RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ _)
variable {Q}
@[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
-- Porting note: added `Subtype.mk_eq_mk`
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
-- Porting note: removed `rw [lift_symm_apply]; rfl`, changed `convert` to `exact`
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 muliplication, 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 }
-- Porting note: Added `h`. `h` is needed for `of`.
letI h : AddCommMonoid s := inferInstanceAs (AddCommMonoid (Subalgebra.toSubmodule s))
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 : AlgHom.id R (CliffordAlgebra Q) = s.val.comp (lift Q of) := by
ext
simp [of]
-- Porting note: `simp` can't apply this
erw [LinearMap.codRestrict_apply]
-- finding a proof is finding an element of the subalgebra
-- Porting note: was `convert Subtype.prop (lift Q of a); exact AlgHom.congr_fun of_id a`
rw [← AlgHom.id_apply (R := R) a, of_id]
exact Subtype.prop (lift Q of a)
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)) :
(ι Q).range.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₂) :
(ι Q₁).range.map (map f).toLinearMap = f.range.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 -- Porting note: replaced `_` with `Q₂`
ext m
exact e.toLinearEquiv.apply_symm_apply m)
((map_comp_map _ _).trans <| by
convert map_id Q₁ using 2 -- Porting note: replaced `_` with `Q₁`
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
|
LinearAlgebra\CliffordAlgebra\CategoryTheory.lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Basic
import Mathlib.LinearAlgebra.QuadraticForm.QuadraticModuleCat
import Mathlib.Algebra.Category.AlgebraCat.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 ⥤ AlgebraCat.{u} R where
obj M := { carrier := CliffordAlgebra M.form }
map {_M _N} f := CliffordAlgebra.map f.toIsometry
map_id _M := CliffordAlgebra.map_id _
map_comp {_M _N _P} f g := (CliffordAlgebra.map_comp_map g.toIsometry f.toIsometry).symm
|
LinearAlgebra\CliffordAlgebra\Conjugation.lean | /-
Copyright (c) 2020 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Grading
import Mathlib.Algebra.Module.Opposites
/-!
# 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]
theorem reverse.map_one : reverse (1 : CliffordAlgebra Q) = 1 :=
op_injective (_root_.map_one reverseOp)
@[simp]
theorem reverse.map_mul (a b : CliffordAlgebra Q) :
reverse (a * b) = reverse b * reverse a :=
op_injective (_root_.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 :
(ι Q).range.map (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap =
LinearMap.range (ι Q) :=
(ι_range_map_lift _ _).trans (LinearMap.range_neg _)
@[simp]
theorem ι_range_comap_involute :
(ι Q).range.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 :
(ι Q).range.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 :
(ι Q).range.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
|
LinearAlgebra\CliffordAlgebra\Contraction.lean | /-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.ExteriorAlgebra.Basic
import Mathlib.LinearAlgebra.CliffordAlgebra.Fold
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation
import Mathlib.LinearAlgebra.Dual
/-!
# 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)
open LinearMap (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
dsimp only
rw [LinearMap.add_apply]
induction' x using CliffordAlgebra.left_induction with r x y hx hy m x hx
· simp_rw [foldr'_algebraMap, smul_zero, zero_add]
· rw [map_add, map_add, map_add, add_add_add_comm, hx, hy]
· 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
dsimp only
rw [LinearMap.smul_apply, RingHom.id_apply]
induction' x using CliffordAlgebra.left_induction with r x y hx hy m x hx
· simp_rw [foldr'_algebraMap, smul_zero]
· rw [map_add, map_add, smul_add, hx, hy]
· 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)
-- Porting note: Lean needs to be reminded of this instance otherwise the statement of the
-- next result times out
instance : SMul R (CliffordAlgebra Q) := inferInstance
/-- 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 r x y hx hy m x hx
· simp_rw [contractLeft_algebraMap, map_zero]
· rw [map_add, map_add, hx, hy, add_zero]
· 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 r x y hx hy m x hx
· simp_rw [contractLeft_algebraMap, map_zero, neg_zero]
· rw [map_add, map_add, map_add, map_add, hx, hy, neg_add]
· 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}
variable (h : B.toQuadraticMap = Q' - Q) (h' : B'.toQuadraticMap = Q'' - Q')
/-- 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
/-- 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' _ _ _
/-- 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 (ι (M := M) Q m * x) = ι (M := M) Q' m * changeForm h x
- contractLeft (Q := Q') (B m) (changeForm h x) :=
-- Porting note: original statement
-- - BilinForm.toLin 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) :
-- Porting note: original statement
-- changeForm h (d⌋x) = d⌋changeForm h x := by
changeForm h (contractLeft (Q := Q) d x) = contractLeft (Q := Q') d (changeForm h x) := by
induction' x using CliffordAlgebra.left_induction with r x y hx hy m x hx
· simp only [contractLeft_algebraMap, changeForm_algebraMap, map_zero]
· rw [map_add, map_add, map_add, map_add, hx, hy]
· 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 r x y hx hy m x hx
· simp_rw [changeForm_algebraMap]
· rw [map_add, hx, hy]
· 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 r x y hx hy m x hx
· simp_rw [changeForm_algebraMap]
· rw [map_add, map_add, map_add, hx, hy]
· 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
dsimp only
exact (changeForm_changeForm _ _ x).trans <|
by simp_rw [(add_neg_self B), changeForm_self_apply]
right_inv := fun x => by
dsimp only
exact (changeForm_changeForm _ _ x).trans <|
by simp_rw [(add_left_neg 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
|
LinearAlgebra\CliffordAlgebra\Equivs.lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.DualNumber
import Mathlib.Algebra.QuaternionBasis
import Mathlib.Data.Complex.Module
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation
import Mathlib.LinearAlgebra.CliffordAlgebra.Star
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)) :=
{ CliffordAlgebra.instRing _ with
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] }
-- Porting note: Changed `x.reverse` to `reverse (R := R) x`
theorem reverse_apply (x : CliffordAlgebra (0 : QuadraticForm R Unit)) :
reverse (R := R) x = 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 m : 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 (R := ℝ) -- Porting note: Added `(R := ℝ)`
@[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) :=
{ CliffordAlgebra.instRing _ with
mul_comm := fun x y =>
CliffordAlgebraComplex.equiv.injective <| by
rw [map_mul, mul_comm, map_mul] }
-- Porting note: Changed `x.reverse` to `reverse (R := ℝ) x`
/-- `reverse` is a no-op over `CliffordAlgebraComplex.Q`. -/
theorem reverse_apply (x : CliffordAlgebra Q) : reverse (R := ℝ) x = 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]
-- this name is too short for us to want it visible after `open CliffordAlgebraComplex`
--attribute [protected] Q -- Porting note: removed
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₁ 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 [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₁,c₂] :=
CliffordAlgebra.lift (Q c₁ c₂)
⟨{ toFun := fun v => (⟨0, v.1, v.2, 0⟩ : ℍ[R,c₁,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₁,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 only [reverse.commutes, AlgHom.commutes, QuaternionAlgebra.coe_algebraMap,
QuaternionAlgebra.star_coe]
| ι x =>
rw [reverse_ι, involute_ι, toQuaternion_ι, map_neg, toQuaternion_ι,
QuaternionAlgebra.neg_mk, star_mk, neg_zero]
| mul x₁ x₂ hx₁ hx₂ => simp only [reverse.map_mul, map_mul, hx₁, hx₂, star_mul]
| add x₁ x₂ hx₁ hx₂ => simp only [reverse.map_add, map_add, hx₁, hx₂, star_add]
/-- Map a quaternion into the clifford algebra. -/
def ofQuaternion : ℍ[R,c₁,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₁,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 [toQuaternion_ι, 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₁,c₂] := by
ext : 1 <;> simp
@[simp]
theorem toQuaternion_ofQuaternion (q : ℍ[R,c₁,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₁,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₁,c₂]) : ofQuaternion (star q) = star (ofQuaternion q) :=
CliffordAlgebraQuaternion.equiv.injective <| by
rw [equiv_apply, equiv_apply, toQuaternion_star, toQuaternion_ofQuaternion,
toQuaternion_ofQuaternion]
-- this name is too short for us to want it visible after `open CliffordAlgebraQuaternion`
--attribute [protected] Q -- Porting note: removed
end CliffordAlgebraQuaternion
/-! ### The clifford algebra isomorphic to the dual numbers -/
namespace CliffordAlgebraDualNumber
open scoped DualNumber
open DualNumber TrivSqZeroExt
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
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, ι_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 leanprover/lean4#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 leanprover/lean4#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 :=
-- Porting note: Original proof was `DualNumber.lift_apply_eps _`
DualNumber.lift_apply_eps (R := R) (B := CliffordAlgebra (0 : QuadraticForm R R)) _
end CliffordAlgebraDualNumber
|
LinearAlgebra\CliffordAlgebra\Even.lean | /-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Fold
import Mathlib.LinearAlgebra.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
-- Porting note: explicit universes
universe uR uM uA uB
variable {R : Type uR} {M : Type uM} [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 : Type uA} {B : Type uB} [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
-- Porting note: added, otherwise Lean can't find this when it needs it
instance : AddCommMonoid (even Q) := AddSubmonoidClass.toAddCommMonoid _
@[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 : Type max uA uM 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 m a₁ a₂ => Prod.ext rfl (Subtype.ext <| LinearMap.ext fun m₃ => mul_add _ _ _))
fun c m a => Prod.ext rfl (Subtype.ext <| LinearMap.ext fun m₃ => 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]
· change f.bilin m₁ m * 0 = Q m • (0 : A) -- Porting note: `•` now needs the type of `0`
rw [mul_zero, smul_zero]
· rintro x _hx y _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]
-- Porting note: In Lean 3, `aux_apply` isn't a simp lemma. I changed `{ attrs := [] }` to
-- `.lemmasOnly`, so that `aux_apply` isn't a simp lemma.
/-- 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! (config := .lemmasOnly) apply]
def aux (f : EvenHom Q A) : CliffordAlgebra.even Q →ₗ[R] A := by
refine ?_ ∘ₗ (even Q).val.toLinearMap
-- Porting note: added, can't be found otherwise
letI : AddCommGroup (S f) := AddSubgroupClass.toAddCommGroup _
exact LinearMap.fst R _ _ ∘ₗ foldr Q (fFold f) (fFold_fFold f) (1, 0)
@[simp, nolint simpNF] -- Added `nolint simpNF` to avoid a timeout #8386
theorem aux_one : aux f 1 = 1 :=
congr_arg Prod.fst (foldr_one _ _ _ _)
@[simp, nolint simpNF] -- Added `nolint simpNF` to avoid a timeout #8386
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, nolint simpNF] -- Added `nolint simpNF` to avoid a timeout #8386
theorem aux_algebraMap (r) (hr) : aux f ⟨algebraMap R _ r, hr⟩ = algebraMap R _ r :=
(congr_arg Prod.fst (foldr_algebraMap _ _ _ _ _)).trans (Algebra.algebraMap_eq_smul_one r).symm
@[simp, nolint simpNF] -- Added `nolint simpNF` to avoid a timeout #8386
theorem aux_mul (x y : even Q) : aux f (x * y) = aux f x * aux f y := by
cases' x with x x_property
cases y
refine (congr_arg Prod.fst (foldr_mul _ _ _ _ _ _)).trans ?_
dsimp only
induction x, x_property using even_induction Q with
| algebraMap r =>
rw [foldr_algebraMap, aux_algebraMap]
exact Algebra.smul_def r _
| add x y hx hy ihx ihy =>
rw [LinearMap.map_add, Prod.fst_add, ihx, ihy, ← add_mul, ← LinearMap.map_add]
rfl
| ι_mul_ι_mul m₁ m₂ x hx ih =>
rw [aux_apply, foldr_mul, foldr_mul, foldr_ι, foldr_ι, fst_fFold_fFold, ih, ← mul_assoc,
Subtype.coe_mk, foldr_mul, foldr_mul, foldr_ι, foldr_ι, fst_fFold_fFold]
rfl
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] -- Porting note: simpNF linter times out on this one
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
|
LinearAlgebra\CliffordAlgebra\EvenEquiv.lean | /-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation
import Mathlib.LinearAlgebra.CliffordAlgebra.Even
import Mathlib.LinearAlgebra.QuadraticForm.Prod
import Mathlib.Tactic.LiftLets
/-!
# 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, QuadraticMap.map_zero,
add_sub_cancel_right, sub_self, map_zero, zero_sub]
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 (#10691): 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) := by
-- Porting note: entire proof was the term-mode `even.lift_ι (Q' Q) _ x y`
unfold ofEven
lift_lets
intro f
-- TODO: replacing `?_` with `_` takes way longer?
exact @even.lift_ι R (M × R) _ _ _ (Q' Q) _ _ _ ⟨f, ?_, ?_⟩ 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, 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 =>
-- Porting note: added `letI`
letI : SubtractionMonoid (even (Q' Q)) := AddGroup.toSubtractionMonoid
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 <|
-- Porting note: added `letI`s
letI : AddCommGroup (even Q') := AddSubgroupClass.toAddCommGroup _
letI : HasDistribNeg (even Q') := NonUnitalNonAssocRing.toHasDistribNeg
{ 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] }
-- Porting note: `simpNF` times out, but only in CI where all of `Mathlib` is imported
@[simp, nolint simpNF]
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
dsimp only [EvenHom.compr₂_bilin, LinearMap.compr₂_apply, AlgHom.toLinearMap_apply,
AlgHom.comp_apply, AlgHom.id_apply]
rw [evenToNeg_ι]
-- Needed to use `RingHom.map_neg` to avoid a timeout and now `erw` #8386
erw [RingHom.map_neg, evenToNeg_ι, neg_neg]
/-- 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 _ _ _ _)
-- Note: times out on linting CI
attribute [nolint simpNF] evenEquivEvenNeg_apply evenEquivEvenNeg_symm_apply
end CliffordAlgebra
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.