Dataset Viewer
path
stringlengths 11
71
| content
stringlengths 75
124k
|
---|---|
Tactic.lean | import Mathlib.Tactic.Abel
import Mathlib.Tactic.AdaptationNote
import Mathlib.Tactic.ApplyAt
import Mathlib.Tactic.ApplyCongr
import Mathlib.Tactic.ApplyFun
import Mathlib.Tactic.ApplyWith
import Mathlib.Tactic.ArithMult
import Mathlib.Tactic.ArithMult.Init
import Mathlib.Tactic.Attr.Core
import Mathlib.Tactic.Attr.Register
import Mathlib.Tactic.Basic
import Mathlib.Tactic.Bound
import Mathlib.Tactic.Bound.Attribute
import Mathlib.Tactic.Bound.Init
import Mathlib.Tactic.ByContra
import Mathlib.Tactic.CC
import Mathlib.Tactic.CC.Addition
import Mathlib.Tactic.CC.Datatypes
import Mathlib.Tactic.CC.Lemmas
import Mathlib.Tactic.CancelDenoms
import Mathlib.Tactic.CancelDenoms.Core
import Mathlib.Tactic.Cases
import Mathlib.Tactic.CasesM
import Mathlib.Tactic.CategoryTheory.BicategoricalComp
import Mathlib.Tactic.CategoryTheory.BicategoryCoherence
import Mathlib.Tactic.CategoryTheory.Coherence
import Mathlib.Tactic.CategoryTheory.Elementwise
import Mathlib.Tactic.CategoryTheory.Monoidal
import Mathlib.Tactic.CategoryTheory.MonoidalComp
import Mathlib.Tactic.CategoryTheory.Reassoc
import Mathlib.Tactic.CategoryTheory.Slice
import Mathlib.Tactic.Change
import Mathlib.Tactic.Check
import Mathlib.Tactic.Choose
import Mathlib.Tactic.Clean
import Mathlib.Tactic.ClearExcept
import Mathlib.Tactic.ClearExclamation
import Mathlib.Tactic.Clear_
import Mathlib.Tactic.Coe
import Mathlib.Tactic.Common
import Mathlib.Tactic.ComputeDegree
import Mathlib.Tactic.CongrExclamation
import Mathlib.Tactic.CongrM
import Mathlib.Tactic.Constructor
import Mathlib.Tactic.Continuity
import Mathlib.Tactic.Continuity.Init
import Mathlib.Tactic.ContinuousFunctionalCalculus
import Mathlib.Tactic.Contrapose
import Mathlib.Tactic.Conv
import Mathlib.Tactic.Convert
import Mathlib.Tactic.Core
import Mathlib.Tactic.DefEqTransformations
import Mathlib.Tactic.DeprecateMe
import Mathlib.Tactic.DeriveFintype
import Mathlib.Tactic.DeriveToExpr
import Mathlib.Tactic.DeriveTraversable
import Mathlib.Tactic.Eqns
import Mathlib.Tactic.Eval
import Mathlib.Tactic.ExistsI
import Mathlib.Tactic.Explode
import Mathlib.Tactic.Explode.Datatypes
import Mathlib.Tactic.Explode.Pretty
import Mathlib.Tactic.ExtendDoc
import Mathlib.Tactic.ExtractGoal
import Mathlib.Tactic.ExtractLets
import Mathlib.Tactic.FBinop
import Mathlib.Tactic.FailIfNoProgress
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.Find
import Mathlib.Tactic.FunProp
import Mathlib.Tactic.FunProp.AEMeasurable
import Mathlib.Tactic.FunProp.Attr
import Mathlib.Tactic.FunProp.ContDiff
import Mathlib.Tactic.FunProp.Core
import Mathlib.Tactic.FunProp.Decl
import Mathlib.Tactic.FunProp.Differentiable
import Mathlib.Tactic.FunProp.Elab
import Mathlib.Tactic.FunProp.FunctionData
import Mathlib.Tactic.FunProp.Mor
import Mathlib.Tactic.FunProp.RefinedDiscrTree
import Mathlib.Tactic.FunProp.StateList
import Mathlib.Tactic.FunProp.Theorems
import Mathlib.Tactic.FunProp.ToBatteries
import Mathlib.Tactic.FunProp.Types
import Mathlib.Tactic.GCongr
import Mathlib.Tactic.GCongr.Core
import Mathlib.Tactic.GCongr.ForwardAttr
import Mathlib.Tactic.Generalize
import Mathlib.Tactic.GeneralizeProofs
import Mathlib.Tactic.Group
import Mathlib.Tactic.GuardGoalNums
import Mathlib.Tactic.GuardHypNums
import Mathlib.Tactic.Have
import Mathlib.Tactic.HaveI
import Mathlib.Tactic.HelpCmd
import Mathlib.Tactic.HigherOrder
import Mathlib.Tactic.Hint
import Mathlib.Tactic.ITauto
import Mathlib.Tactic.InferParam
import Mathlib.Tactic.Inhabit
import Mathlib.Tactic.IntervalCases
import Mathlib.Tactic.IrreducibleDef
import Mathlib.Tactic.Lemma
import Mathlib.Tactic.Lift
import Mathlib.Tactic.LiftLets
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Linarith.Datatypes
import Mathlib.Tactic.Linarith.Frontend
import Mathlib.Tactic.Linarith.Lemmas
import Mathlib.Tactic.Linarith.Oracle.FourierMotzkin
import Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm
import Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Datatypes
import Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.Gauss
import Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.PositiveVector
import Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.SimplexAlgorithm
import Mathlib.Tactic.Linarith.Parsing
import Mathlib.Tactic.Linarith.Preprocessing
import Mathlib.Tactic.Linarith.Verification
import Mathlib.Tactic.LinearCombination
import Mathlib.Tactic.Linter
import Mathlib.Tactic.Linter.GlobalAttributeIn
import Mathlib.Tactic.Linter.HashCommandLinter
import Mathlib.Tactic.Linter.HaveLetLinter
import Mathlib.Tactic.Linter.Lint
import Mathlib.Tactic.Linter.MinImports
import Mathlib.Tactic.Linter.OldObtain
import Mathlib.Tactic.Linter.RefineLinter
import Mathlib.Tactic.Linter.Style
import Mathlib.Tactic.Linter.TextBased
import Mathlib.Tactic.Linter.UnusedTactic
import Mathlib.Tactic.Measurability
import Mathlib.Tactic.Measurability.Init
import Mathlib.Tactic.MinImports
import Mathlib.Tactic.MkIffOfInductiveProp
import Mathlib.Tactic.ModCases
import Mathlib.Tactic.Monotonicity
import Mathlib.Tactic.Monotonicity.Attr
import Mathlib.Tactic.Monotonicity.Basic
import Mathlib.Tactic.Monotonicity.Lemmas
import Mathlib.Tactic.MoveAdd
import Mathlib.Tactic.NoncommRing
import Mathlib.Tactic.Nontriviality
import Mathlib.Tactic.Nontriviality.Core
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.NormNum.Basic
import Mathlib.Tactic.NormNum.BigOperators
import Mathlib.Tactic.NormNum.Core
import Mathlib.Tactic.NormNum.DivMod
import Mathlib.Tactic.NormNum.Eq
import Mathlib.Tactic.NormNum.GCD
import Mathlib.Tactic.NormNum.Ineq
import Mathlib.Tactic.NormNum.Inv
import Mathlib.Tactic.NormNum.IsCoprime
import Mathlib.Tactic.NormNum.LegendreSymbol
import Mathlib.Tactic.NormNum.NatFib
import Mathlib.Tactic.NormNum.NatSqrt
import Mathlib.Tactic.NormNum.OfScientific
import Mathlib.Tactic.NormNum.Pow
import Mathlib.Tactic.NormNum.Prime
import Mathlib.Tactic.NormNum.Result
import Mathlib.Tactic.NthRewrite
import Mathlib.Tactic.Observe
import Mathlib.Tactic.PPWithUniv
import Mathlib.Tactic.Peel
import Mathlib.Tactic.Polyrith
import Mathlib.Tactic.Positivity
import Mathlib.Tactic.Positivity.Basic
import Mathlib.Tactic.Positivity.Core
import Mathlib.Tactic.Positivity.Finset
import Mathlib.Tactic.ProdAssoc
import Mathlib.Tactic.ProjectionNotation
import Mathlib.Tactic.Propose
import Mathlib.Tactic.ProxyType
import Mathlib.Tactic.PushNeg
import Mathlib.Tactic.Qify
import Mathlib.Tactic.RSuffices
import Mathlib.Tactic.Recall
import Mathlib.Tactic.Recover
import Mathlib.Tactic.ReduceModChar
import Mathlib.Tactic.ReduceModChar.Ext
import Mathlib.Tactic.Relation.Rfl
import Mathlib.Tactic.Relation.Symm
import Mathlib.Tactic.Relation.Trans
import Mathlib.Tactic.Rename
import Mathlib.Tactic.RenameBVar
import Mathlib.Tactic.Replace
import Mathlib.Tactic.RewriteSearch
import Mathlib.Tactic.Rify
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Ring.Basic
import Mathlib.Tactic.Ring.PNat
import Mathlib.Tactic.Ring.RingNF
import Mathlib.Tactic.Sat.FromLRAT
import Mathlib.Tactic.Says
import Mathlib.Tactic.ScopedNS
import Mathlib.Tactic.Set
import Mathlib.Tactic.SetLike
import Mathlib.Tactic.SimpIntro
import Mathlib.Tactic.SimpRw
import Mathlib.Tactic.Simps.Basic
import Mathlib.Tactic.Simps.NotationClass
import Mathlib.Tactic.SlimCheck
import Mathlib.Tactic.SplitIfs
import Mathlib.Tactic.Spread
import Mathlib.Tactic.Subsingleton
import Mathlib.Tactic.Substs
import Mathlib.Tactic.SuccessIfFailWithMsg
import Mathlib.Tactic.SudoSetOption
import Mathlib.Tactic.SuppressCompilation
import Mathlib.Tactic.SwapVar
import Mathlib.Tactic.TFAE
import Mathlib.Tactic.Tauto
import Mathlib.Tactic.TermCongr
import Mathlib.Tactic.ToAdditive
import Mathlib.Tactic.ToAdditive.Frontend
import Mathlib.Tactic.ToExpr
import Mathlib.Tactic.ToLevel
import Mathlib.Tactic.Trace
import Mathlib.Tactic.TryThis
import Mathlib.Tactic.TypeCheck
import Mathlib.Tactic.TypeStar
import Mathlib.Tactic.UnsetOption
import Mathlib.Tactic.Use
import Mathlib.Tactic.Variable
import Mathlib.Tactic.WLOG
import Mathlib.Tactic.Widget.Calc
import Mathlib.Tactic.Widget.CommDiag
import Mathlib.Tactic.Widget.CongrM
import Mathlib.Tactic.Widget.Conv
import Mathlib.Tactic.Widget.GCongr
import Mathlib.Tactic.Widget.InteractiveUnfold
import Mathlib.Tactic.Widget.SelectInsertParamsClass
import Mathlib.Tactic.Widget.SelectPanelUtils
import Mathlib.Tactic.Widget.StringDiagram
import Mathlib.Tactic.Zify
|
Algebra\AddTorsor.lean | /-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Yury Kudryashov
-/
import Mathlib.Data.Set.Pointwise.SMul
/-!
# Torsors of additive group actions
This file defines torsors of additive group actions.
## Notations
The group elements are referred to as acting on points. This file
defines the notation `+ᵥ` for adding a group element to a point and
`-ᵥ` for subtracting two points to produce a group element.
## Implementation notes
Affine spaces are the motivating example of torsors of additive group actions. It may be appropriate
to refactor in terms of the general definition of group actions, via `to_additive`, when there is a
use for multiplicative torsors (currently mathlib only develops the theory of group actions for
multiplicative group actions).
## Notations
* `v +ᵥ p` is a notation for `VAdd.vadd`, the left action of an additive monoid;
* `p₁ -ᵥ p₂` is a notation for `VSub.vsub`, difference between two points in an additive torsor
as an element of the corresponding additive group;
## References
* https://en.wikipedia.org/wiki/Principal_homogeneous_space
* https://en.wikipedia.org/wiki/Affine_space
-/
/-- An `AddTorsor G P` gives a structure to the nonempty type `P`,
acted on by an `AddGroup G` with a transitive and free action given
by the `+ᵥ` operation and a corresponding subtraction given by the
`-ᵥ` operation. In the case of a vector space, it is an affine
space. -/
class AddTorsor (G : outParam Type*) (P : Type*) [AddGroup G] extends AddAction G P,
VSub G P where
[nonempty : Nonempty P]
/-- Torsor subtraction and addition with the same element cancels out. -/
vsub_vadd' : ∀ p₁ p₂ : P, (p₁ -ᵥ p₂ : G) +ᵥ p₂ = p₁
/-- Torsor addition and subtraction with the same element cancels out. -/
vadd_vsub' : ∀ (g : G) (p : P), g +ᵥ p -ᵥ p = g
-- Porting note(#12096): removed `nolint instance_priority`; lint not ported yet
attribute [instance 100] AddTorsor.nonempty
-- Porting note(#12094): removed nolint; dangerous_instance linter not ported yet
--attribute [nolint dangerous_instance] AddTorsor.toVSub
/-- An `AddGroup G` is a torsor for itself. -/
-- Porting note(#12096): linter not ported yet
--@[nolint instance_priority]
instance addGroupIsAddTorsor (G : Type*) [AddGroup G] : AddTorsor G G where
vsub := Sub.sub
vsub_vadd' := sub_add_cancel
vadd_vsub' := add_sub_cancel_right
/-- Simplify subtraction for a torsor for an `AddGroup G` over
itself. -/
@[simp]
theorem vsub_eq_sub {G : Type*} [AddGroup G] (g₁ g₂ : G) : g₁ -ᵥ g₂ = g₁ - g₂ :=
rfl
section General
variable {G : Type*} {P : Type*} [AddGroup G] [T : AddTorsor G P]
/-- Adding the result of subtracting from another point produces that
point. -/
@[simp]
theorem vsub_vadd (p₁ p₂ : P) : p₁ -ᵥ p₂ +ᵥ p₂ = p₁ :=
AddTorsor.vsub_vadd' p₁ p₂
/-- Adding a group element then subtracting the original point
produces that group element. -/
@[simp]
theorem vadd_vsub (g : G) (p : P) : g +ᵥ p -ᵥ p = g :=
AddTorsor.vadd_vsub' g p
/-- If the same point added to two group elements produces equal
results, those group elements are equal. -/
theorem vadd_right_cancel {g₁ g₂ : G} (p : P) (h : g₁ +ᵥ p = g₂ +ᵥ p) : g₁ = g₂ := by
-- Porting note: vadd_vsub g₁ → vadd_vsub g₁ p
rw [← vadd_vsub g₁ p, h, vadd_vsub]
@[simp]
theorem vadd_right_cancel_iff {g₁ g₂ : G} (p : P) : g₁ +ᵥ p = g₂ +ᵥ p ↔ g₁ = g₂ :=
⟨vadd_right_cancel p, fun h => h ▸ rfl⟩
/-- Adding a group element to the point `p` is an injective
function. -/
theorem vadd_right_injective (p : P) : Function.Injective ((· +ᵥ p) : G → P) := fun _ _ =>
vadd_right_cancel p
/-- Adding a group element to a point, then subtracting another point,
produces the same result as subtracting the points then adding the
group element. -/
theorem vadd_vsub_assoc (g : G) (p₁ p₂ : P) : g +ᵥ p₁ -ᵥ p₂ = g + (p₁ -ᵥ p₂) := by
apply vadd_right_cancel p₂
rw [vsub_vadd, add_vadd, vsub_vadd]
/-- Subtracting a point from itself produces 0. -/
@[simp]
theorem vsub_self (p : P) : p -ᵥ p = (0 : G) := by
rw [← zero_add (p -ᵥ p), ← vadd_vsub_assoc, vadd_vsub]
/-- If subtracting two points produces 0, they are equal. -/
theorem eq_of_vsub_eq_zero {p₁ p₂ : P} (h : p₁ -ᵥ p₂ = (0 : G)) : p₁ = p₂ := by
rw [← vsub_vadd p₁ p₂, h, zero_vadd]
/-- Subtracting two points produces 0 if and only if they are
equal. -/
@[simp]
theorem vsub_eq_zero_iff_eq {p₁ p₂ : P} : p₁ -ᵥ p₂ = (0 : G) ↔ p₁ = p₂ :=
Iff.intro eq_of_vsub_eq_zero fun h => h ▸ vsub_self _
theorem vsub_ne_zero {p q : P} : p -ᵥ q ≠ (0 : G) ↔ p ≠ q :=
not_congr vsub_eq_zero_iff_eq
/-- Cancellation adding the results of two subtractions. -/
@[simp]
theorem vsub_add_vsub_cancel (p₁ p₂ p₃ : P) : p₁ -ᵥ p₂ + (p₂ -ᵥ p₃) = p₁ -ᵥ p₃ := by
apply vadd_right_cancel p₃
rw [add_vadd, vsub_vadd, vsub_vadd, vsub_vadd]
/-- Subtracting two points in the reverse order produces the negation
of subtracting them. -/
@[simp]
theorem neg_vsub_eq_vsub_rev (p₁ p₂ : P) : -(p₁ -ᵥ p₂) = p₂ -ᵥ p₁ := by
refine neg_eq_of_add_eq_zero_right (vadd_right_cancel p₁ ?_)
rw [vsub_add_vsub_cancel, vsub_self]
theorem vadd_vsub_eq_sub_vsub (g : G) (p q : P) : g +ᵥ p -ᵥ q = g - (q -ᵥ p) := by
rw [vadd_vsub_assoc, sub_eq_add_neg, neg_vsub_eq_vsub_rev]
/-- Subtracting the result of adding a group element produces the same result
as subtracting the points and subtracting that group element. -/
theorem vsub_vadd_eq_vsub_sub (p₁ p₂ : P) (g : G) : p₁ -ᵥ (g +ᵥ p₂) = p₁ -ᵥ p₂ - g := by
rw [← add_right_inj (p₂ -ᵥ p₁ : G), vsub_add_vsub_cancel, ← neg_vsub_eq_vsub_rev, vadd_vsub, ←
add_sub_assoc, ← neg_vsub_eq_vsub_rev, neg_add_self, zero_sub]
/-- Cancellation subtracting the results of two subtractions. -/
@[simp]
theorem vsub_sub_vsub_cancel_right (p₁ p₂ p₃ : P) : p₁ -ᵥ p₃ - (p₂ -ᵥ p₃) = p₁ -ᵥ p₂ := by
rw [← vsub_vadd_eq_vsub_sub, vsub_vadd]
/-- Convert between an equality with adding a group element to a point
and an equality of a subtraction of two points with a group
element. -/
theorem eq_vadd_iff_vsub_eq (p₁ : P) (g : G) (p₂ : P) : p₁ = g +ᵥ p₂ ↔ p₁ -ᵥ p₂ = g :=
⟨fun h => h.symm ▸ vadd_vsub _ _, fun h => h ▸ (vsub_vadd _ _).symm⟩
theorem vadd_eq_vadd_iff_neg_add_eq_vsub {v₁ v₂ : G} {p₁ p₂ : P} :
v₁ +ᵥ p₁ = v₂ +ᵥ p₂ ↔ -v₁ + v₂ = p₁ -ᵥ p₂ := by
rw [eq_vadd_iff_vsub_eq, vadd_vsub_assoc, ← add_right_inj (-v₁), neg_add_cancel_left, eq_comm]
namespace Set
open Pointwise
-- porting note (#10618): simp can prove this
--@[simp]
theorem singleton_vsub_self (p : P) : ({p} : Set P) -ᵥ {p} = {(0 : G)} := by
rw [Set.singleton_vsub_singleton, vsub_self]
end Set
@[simp]
theorem vadd_vsub_vadd_cancel_right (v₁ v₂ : G) (p : P) : v₁ +ᵥ p -ᵥ (v₂ +ᵥ p) = v₁ - v₂ := by
rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, vsub_self, add_zero]
/-- If the same point subtracted from two points produces equal
results, those points are equal. -/
theorem vsub_left_cancel {p₁ p₂ p : P} (h : p₁ -ᵥ p = p₂ -ᵥ p) : p₁ = p₂ := by
rwa [← sub_eq_zero, vsub_sub_vsub_cancel_right, vsub_eq_zero_iff_eq] at h
/-- The same point subtracted from two points produces equal results
if and only if those points are equal. -/
@[simp]
theorem vsub_left_cancel_iff {p₁ p₂ p : P} : p₁ -ᵥ p = p₂ -ᵥ p ↔ p₁ = p₂ :=
⟨vsub_left_cancel, fun h => h ▸ rfl⟩
/-- Subtracting the point `p` is an injective function. -/
theorem vsub_left_injective (p : P) : Function.Injective ((· -ᵥ p) : P → G) := fun _ _ =>
vsub_left_cancel
/-- If subtracting two points from the same point produces equal
results, those points are equal. -/
theorem vsub_right_cancel {p₁ p₂ p : P} (h : p -ᵥ p₁ = p -ᵥ p₂) : p₁ = p₂ := by
refine vadd_left_cancel (p -ᵥ p₂) ?_
rw [vsub_vadd, ← h, vsub_vadd]
/-- Subtracting two points from the same point produces equal results
if and only if those points are equal. -/
@[simp]
theorem vsub_right_cancel_iff {p₁ p₂ p : P} : p -ᵥ p₁ = p -ᵥ p₂ ↔ p₁ = p₂ :=
⟨vsub_right_cancel, fun h => h ▸ rfl⟩
/-- Subtracting a point from the point `p` is an injective
function. -/
theorem vsub_right_injective (p : P) : Function.Injective ((p -ᵥ ·) : P → G) := fun _ _ =>
vsub_right_cancel
end General
section comm
variable {G : Type*} {P : Type*} [AddCommGroup G] [AddTorsor G P]
/-- Cancellation subtracting the results of two subtractions. -/
@[simp]
theorem vsub_sub_vsub_cancel_left (p₁ p₂ p₃ : P) : p₃ -ᵥ p₂ - (p₃ -ᵥ p₁) = p₁ -ᵥ p₂ := by
rw [sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm, vsub_add_vsub_cancel]
@[simp]
theorem vadd_vsub_vadd_cancel_left (v : G) (p₁ p₂ : P) : v +ᵥ p₁ -ᵥ (v +ᵥ p₂) = p₁ -ᵥ p₂ := by
rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_sub_cancel_left]
theorem vsub_vadd_comm (p₁ p₂ p₃ : P) : (p₁ -ᵥ p₂ : G) +ᵥ p₃ = p₃ -ᵥ p₂ +ᵥ p₁ := by
rw [← @vsub_eq_zero_iff_eq G, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub]
simp
theorem vadd_eq_vadd_iff_sub_eq_vsub {v₁ v₂ : G} {p₁ p₂ : P} :
v₁ +ᵥ p₁ = v₂ +ᵥ p₂ ↔ v₂ - v₁ = p₁ -ᵥ p₂ := by
rw [vadd_eq_vadd_iff_neg_add_eq_vsub, neg_add_eq_sub]
theorem vsub_sub_vsub_comm (p₁ p₂ p₃ p₄ : P) : p₁ -ᵥ p₂ - (p₃ -ᵥ p₄) = p₁ -ᵥ p₃ - (p₂ -ᵥ p₄) := by
rw [← vsub_vadd_eq_vsub_sub, vsub_vadd_comm, vsub_vadd_eq_vsub_sub]
end comm
namespace Prod
variable {G G' P P' : Type*} [AddGroup G] [AddGroup G'] [AddTorsor G P] [AddTorsor G' P']
instance instAddTorsor : AddTorsor (G × G') (P × P') where
vadd v p := (v.1 +ᵥ p.1, v.2 +ᵥ p.2)
zero_vadd _ := Prod.ext (zero_vadd _ _) (zero_vadd _ _)
add_vadd _ _ _ := Prod.ext (add_vadd _ _ _) (add_vadd _ _ _)
vsub p₁ p₂ := (p₁.1 -ᵥ p₂.1, p₁.2 -ᵥ p₂.2)
nonempty := Prod.instNonempty
vsub_vadd' _ _ := Prod.ext (vsub_vadd _ _) (vsub_vadd _ _)
vadd_vsub' _ _ := Prod.ext (vadd_vsub _ _) (vadd_vsub _ _)
-- Porting note: The proofs above used to be shorter:
-- zero_vadd p := by simp ⊢ 0 +ᵥ p = p
-- add_vadd := by simp [add_vadd] ⊢ ∀ (a : G) (b : G') (a_1 : G) (b_1 : G') (a_2 : P) (b_2 : P'),
-- (a + a_1, b + b_1) +ᵥ (a_2, b_2) = (a, b) +ᵥ ((a_1, b_1) +ᵥ (a_2, b_2))
-- vsub_vadd' p₁ p₂ := show (p₁.1 -ᵥ p₂.1 +ᵥ p₂.1, _) = p₁ by simp
-- ⊢ (p₁.fst -ᵥ p₂.fst +ᵥ p₂.fst, ((p₁.fst -ᵥ p₂.fst, p₁.snd -ᵥ p₂.snd) +ᵥ p₂).snd) = p₁
-- vadd_vsub' v p := show (v.1 +ᵥ p.1 -ᵥ p.1, v.2 +ᵥ p.2 -ᵥ p.2) = v by simp
-- ⊢ (v.fst +ᵥ p.fst -ᵥ p.fst, v.snd) = v
@[simp]
theorem fst_vadd (v : G × G') (p : P × P') : (v +ᵥ p).1 = v.1 +ᵥ p.1 :=
rfl
@[simp]
theorem snd_vadd (v : G × G') (p : P × P') : (v +ᵥ p).2 = v.2 +ᵥ p.2 :=
rfl
@[simp]
theorem mk_vadd_mk (v : G) (v' : G') (p : P) (p' : P') : (v, v') +ᵥ (p, p') = (v +ᵥ p, v' +ᵥ p') :=
rfl
@[simp]
theorem fst_vsub (p₁ p₂ : P × P') : (p₁ -ᵥ p₂ : G × G').1 = p₁.1 -ᵥ p₂.1 :=
rfl
@[simp]
theorem snd_vsub (p₁ p₂ : P × P') : (p₁ -ᵥ p₂ : G × G').2 = p₁.2 -ᵥ p₂.2 :=
rfl
@[simp]
theorem mk_vsub_mk (p₁ p₂ : P) (p₁' p₂' : P') :
((p₁, p₁') -ᵥ (p₂, p₂') : G × G') = (p₁ -ᵥ p₂, p₁' -ᵥ p₂') :=
rfl
end Prod
namespace Pi
universe u v w
variable {I : Type u} {fg : I → Type v} [∀ i, AddGroup (fg i)] {fp : I → Type w}
open AddAction AddTorsor
/-- A product of `AddTorsor`s is an `AddTorsor`. -/
instance instAddTorsor [∀ i, AddTorsor (fg i) (fp i)] : AddTorsor (∀ i, fg i) (∀ i, fp i) where
vadd g p i := g i +ᵥ p i
zero_vadd p := funext fun i => zero_vadd (fg i) (p i)
add_vadd g₁ g₂ p := funext fun i => add_vadd (g₁ i) (g₂ i) (p i)
vsub p₁ p₂ i := p₁ i -ᵥ p₂ i
vsub_vadd' p₁ p₂ := funext fun i => vsub_vadd (p₁ i) (p₂ i)
vadd_vsub' g p := funext fun i => vadd_vsub (g i) (p i)
end Pi
namespace Equiv
variable {G : Type*} {P : Type*} [AddGroup G] [AddTorsor G P]
/-- `v ↦ v +ᵥ p` as an equivalence. -/
def vaddConst (p : P) : G ≃ P where
toFun v := v +ᵥ p
invFun p' := p' -ᵥ p
left_inv _ := vadd_vsub _ _
right_inv _ := vsub_vadd _ _
@[simp]
theorem coe_vaddConst (p : P) : ⇑(vaddConst p) = fun v => v +ᵥ p :=
rfl
@[simp]
theorem coe_vaddConst_symm (p : P) : ⇑(vaddConst p).symm = fun p' => p' -ᵥ p :=
rfl
/-- `p' ↦ p -ᵥ p'` as an equivalence. -/
def constVSub (p : P) : P ≃ G where
toFun := (p -ᵥ ·)
invFun := (-· +ᵥ p)
left_inv p' := by simp
right_inv v := by simp [vsub_vadd_eq_vsub_sub]
@[simp] lemma coe_constVSub (p : P) : ⇑(constVSub p) = (p -ᵥ ·) := rfl
@[simp]
theorem coe_constVSub_symm (p : P) : ⇑(constVSub p).symm = fun (v : G) => -v +ᵥ p :=
rfl
variable (P)
/-- The permutation given by `p ↦ v +ᵥ p`. -/
def constVAdd (v : G) : Equiv.Perm P where
toFun := (v +ᵥ ·)
invFun := (-v +ᵥ ·)
left_inv p := by simp [vadd_vadd]
right_inv p := by simp [vadd_vadd]
@[simp] lemma coe_constVAdd (v : G) : ⇑(constVAdd P v) = (v +ᵥ ·) := rfl
variable (G)
@[simp]
theorem constVAdd_zero : constVAdd P (0 : G) = 1 :=
ext <| zero_vadd G
variable {G}
@[simp]
theorem constVAdd_add (v₁ v₂ : G) : constVAdd P (v₁ + v₂) = constVAdd P v₁ * constVAdd P v₂ :=
ext <| add_vadd v₁ v₂
/-- `Equiv.constVAdd` as a homomorphism from `Multiplicative G` to `Equiv.perm P` -/
def constVAddHom : Multiplicative G →* Equiv.Perm P where
toFun v := constVAdd P (Multiplicative.toAdd v)
map_one' := constVAdd_zero G P
map_mul' := constVAdd_add P
variable {P}
-- Porting note: Previous code was:
-- open _Root_.Function
open Function
/-- Point reflection in `x` as a permutation. -/
def pointReflection (x : P) : Perm P :=
(constVSub x).trans (vaddConst x)
theorem pointReflection_apply (x y : P) : pointReflection x y = x -ᵥ y +ᵥ x :=
rfl
@[simp]
theorem pointReflection_vsub_left (x y : P) : pointReflection x y -ᵥ x = x -ᵥ y :=
vadd_vsub ..
@[simp]
theorem left_vsub_pointReflection (x y : P) : x -ᵥ pointReflection x y = y -ᵥ x :=
neg_injective <| by simp
@[simp]
theorem pointReflection_vsub_right (x y : P) : pointReflection x y -ᵥ y = 2 • (x -ᵥ y) := by
simp [pointReflection, two_nsmul, vadd_vsub_assoc]
@[simp]
theorem right_vsub_pointReflection (x y : P) : y -ᵥ pointReflection x y = 2 • (y -ᵥ x) :=
neg_injective <| by simp [← neg_nsmul]
@[simp]
theorem pointReflection_symm (x : P) : (pointReflection x).symm = pointReflection x :=
ext <| by simp [pointReflection]
@[simp]
theorem pointReflection_self (x : P) : pointReflection x x = x :=
vsub_vadd _ _
theorem pointReflection_involutive (x : P) : Involutive (pointReflection x : P → P) := fun y =>
(Equiv.apply_eq_iff_eq_symm_apply _).2 <| by rw [pointReflection_symm]
/-- `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 • · : G → G)) :
pointReflection x y = y ↔ y = x := by
rw [pointReflection_apply, eq_comm, eq_vadd_iff_vsub_eq, ← neg_vsub_eq_vsub_rev,
neg_eq_iff_add_eq_zero, ← two_nsmul, ← nsmul_zero 2, h.eq_iff, vsub_eq_zero_iff_eq, eq_comm]
-- Porting note: need this to calm down CI
theorem injective_pointReflection_left_of_injective_bit0 {G P : Type*} [AddCommGroup G]
[AddTorsor G P] (h : Injective (2 • · : G → G)) (y : P) :
Injective fun x : P => pointReflection x y :=
fun x₁ x₂ (hy : pointReflection x₁ y = pointReflection x₂ y) => by
rwa [pointReflection_apply, pointReflection_apply, vadd_eq_vadd_iff_sub_eq_vsub,
vsub_sub_vsub_cancel_right, ← neg_vsub_eq_vsub_rev, neg_eq_iff_add_eq_zero,
← two_nsmul, ← nsmul_zero 2, h.eq_iff, vsub_eq_zero_iff_eq] at hy
end Equiv
theorem AddTorsor.subsingleton_iff (G P : Type*) [AddGroup G] [AddTorsor G P] :
Subsingleton G ↔ Subsingleton P := by
inhabit P
exact (Equiv.vaddConst default).subsingleton_congr
|
Algebra\AlgebraicCard.lean | /-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.Algebra.Polynomial.Cardinal
import Mathlib.RingTheory.Algebraic
/-!
### Cardinality of algebraic numbers
In this file, we prove variants of the following result: the cardinality of algebraic numbers under
an R-algebra is at most `# R[X] * ℵ₀`.
Although this can be used to prove that real or complex transcendental numbers exist, a more direct
proof is given by `Liouville.is_transcendental`.
-/
universe u v
open Cardinal Polynomial Set
open Cardinal Polynomial
namespace Algebraic
theorem infinite_of_charZero (R A : Type*) [CommRing R] [IsDomain R] [Ring A] [Algebra R A]
[CharZero A] : { x : A | IsAlgebraic R x }.Infinite :=
infinite_of_injective_forall_mem Nat.cast_injective isAlgebraic_nat
theorem aleph0_le_cardinal_mk_of_charZero (R A : Type*) [CommRing R] [IsDomain R] [Ring A]
[Algebra R A] [CharZero A] : ℵ₀ ≤ #{ x : A // IsAlgebraic R x } :=
infinite_iff.1 (Set.infinite_coe_iff.2 <| infinite_of_charZero R A)
section lift
variable (R : Type u) (A : Type v) [CommRing R] [CommRing A] [IsDomain A] [Algebra R A]
[NoZeroSMulDivisors R A]
theorem cardinal_mk_lift_le_mul :
Cardinal.lift.{u} #{ x : A // IsAlgebraic R x } ≤ Cardinal.lift.{v} #R[X] * ℵ₀ := by
rw [← mk_uLift, ← mk_uLift]
choose g hg₁ hg₂ using fun x : { x : A | IsAlgebraic R x } => x.coe_prop
refine lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le g fun f => ?_
rw [lift_le_aleph0, le_aleph0_iff_set_countable]
suffices MapsTo (↑) (g ⁻¹' {f}) (f.rootSet A) from
this.countable_of_injOn Subtype.coe_injective.injOn (f.rootSet_finite A).countable
rintro x (rfl : g x = f)
exact mem_rootSet.2 ⟨hg₁ x, hg₂ x⟩
theorem cardinal_mk_lift_le_max :
Cardinal.lift.{u} #{ x : A // IsAlgebraic R x } ≤ max (Cardinal.lift.{v} #R) ℵ₀ :=
(cardinal_mk_lift_le_mul R A).trans <|
(mul_le_mul_right' (lift_le.2 cardinal_mk_le_max) _).trans <| by simp
@[simp]
theorem cardinal_mk_lift_of_infinite [Infinite R] :
Cardinal.lift.{u} #{ x : A // IsAlgebraic R x } = Cardinal.lift.{v} #R :=
((cardinal_mk_lift_le_max R A).trans_eq (max_eq_left <| aleph0_le_mk _)).antisymm <|
lift_mk_le'.2 ⟨⟨fun x => ⟨algebraMap R A x, isAlgebraic_algebraMap _⟩, fun _ _ h =>
NoZeroSMulDivisors.algebraMap_injective R A (Subtype.ext_iff.1 h)⟩⟩
variable [Countable R]
@[simp]
protected theorem countable : Set.Countable { x : A | IsAlgebraic R x } := by
rw [← le_aleph0_iff_set_countable, ← lift_le_aleph0]
apply (cardinal_mk_lift_le_max R A).trans
simp
@[simp]
theorem cardinal_mk_of_countable_of_charZero [CharZero A] [IsDomain R] :
#{ x : A // IsAlgebraic R x } = ℵ₀ :=
(Algebraic.countable R A).le_aleph0.antisymm (aleph0_le_cardinal_mk_of_charZero R A)
end lift
section NonLift
variable (R A : Type u) [CommRing R] [CommRing A] [IsDomain A] [Algebra R A]
[NoZeroSMulDivisors R A]
theorem cardinal_mk_le_mul : #{ x : A // IsAlgebraic R x } ≤ #R[X] * ℵ₀ := by
rw [← lift_id #_, ← lift_id #R[X]]
exact cardinal_mk_lift_le_mul R A
theorem cardinal_mk_le_max : #{ x : A // IsAlgebraic R x } ≤ max #R ℵ₀ := by
rw [← lift_id #_, ← lift_id #R]
exact cardinal_mk_lift_le_max R A
@[simp]
theorem cardinal_mk_of_infinite [Infinite R] : #{ x : A // IsAlgebraic R x } = #R :=
lift_inj.1 <| cardinal_mk_lift_of_infinite R A
end NonLift
end Algebraic
|
Algebra\Bounds.lean | /-
Copyright (c) 2021 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.Order.Group.OrderIso
import Mathlib.Data.Set.Pointwise.Basic
import Mathlib.Order.Bounds.OrderIso
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual
/-!
# Upper/lower bounds in ordered monoids and groups
In this file we prove a few facts like “`-s` is bounded above iff `s` is bounded below”
(`bddAbove_neg`).
-/
open Function Set
open Pointwise
section InvNeg
variable {G : Type*} [Group G] [Preorder G] [CovariantClass G G (· * ·) (· ≤ ·)]
[CovariantClass G G (swap (· * ·)) (· ≤ ·)] {s : Set G} {a : G}
@[to_additive (attr := simp)]
theorem bddAbove_inv : BddAbove s⁻¹ ↔ BddBelow s :=
(OrderIso.inv G).bddAbove_preimage
@[to_additive (attr := simp)]
theorem bddBelow_inv : BddBelow s⁻¹ ↔ BddAbove s :=
(OrderIso.inv G).bddBelow_preimage
@[to_additive]
theorem BddAbove.inv (h : BddAbove s) : BddBelow s⁻¹ :=
bddBelow_inv.2 h
@[to_additive]
theorem BddBelow.inv (h : BddBelow s) : BddAbove s⁻¹ :=
bddAbove_inv.2 h
@[to_additive (attr := simp)]
theorem isLUB_inv : IsLUB s⁻¹ a ↔ IsGLB s a⁻¹ :=
(OrderIso.inv G).isLUB_preimage
@[to_additive]
theorem isLUB_inv' : IsLUB s⁻¹ a⁻¹ ↔ IsGLB s a :=
(OrderIso.inv G).isLUB_preimage'
@[to_additive]
theorem IsGLB.inv (h : IsGLB s a) : IsLUB s⁻¹ a⁻¹ :=
isLUB_inv'.2 h
@[to_additive (attr := simp)]
theorem isGLB_inv : IsGLB s⁻¹ a ↔ IsLUB s a⁻¹ :=
(OrderIso.inv G).isGLB_preimage
@[to_additive]
theorem isGLB_inv' : IsGLB s⁻¹ a⁻¹ ↔ IsLUB s a :=
(OrderIso.inv G).isGLB_preimage'
@[to_additive]
theorem IsLUB.inv (h : IsLUB s a) : IsGLB s⁻¹ a⁻¹ :=
isGLB_inv'.2 h
@[to_additive]
lemma BddBelow.range_inv {α : Type*} {f : α → G} (hf : BddBelow (range f)) :
BddAbove (range (fun x => (f x)⁻¹)) :=
hf.range_comp (OrderIso.inv G).monotone
@[to_additive]
lemma BddAbove.range_inv {α : Type*} {f : α → G} (hf : BddAbove (range f)) :
BddBelow (range (fun x => (f x)⁻¹)) :=
BddBelow.range_inv (G := Gᵒᵈ) hf
end InvNeg
section mul_add
variable {M : Type*} [Mul M] [Preorder M] [CovariantClass M M (· * ·) (· ≤ ·)]
[CovariantClass M M (swap (· * ·)) (· ≤ ·)]
@[to_additive]
theorem mul_mem_upperBounds_mul {s t : Set M} {a b : M} (ha : a ∈ upperBounds s)
(hb : b ∈ upperBounds t) : a * b ∈ upperBounds (s * t) :=
forall_image2_iff.2 fun _ hx _ hy => mul_le_mul' (ha hx) (hb hy)
@[to_additive]
theorem subset_upperBounds_mul (s t : Set M) :
upperBounds s * upperBounds t ⊆ upperBounds (s * t) :=
image2_subset_iff.2 fun _ hx _ hy => mul_mem_upperBounds_mul hx hy
@[to_additive]
theorem mul_mem_lowerBounds_mul {s t : Set M} {a b : M} (ha : a ∈ lowerBounds s)
(hb : b ∈ lowerBounds t) : a * b ∈ lowerBounds (s * t) :=
mul_mem_upperBounds_mul (M := Mᵒᵈ) ha hb
@[to_additive]
theorem subset_lowerBounds_mul (s t : Set M) :
lowerBounds s * lowerBounds t ⊆ lowerBounds (s * t) :=
subset_upperBounds_mul (M := Mᵒᵈ) _ _
@[to_additive]
theorem BddAbove.mul {s t : Set M} (hs : BddAbove s) (ht : BddAbove t) : BddAbove (s * t) :=
(Nonempty.mul hs ht).mono (subset_upperBounds_mul s t)
@[to_additive]
theorem BddBelow.mul {s t : Set M} (hs : BddBelow s) (ht : BddBelow t) : BddBelow (s * t) :=
(Nonempty.mul hs ht).mono (subset_lowerBounds_mul s t)
@[to_additive]
lemma BddAbove.range_mul {α : Type*} {f g : α → M} (hf : BddAbove (range f))
(hg : BddAbove (range g)) : BddAbove (range (fun x => f x * g x)) :=
BddAbove.range_comp (f := fun x => (⟨f x, g x⟩ : M × M))
(bddAbove_range_prod.mpr ⟨hf, hg⟩) (Monotone.mul' monotone_fst monotone_snd)
@[to_additive]
lemma BddBelow.range_mul {α : Type*} {f g : α → M} (hf : BddBelow (range f))
(hg : BddBelow (range g)) : BddBelow (range (fun x => f x * g x)) :=
BddAbove.range_mul (M := Mᵒᵈ) hf hg
end mul_add
section ConditionallyCompleteLattice
section Right
variable {ι G : Type*} [Group G] [ConditionallyCompleteLattice G]
[CovariantClass G G (Function.swap (· * ·)) (· ≤ ·)] [Nonempty ι] {f : ι → G}
@[to_additive]
theorem ciSup_mul (hf : BddAbove (range f)) (a : G) : (⨆ i, f i) * a = ⨆ i, f i * a :=
(OrderIso.mulRight a).map_ciSup hf
@[to_additive]
theorem ciSup_div (hf : BddAbove (range f)) (a : G) : (⨆ i, f i) / a = ⨆ i, f i / a := by
simp only [div_eq_mul_inv, ciSup_mul hf]
@[to_additive]
theorem ciInf_mul (hf : BddBelow (range f)) (a : G) : (⨅ i, f i) * a = ⨅ i, f i * a :=
(OrderIso.mulRight a).map_ciInf hf
@[to_additive]
theorem ciInf_div (hf : BddBelow (range f)) (a : G) : (⨅ i, f i) / a = ⨅ i, f i / a := by
simp only [div_eq_mul_inv, ciInf_mul hf]
end Right
section Left
variable {ι : Sort*} {G : Type*} [Group G] [ConditionallyCompleteLattice G]
[CovariantClass G G (· * ·) (· ≤ ·)] [Nonempty ι] {f : ι → G}
@[to_additive]
theorem mul_ciSup (hf : BddAbove (range f)) (a : G) : (a * ⨆ i, f i) = ⨆ i, a * f i :=
(OrderIso.mulLeft a).map_ciSup hf
@[to_additive]
theorem mul_ciInf (hf : BddBelow (range f)) (a : G) : (a * ⨅ i, f i) = ⨅ i, a * f i :=
(OrderIso.mulLeft a).map_ciInf hf
end Left
end ConditionallyCompleteLattice
|
Algebra\CubicDiscriminant.lean | /-
Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.Algebra.Polynomial.Splits
/-!
# Cubics and discriminants
This file defines cubic polynomials over a semiring and their discriminants over a splitting field.
## Main definitions
* `Cubic`: the structure representing a cubic polynomial.
* `Cubic.disc`: the discriminant of a cubic polynomial.
## Main statements
* `Cubic.disc_ne_zero_iff_roots_nodup`: the cubic discriminant is not equal to zero if and only if
the cubic has no duplicate roots.
## References
* https://en.wikipedia.org/wiki/Cubic_equation
* https://en.wikipedia.org/wiki/Discriminant
## Tags
cubic, discriminant, polynomial, root
-/
noncomputable section
/-- The structure representing a cubic polynomial. -/
@[ext]
structure Cubic (R : Type*) where
(a b c d : R)
namespace Cubic
open Cubic Polynomial
open Polynomial
variable {R S F K : Type*}
instance [Inhabited R] : Inhabited (Cubic R) :=
⟨⟨default, default, default, default⟩⟩
instance [Zero R] : Zero (Cubic R) :=
⟨⟨0, 0, 0, 0⟩⟩
section Basic
variable {P Q : Cubic R} {a b c d a' b' c' d' : R} [Semiring R]
/-- Convert a cubic polynomial to a polynomial. -/
def toPoly (P : Cubic R) : R[X] :=
C P.a * X ^ 3 + C P.b * X ^ 2 + C P.c * X + C P.d
theorem C_mul_prod_X_sub_C_eq [CommRing S] {w x y z : S} :
C w * (X - C x) * (X - C y) * (X - C z) =
toPoly ⟨w, w * -(x + y + z), w * (x * y + x * z + y * z), w * -(x * y * z)⟩ := by
simp only [toPoly, C_neg, C_add, C_mul]
ring1
theorem prod_X_sub_C_eq [CommRing S] {x y z : S} :
(X - C x) * (X - C y) * (X - C z) =
toPoly ⟨1, -(x + y + z), x * y + x * z + y * z, -(x * y * z)⟩ := by
rw [← one_mul <| X - C x, ← C_1, C_mul_prod_X_sub_C_eq, one_mul, one_mul, one_mul]
/-! ### Coefficients -/
section Coeff
private theorem coeffs : (∀ n > 3, P.toPoly.coeff n = 0) ∧ P.toPoly.coeff 3 = P.a ∧
P.toPoly.coeff 2 = P.b ∧ P.toPoly.coeff 1 = P.c ∧ P.toPoly.coeff 0 = P.d := by
simp only [toPoly, coeff_add, coeff_C, coeff_C_mul_X, coeff_C_mul_X_pow]
norm_num
intro n hn
repeat' rw [if_neg]
any_goals linarith only [hn]
repeat' rw [zero_add]
@[simp]
theorem coeff_eq_zero {n : ℕ} (hn : 3 < n) : P.toPoly.coeff n = 0 :=
coeffs.1 n hn
@[simp]
theorem coeff_eq_a : P.toPoly.coeff 3 = P.a :=
coeffs.2.1
@[simp]
theorem coeff_eq_b : P.toPoly.coeff 2 = P.b :=
coeffs.2.2.1
@[simp]
theorem coeff_eq_c : P.toPoly.coeff 1 = P.c :=
coeffs.2.2.2.1
@[simp]
theorem coeff_eq_d : P.toPoly.coeff 0 = P.d :=
coeffs.2.2.2.2
theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [← coeff_eq_a, h, coeff_eq_a]
theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by rw [← coeff_eq_b, h, coeff_eq_b]
theorem c_of_eq (h : P.toPoly = Q.toPoly) : P.c = Q.c := by rw [← coeff_eq_c, h, coeff_eq_c]
theorem d_of_eq (h : P.toPoly = Q.toPoly) : P.d = Q.d := by rw [← coeff_eq_d, h, coeff_eq_d]
theorem toPoly_injective (P Q : Cubic R) : P.toPoly = Q.toPoly ↔ P = Q :=
⟨fun h ↦ Cubic.ext (a_of_eq h) (b_of_eq h) (c_of_eq h) (d_of_eq h), congr_arg toPoly⟩
theorem of_a_eq_zero (ha : P.a = 0) : P.toPoly = C P.b * X ^ 2 + C P.c * X + C P.d := by
rw [toPoly, ha, C_0, zero_mul, zero_add]
theorem of_a_eq_zero' : toPoly ⟨0, b, c, d⟩ = C b * X ^ 2 + C c * X + C d :=
of_a_eq_zero rfl
theorem of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly = C P.c * X + C P.d := by
rw [of_a_eq_zero ha, hb, C_0, zero_mul, zero_add]
theorem of_b_eq_zero' : toPoly ⟨0, 0, c, d⟩ = C c * X + C d :=
of_b_eq_zero rfl rfl
theorem of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly = C P.d := by
rw [of_b_eq_zero ha hb, hc, C_0, zero_mul, zero_add]
theorem of_c_eq_zero' : toPoly ⟨0, 0, 0, d⟩ = C d :=
of_c_eq_zero rfl rfl rfl
theorem of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) :
P.toPoly = 0 := by
rw [of_c_eq_zero ha hb hc, hd, C_0]
theorem of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly = 0 :=
of_d_eq_zero rfl rfl rfl rfl
theorem zero : (0 : Cubic R).toPoly = 0 :=
of_d_eq_zero'
theorem toPoly_eq_zero_iff (P : Cubic R) : P.toPoly = 0 ↔ P = 0 := by
rw [← zero, toPoly_injective]
private theorem ne_zero (h0 : P.a ≠ 0 ∨ P.b ≠ 0 ∨ P.c ≠ 0 ∨ P.d ≠ 0) : P.toPoly ≠ 0 := by
contrapose! h0
rw [(toPoly_eq_zero_iff P).mp h0]
exact ⟨rfl, rfl, rfl, rfl⟩
theorem ne_zero_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly ≠ 0 :=
(or_imp.mp ne_zero).1 ha
theorem ne_zero_of_b_ne_zero (hb : P.b ≠ 0) : P.toPoly ≠ 0 :=
(or_imp.mp (or_imp.mp ne_zero).2).1 hb
theorem ne_zero_of_c_ne_zero (hc : P.c ≠ 0) : P.toPoly ≠ 0 :=
(or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).1 hc
theorem ne_zero_of_d_ne_zero (hd : P.d ≠ 0) : P.toPoly ≠ 0 :=
(or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).2 hd
@[simp]
theorem leadingCoeff_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.leadingCoeff = P.a :=
leadingCoeff_cubic ha
@[simp]
theorem leadingCoeff_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).leadingCoeff = a :=
leadingCoeff_of_a_ne_zero ha
@[simp]
theorem leadingCoeff_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.leadingCoeff = P.b := by
rw [of_a_eq_zero ha, leadingCoeff_quadratic hb]
@[simp]
theorem leadingCoeff_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).leadingCoeff = b :=
leadingCoeff_of_b_ne_zero rfl hb
@[simp]
theorem leadingCoeff_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) :
P.toPoly.leadingCoeff = P.c := by
rw [of_b_eq_zero ha hb, leadingCoeff_linear hc]
@[simp]
theorem leadingCoeff_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).leadingCoeff = c :=
leadingCoeff_of_c_ne_zero rfl rfl hc
@[simp]
theorem leadingCoeff_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) :
P.toPoly.leadingCoeff = P.d := by
rw [of_c_eq_zero ha hb hc, leadingCoeff_C]
-- @[simp] -- porting note (#10618): simp can prove this
theorem leadingCoeff_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).leadingCoeff = d :=
leadingCoeff_of_c_eq_zero rfl rfl rfl
theorem monic_of_a_eq_one (ha : P.a = 1) : P.toPoly.Monic := by
nontriviality R
rw [Monic, leadingCoeff_of_a_ne_zero (ha ▸ one_ne_zero), ha]
theorem monic_of_a_eq_one' : (toPoly ⟨1, b, c, d⟩).Monic :=
monic_of_a_eq_one rfl
theorem monic_of_b_eq_one (ha : P.a = 0) (hb : P.b = 1) : P.toPoly.Monic := by
nontriviality R
rw [Monic, leadingCoeff_of_b_ne_zero ha (hb ▸ one_ne_zero), hb]
theorem monic_of_b_eq_one' : (toPoly ⟨0, 1, c, d⟩).Monic :=
monic_of_b_eq_one rfl rfl
theorem monic_of_c_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 1) : P.toPoly.Monic := by
nontriviality R
rw [Monic, leadingCoeff_of_c_ne_zero ha hb (hc ▸ one_ne_zero), hc]
theorem monic_of_c_eq_one' : (toPoly ⟨0, 0, 1, d⟩).Monic :=
monic_of_c_eq_one rfl rfl rfl
theorem monic_of_d_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 1) :
P.toPoly.Monic := by
rw [Monic, leadingCoeff_of_c_eq_zero ha hb hc, hd]
theorem monic_of_d_eq_one' : (toPoly ⟨0, 0, 0, 1⟩).Monic :=
monic_of_d_eq_one rfl rfl rfl rfl
end Coeff
/-! ### Degrees -/
section Degree
/-- The equivalence between cubic polynomials and polynomials of degree at most three. -/
@[simps]
def equiv : Cubic R ≃ { p : R[X] // p.degree ≤ 3 } where
toFun P := ⟨P.toPoly, degree_cubic_le⟩
invFun f := ⟨coeff f 3, coeff f 2, coeff f 1, coeff f 0⟩
left_inv P := by ext <;> simp only [Subtype.coe_mk, coeffs]
right_inv f := by
-- Porting note: Added `simp only [Nat.zero_eq, Nat.succ_eq_add_one] <;> ring_nf`
-- There's probably a better way to do this.
ext (_ | _ | _ | _ | n) <;> simp only [Nat.zero_eq, Nat.succ_eq_add_one] <;> ring_nf
<;> try simp only [coeffs]
have h3 : 3 < 4 + n := by linarith only
rw [coeff_eq_zero h3,
(degree_le_iff_coeff_zero (f : R[X]) 3).mp f.2 _ <| WithBot.coe_lt_coe.mpr (by exact h3)]
@[simp]
theorem degree_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.degree = 3 :=
degree_cubic ha
@[simp]
theorem degree_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).degree = 3 :=
degree_of_a_ne_zero ha
theorem degree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.degree ≤ 2 := by
simpa only [of_a_eq_zero ha] using degree_quadratic_le
theorem degree_of_a_eq_zero' : (toPoly ⟨0, b, c, d⟩).degree ≤ 2 :=
degree_of_a_eq_zero rfl
@[simp]
theorem degree_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.degree = 2 := by
rw [of_a_eq_zero ha, degree_quadratic hb]
@[simp]
theorem degree_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).degree = 2 :=
degree_of_b_ne_zero rfl hb
theorem degree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.degree ≤ 1 := by
simpa only [of_b_eq_zero ha hb] using degree_linear_le
theorem degree_of_b_eq_zero' : (toPoly ⟨0, 0, c, d⟩).degree ≤ 1 :=
degree_of_b_eq_zero rfl rfl
@[simp]
theorem degree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) : P.toPoly.degree = 1 := by
rw [of_b_eq_zero ha hb, degree_linear hc]
@[simp]
theorem degree_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).degree = 1 :=
degree_of_c_ne_zero rfl rfl hc
theorem degree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.degree ≤ 0 := by
simpa only [of_c_eq_zero ha hb hc] using degree_C_le
theorem degree_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).degree ≤ 0 :=
degree_of_c_eq_zero rfl rfl rfl
@[simp]
theorem degree_of_d_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d ≠ 0) :
P.toPoly.degree = 0 := by
rw [of_c_eq_zero ha hb hc, degree_C hd]
@[simp]
theorem degree_of_d_ne_zero' (hd : d ≠ 0) : (toPoly ⟨0, 0, 0, d⟩).degree = 0 :=
degree_of_d_ne_zero rfl rfl rfl hd
@[simp]
theorem degree_of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) :
P.toPoly.degree = ⊥ := by
rw [of_d_eq_zero ha hb hc hd, degree_zero]
-- @[simp] -- porting note (#10618): simp can prove this
theorem degree_of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly.degree = ⊥ :=
degree_of_d_eq_zero rfl rfl rfl rfl
@[simp]
theorem degree_of_zero : (0 : Cubic R).toPoly.degree = ⊥ :=
degree_of_d_eq_zero'
@[simp]
theorem natDegree_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.natDegree = 3 :=
natDegree_cubic ha
@[simp]
theorem natDegree_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).natDegree = 3 :=
natDegree_of_a_ne_zero ha
theorem natDegree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.natDegree ≤ 2 := by
simpa only [of_a_eq_zero ha] using natDegree_quadratic_le
theorem natDegree_of_a_eq_zero' : (toPoly ⟨0, b, c, d⟩).natDegree ≤ 2 :=
natDegree_of_a_eq_zero rfl
@[simp]
theorem natDegree_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.natDegree = 2 := by
rw [of_a_eq_zero ha, natDegree_quadratic hb]
@[simp]
theorem natDegree_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).natDegree = 2 :=
natDegree_of_b_ne_zero rfl hb
theorem natDegree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.natDegree ≤ 1 := by
simpa only [of_b_eq_zero ha hb] using natDegree_linear_le
theorem natDegree_of_b_eq_zero' : (toPoly ⟨0, 0, c, d⟩).natDegree ≤ 1 :=
natDegree_of_b_eq_zero rfl rfl
@[simp]
theorem natDegree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) :
P.toPoly.natDegree = 1 := by
rw [of_b_eq_zero ha hb, natDegree_linear hc]
@[simp]
theorem natDegree_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).natDegree = 1 :=
natDegree_of_c_ne_zero rfl rfl hc
@[simp]
theorem natDegree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) :
P.toPoly.natDegree = 0 := by
rw [of_c_eq_zero ha hb hc, natDegree_C]
-- @[simp] -- porting note (#10618): simp can prove this
theorem natDegree_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).natDegree = 0 :=
natDegree_of_c_eq_zero rfl rfl rfl
@[simp]
theorem natDegree_of_zero : (0 : Cubic R).toPoly.natDegree = 0 :=
natDegree_of_c_eq_zero'
end Degree
/-! ### Map across a homomorphism -/
section Map
variable [Semiring S] {φ : R →+* S}
/-- Map a cubic polynomial across a semiring homomorphism. -/
def map (φ : R →+* S) (P : Cubic R) : Cubic S :=
⟨φ P.a, φ P.b, φ P.c, φ P.d⟩
theorem map_toPoly : (map φ P).toPoly = Polynomial.map φ P.toPoly := by
simp only [map, toPoly, map_C, map_X, Polynomial.map_add, Polynomial.map_mul, Polynomial.map_pow]
end Map
end Basic
section Roots
open Multiset
/-! ### Roots over an extension -/
section Extension
variable {P : Cubic R} [CommRing R] [CommRing S] {φ : R →+* S}
/-- The roots of a cubic polynomial. -/
def roots [IsDomain R] (P : Cubic R) : Multiset R :=
P.toPoly.roots
theorem map_roots [IsDomain S] : (map φ P).roots = (Polynomial.map φ P.toPoly).roots := by
rw [roots, map_toPoly]
theorem mem_roots_iff [IsDomain R] (h0 : P.toPoly ≠ 0) (x : R) :
x ∈ P.roots ↔ P.a * x ^ 3 + P.b * x ^ 2 + P.c * x + P.d = 0 := by
rw [roots, mem_roots h0, IsRoot, toPoly]
simp only [eval_C, eval_X, eval_add, eval_mul, eval_pow]
theorem card_roots_le [IsDomain R] [DecidableEq R] : P.roots.toFinset.card ≤ 3 := by
apply (toFinset_card_le P.toPoly.roots).trans
by_cases hP : P.toPoly = 0
· exact (card_roots' P.toPoly).trans (by rw [hP, natDegree_zero]; exact zero_le 3)
· exact WithBot.coe_le_coe.1 ((card_roots hP).trans degree_cubic_le)
end Extension
variable {P : Cubic F} [Field F] [Field K] {φ : F →+* K} {x y z : K}
/-! ### Roots over a splitting field -/
section Split
theorem splits_iff_card_roots (ha : P.a ≠ 0) :
Splits φ P.toPoly ↔ Multiset.card (map φ P).roots = 3 := by
replace ha : (map φ P).a ≠ 0 := (_root_.map_ne_zero φ).mpr ha
nth_rw 1 [← RingHom.id_comp φ]
rw [roots, ← splits_map_iff, ← map_toPoly, Polynomial.splits_iff_card_roots,
← ((degree_eq_iff_natDegree_eq <| ne_zero_of_a_ne_zero ha).1 <| degree_of_a_ne_zero ha : _ = 3)]
theorem splits_iff_roots_eq_three (ha : P.a ≠ 0) :
Splits φ P.toPoly ↔ ∃ x y z : K, (map φ P).roots = {x, y, z} := by
rw [splits_iff_card_roots ha, card_eq_three]
theorem eq_prod_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
(map φ P).toPoly = C (φ P.a) * (X - C x) * (X - C y) * (X - C z) := by
rw [map_toPoly,
eq_prod_roots_of_splits <|
(splits_iff_roots_eq_three ha).mpr <| Exists.intro x <| Exists.intro y <| Exists.intro z h3,
leadingCoeff_of_a_ne_zero ha, ← map_roots, h3]
change C (φ P.a) * ((X - C x) ::ₘ (X - C y) ::ₘ {X - C z}).prod = _
rw [prod_cons, prod_cons, prod_singleton, mul_assoc, mul_assoc]
theorem eq_sum_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
map φ P =
⟨φ P.a, φ P.a * -(x + y + z), φ P.a * (x * y + x * z + y * z), φ P.a * -(x * y * z)⟩ := by
apply_fun @toPoly _ _
· rw [eq_prod_three_roots ha h3, C_mul_prod_X_sub_C_eq]
· exact fun P Q ↦ (toPoly_injective P Q).mp
theorem b_eq_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
φ P.b = φ P.a * -(x + y + z) := by
injection eq_sum_three_roots ha h3
theorem c_eq_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
φ P.c = φ P.a * (x * y + x * z + y * z) := by
injection eq_sum_three_roots ha h3
theorem d_eq_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
φ P.d = φ P.a * -(x * y * z) := by
injection eq_sum_three_roots ha h3
end Split
/-! ### Discriminant over a splitting field -/
section Discriminant
/-- The discriminant of a cubic polynomial. -/
def disc {R : Type*} [Ring R] (P : Cubic R) : R :=
P.b ^ 2 * P.c ^ 2 - 4 * P.a * P.c ^ 3 - 4 * P.b ^ 3 * P.d - 27 * P.a ^ 2 * P.d ^ 2 +
18 * P.a * P.b * P.c * P.d
theorem disc_eq_prod_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
φ P.disc = (φ P.a * φ P.a * (x - y) * (x - z) * (y - z)) ^ 2 := by
simp only [disc, RingHom.map_add, RingHom.map_sub, RingHom.map_mul, map_pow]
-- Porting note: Replaced `simp only [RingHom.map_one, map_bit0, map_bit1]` with f4, f18, f27
have f4 : φ 4 = 4 := map_natCast φ 4
have f18 : φ 18 = 18 := map_natCast φ 18
have f27 : φ 27 = 27 := map_natCast φ 27
rw [f4, f18, f27, b_eq_three_roots ha h3, c_eq_three_roots ha h3, d_eq_three_roots ha h3]
ring1
theorem disc_ne_zero_iff_roots_ne (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
P.disc ≠ 0 ↔ x ≠ y ∧ x ≠ z ∧ y ≠ z := by
rw [← _root_.map_ne_zero φ, disc_eq_prod_three_roots ha h3, pow_two]
simp_rw [mul_ne_zero_iff, sub_ne_zero, _root_.map_ne_zero, and_self_iff, and_iff_right ha,
and_assoc]
theorem disc_ne_zero_iff_roots_nodup (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
P.disc ≠ 0 ↔ (map φ P).roots.Nodup := by
rw [disc_ne_zero_iff_roots_ne ha h3, h3]
change _ ↔ (x ::ₘ y ::ₘ {z}).Nodup
rw [nodup_cons, nodup_cons, mem_cons, mem_singleton, mem_singleton]
simp only [nodup_singleton]
tauto
theorem card_roots_of_disc_ne_zero [DecidableEq K] (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z})
(hd : P.disc ≠ 0) : (map φ P).roots.toFinset.card = 3 := by
rw [toFinset_card_of_nodup <| (disc_ne_zero_iff_roots_nodup ha h3).mp hd,
← splits_iff_card_roots ha, splits_iff_roots_eq_three ha]
exact ⟨x, ⟨y, ⟨z, h3⟩⟩⟩
end Discriminant
end Roots
end Cubic
|
Algebra\DirectLimit.lean | /-
Copyright (c) 2019 Kenny Lau, Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Jujian Zhang
-/
import Mathlib.Data.Finset.Order
import Mathlib.Algebra.DirectSum.Module
import Mathlib.RingTheory.FreeCommRing
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.RingTheory.Ideal.Quotient
import Mathlib.Tactic.SuppressCompilation
/-!
# Direct limit of modules, abelian groups, rings, and fields.
See Atiyah-Macdonald PP.32-33, Matsumura PP.269-270
Generalizes the notion of "union", or "gluing", of incomparable modules over the same ring,
or incomparable abelian groups, or rings, or fields.
It is constructed as a quotient of the free module (for the module case) or quotient of
the free commutative ring (for the ring case) instead of a quotient of the disjoint union
so as to make the operations (addition etc.) "computable".
## Main definitions
* `DirectedSystem f`
* `Module.DirectLimit G f`
* `AddCommGroup.DirectLimit G f`
* `Ring.DirectLimit G f`
-/
suppress_compilation
universe u v v' v'' w u₁
open Submodule
variable {R : Type u} [Ring R]
variable {ι : Type v}
variable [Preorder ι]
variable (G : ι → Type w)
/-- A directed system is a functor from a category (directed poset) to another category. -/
class DirectedSystem (f : ∀ i j, i ≤ j → G i → G j) : Prop where
map_self' : ∀ i x h, f i i h x = x
map_map' : ∀ {i j k} (hij hjk x), f j k hjk (f i j hij x) = f i k (le_trans hij hjk) x
section
variable {G}
variable (f : ∀ i j, i ≤ j → G i → G j) [DirectedSystem G fun i j h => f i j h]
theorem DirectedSystem.map_self i x h : f i i h x = x :=
DirectedSystem.map_self' i x h
theorem DirectedSystem.map_map {i j k} (hij hjk x) :
f j k hjk (f i j hij x) = f i k (le_trans hij hjk) x :=
DirectedSystem.map_map' hij hjk x
end
namespace Module
variable [∀ i, AddCommGroup (G i)] [∀ i, Module R (G i)]
variable {G}
variable (f : ∀ i j, i ≤ j → G i →ₗ[R] G j)
/-- A copy of `DirectedSystem.map_self` specialized to linear maps, as otherwise the
`fun i j h ↦ f i j h` can confuse the simplifier. -/
nonrec theorem DirectedSystem.map_self [DirectedSystem G fun i j h => f i j h] (i x h) :
f i i h x = x :=
DirectedSystem.map_self (fun i j h => f i j h) i x h
/-- A copy of `DirectedSystem.map_map` specialized to linear maps, as otherwise the
`fun i j h ↦ f i j h` can confuse the simplifier. -/
nonrec theorem DirectedSystem.map_map [DirectedSystem G fun i j h => f i j h] {i j k} (hij hjk x) :
f j k hjk (f i j hij x) = f i k (le_trans hij hjk) x :=
DirectedSystem.map_map (fun i j h => f i j h) hij hjk x
variable (G)
/-- The direct limit of a directed system is the modules glued together along the maps. -/
def DirectLimit [DecidableEq ι] : Type max v w :=
DirectSum ι G ⧸
(span R <|
{ a |
∃ (i j : _) (H : i ≤ j) (x : _),
DirectSum.lof R ι G i x - DirectSum.lof R ι G j (f i j H x) = a })
namespace DirectLimit
section Basic
variable [DecidableEq ι]
instance addCommGroup : AddCommGroup (DirectLimit G f) :=
Quotient.addCommGroup _
instance module : Module R (DirectLimit G f) :=
Quotient.module _
instance inhabited : Inhabited (DirectLimit G f) :=
⟨0⟩
instance unique [IsEmpty ι] : Unique (DirectLimit G f) :=
inferInstanceAs <| Unique (Quotient _)
variable (R ι)
/-- The canonical map from a component to the direct limit. -/
def of (i) : G i →ₗ[R] DirectLimit G f :=
(mkQ _).comp <| DirectSum.lof R ι G i
variable {R ι G f}
@[simp]
theorem of_f {i j hij x} : of R ι G f j (f i j hij x) = of R ι G f i x :=
Eq.symm <| (Submodule.Quotient.eq _).2 <| subset_span ⟨i, j, hij, x, rfl⟩
/-- Every element of the direct limit corresponds to some element in
some component of the directed system. -/
theorem exists_of [Nonempty ι] [IsDirected ι (· ≤ ·)] (z : DirectLimit G f) :
∃ i x, of R ι G f i x = z :=
Nonempty.elim (by infer_instance) fun ind : ι =>
Quotient.inductionOn' z fun z =>
DirectSum.induction_on z ⟨ind, 0, LinearMap.map_zero _⟩ (fun i x => ⟨i, x, rfl⟩)
fun p q ⟨i, x, ihx⟩ ⟨j, y, ihy⟩ =>
let ⟨k, hik, hjk⟩ := exists_ge_ge i j
⟨k, f i k hik x + f j k hjk y, by
rw [LinearMap.map_add, of_f, of_f, ihx, ihy]
rfl ⟩
@[elab_as_elim]
protected theorem induction_on [Nonempty ι] [IsDirected ι (· ≤ ·)] {C : DirectLimit G f → Prop}
(z : DirectLimit G f) (ih : ∀ i x, C (of R ι G f i x)) : C z :=
let ⟨i, x, h⟩ := exists_of z
h ▸ ih i x
variable {P : Type u₁} [AddCommGroup P] [Module R P] (g : ∀ i, G i →ₗ[R] P)
variable (Hg : ∀ i j hij x, g j (f i j hij x) = g i x)
variable (R ι G f)
/-- The universal property of the direct limit: maps from the components to another module
that respect the directed system structure (i.e. make some diagram commute) give rise
to a unique map out of the direct limit. -/
def lift : DirectLimit G f →ₗ[R] P :=
liftQ _ (DirectSum.toModule R ι P g)
(span_le.2 fun a ⟨i, j, hij, x, hx⟩ => by
rw [← hx, SetLike.mem_coe, LinearMap.sub_mem_ker_iff, DirectSum.toModule_lof,
DirectSum.toModule_lof, Hg])
variable {R ι G f}
theorem lift_of {i} (x) : lift R ι G f g Hg (of R ι G f i x) = g i x :=
DirectSum.toModule_lof R _ _
theorem lift_unique [IsDirected ι (· ≤ ·)] (F : DirectLimit G f →ₗ[R] P) (x) :
F x =
lift R ι G f (fun i => F.comp <| of R ι G f i)
(fun i j hij x => by rw [LinearMap.comp_apply, of_f]; rfl) x := by
cases isEmpty_or_nonempty ι
· simp_rw [Subsingleton.elim x 0, _root_.map_zero]
· exact DirectLimit.induction_on x fun i x => by rw [lift_of]; rfl
lemma lift_injective [IsDirected ι (· ≤ ·)]
(injective : ∀ i, Function.Injective <| g i) :
Function.Injective (lift R ι G f g Hg) := by
cases isEmpty_or_nonempty ι
· apply Function.injective_of_subsingleton
simp_rw [injective_iff_map_eq_zero] at injective ⊢
intros z hz
induction' z using DirectLimit.induction_on with _ g
rw [lift_of] at hz
rw [injective _ g hz, _root_.map_zero]
section functorial
variable {G' : ι → Type v'} [∀ i, AddCommGroup (G' i)] [∀ i, Module R (G' i)]
variable {f' : ∀ i j, i ≤ j → G' i →ₗ[R] G' j}
variable {G'' : ι → Type v''} [∀ i, AddCommGroup (G'' i)] [∀ i, Module R (G'' i)]
variable {f'' : ∀ i j, i ≤ j → G'' i →ₗ[R] G'' j}
/--
Consider direct limits `lim G` and `lim G'` with direct system `f` and `f'` respectively, any
family of linear maps `gᵢ : Gᵢ ⟶ G'ᵢ` such that `g ∘ f = f' ∘ g` induces a linear map
`lim G ⟶ lim G'`.
-/
def map (g : (i : ι) → G i →ₗ[R] G' i) (hg : ∀ i j h, g j ∘ₗ f i j h = f' i j h ∘ₗ g i) :
DirectLimit G f →ₗ[R] DirectLimit G' f' :=
lift _ _ _ _ (fun i ↦ of _ _ _ _ _ ∘ₗ g i) fun i j h g ↦ by
cases isEmpty_or_nonempty ι
· subsingleton
· have eq1 := LinearMap.congr_fun (hg i j h) g
simp only [LinearMap.coe_comp, Function.comp_apply] at eq1 ⊢
rw [eq1, of_f]
@[simp] lemma map_apply_of (g : (i : ι) → G i →ₗ[R] G' i)
(hg : ∀ i j h, g j ∘ₗ f i j h = f' i j h ∘ₗ g i)
{i : ι} (x : G i) :
map g hg (of _ _ G f _ x) = of R ι G' f' i (g i x) :=
lift_of _ _ _
@[simp] lemma map_id [IsDirected ι (· ≤ ·)] :
map (fun i ↦ LinearMap.id) (fun _ _ _ ↦ rfl) = LinearMap.id (R := R) (M := DirectLimit G f) :=
DFunLike.ext _ _ fun x ↦ (isEmpty_or_nonempty ι).elim (by subsingleton) fun _ ↦
x.induction_on fun i g ↦ by simp
lemma map_comp [IsDirected ι (· ≤ ·)]
(g₁ : (i : ι) → G i →ₗ[R] G' i) (g₂ : (i : ι) → G' i →ₗ[R] G'' i)
(hg₁ : ∀ i j h, g₁ j ∘ₗ f i j h = f' i j h ∘ₗ g₁ i)
(hg₂ : ∀ i j h, g₂ j ∘ₗ f' i j h = f'' i j h ∘ₗ g₂ i) :
(map g₂ hg₂ ∘ₗ map g₁ hg₁ :
DirectLimit G f →ₗ[R] DirectLimit G'' f'') =
(map (fun i ↦ g₂ i ∘ₗ g₁ i) fun i j h ↦ by
rw [LinearMap.comp_assoc, hg₁ i, ← LinearMap.comp_assoc, hg₂ i, LinearMap.comp_assoc] :
DirectLimit G f →ₗ[R] DirectLimit G'' f'') :=
DFunLike.ext _ _ fun x ↦ (isEmpty_or_nonempty ι).elim (by subsingleton) fun _ ↦
x.induction_on fun i g ↦ by simp
open LinearEquiv LinearMap in
/--
Consider direct limits `lim G` and `lim G'` with direct system `f` and `f'` respectively, any
family of equivalences `eᵢ : Gᵢ ≅ G'ᵢ` such that `e ∘ f = f' ∘ e` induces an equivalence
`lim G ≅ lim G'`.
-/
def congr [IsDirected ι (· ≤ ·)]
(e : (i : ι) → G i ≃ₗ[R] G' i) (he : ∀ i j h, e j ∘ₗ f i j h = f' i j h ∘ₗ e i) :
DirectLimit G f ≃ₗ[R] DirectLimit G' f' :=
LinearEquiv.ofLinear (map (e ·) he)
(map (fun i ↦ (e i).symm) fun i j h ↦ by
rw [toLinearMap_symm_comp_eq, ← comp_assoc, he i, comp_assoc, comp_coe, symm_trans_self,
refl_toLinearMap, comp_id])
(by simp [map_comp]) (by simp [map_comp])
lemma congr_apply_of [IsDirected ι (· ≤ ·)]
(e : (i : ι) → G i ≃ₗ[R] G' i) (he : ∀ i j h, e j ∘ₗ f i j h = f' i j h ∘ₗ e i)
{i : ι} (g : G i) :
congr e he (of _ _ G f i g) = of _ _ G' f' i (e i g) :=
map_apply_of _ he _
open LinearEquiv LinearMap in
lemma congr_symm_apply_of [IsDirected ι (· ≤ ·)]
(e : (i : ι) → G i ≃ₗ[R] G' i) (he : ∀ i j h, e j ∘ₗ f i j h = f' i j h ∘ₗ e i)
{i : ι} (g : G' i) :
(congr e he).symm (of _ _ G' f' i g) = of _ _ G f i ((e i).symm g) :=
map_apply_of _ (fun i j h ↦ by
rw [toLinearMap_symm_comp_eq, ← comp_assoc, he i, comp_assoc, comp_coe, symm_trans_self,
refl_toLinearMap, comp_id]) _
end functorial
end Basic
section Totalize
open Classical in
/-- `totalize G f i j` is a linear map from `G i` to `G j`, for *every* `i` and `j`.
If `i ≤ j`, then it is the map `f i j` that comes with the directed system `G`,
and otherwise it is the zero map. -/
noncomputable def totalize (i j) : G i →ₗ[R] G j :=
if h : i ≤ j then f i j h else 0
variable {G f}
theorem totalize_of_le {i j} (h : i ≤ j) : totalize G f i j = f i j h :=
dif_pos h
theorem totalize_of_not_le {i j} (h : ¬i ≤ j) : totalize G f i j = 0 :=
dif_neg h
end Totalize
variable [DecidableEq ι] [DirectedSystem G fun i j h => f i j h]
variable {G f}
theorem toModule_totalize_of_le [∀ i (k : G i), Decidable (k ≠ 0)] {x : DirectSum ι G} {i j : ι}
(hij : i ≤ j) (hx : ∀ k ∈ x.support, k ≤ i) :
DirectSum.toModule R ι (G j) (fun k => totalize G f k j) x =
f i j hij (DirectSum.toModule R ι (G i) (fun k => totalize G f k i) x) := by
rw [← @DFinsupp.sum_single ι G _ _ _ x]
unfold DFinsupp.sum
simp only [map_sum]
refine Finset.sum_congr rfl fun k hk => ?_
rw [DirectSum.single_eq_lof R k (x k), DirectSum.toModule_lof, DirectSum.toModule_lof,
totalize_of_le (hx k hk), totalize_of_le (le_trans (hx k hk) hij), DirectedSystem.map_map]
theorem of.zero_exact_aux [∀ i (k : G i), Decidable (k ≠ 0)] [Nonempty ι] [IsDirected ι (· ≤ ·)]
{x : DirectSum ι G} (H : (Submodule.Quotient.mk x : DirectLimit G f) = (0 : DirectLimit G f)) :
∃ j,
(∀ k ∈ x.support, k ≤ j) ∧
DirectSum.toModule R ι (G j) (fun i => totalize G f i j) x = (0 : G j) :=
Nonempty.elim (by infer_instance) fun ind : ι =>
span_induction ((Quotient.mk_eq_zero _).1 H)
(fun x ⟨i, j, hij, y, hxy⟩ =>
let ⟨k, hik, hjk⟩ := exists_ge_ge i j
⟨k, by
subst hxy
constructor
· intro i0 hi0
rw [DFinsupp.mem_support_iff, DirectSum.sub_apply, ← DirectSum.single_eq_lof, ←
DirectSum.single_eq_lof, DFinsupp.single_apply, DFinsupp.single_apply] at hi0
split_ifs at hi0 with hi hj hj
· rwa [hi] at hik
· rwa [hi] at hik
· rwa [hj] at hjk
exfalso
apply hi0
rw [sub_zero]
simp [LinearMap.map_sub, totalize_of_le, hik, hjk, DirectedSystem.map_map,
DirectSum.apply_eq_component, DirectSum.component.of]⟩)
⟨ind, fun _ h => (Finset.not_mem_empty _ h).elim, LinearMap.map_zero _⟩
(fun x y ⟨i, hi, hxi⟩ ⟨j, hj, hyj⟩ =>
let ⟨k, hik, hjk⟩ := exists_ge_ge i j
⟨k, fun l hl =>
(Finset.mem_union.1 (DFinsupp.support_add hl)).elim (fun hl => le_trans (hi _ hl) hik)
fun hl => le_trans (hj _ hl) hjk, by
-- Porting note: this had been
-- simp [LinearMap.map_add, hxi, hyj, toModule_totalize_of_le hik hi,
-- toModule_totalize_of_le hjk hj]
simp only [map_add]
rw [toModule_totalize_of_le hik hi, toModule_totalize_of_le hjk hj]
simp [hxi, hyj]⟩)
fun a x ⟨i, hi, hxi⟩ =>
⟨i, fun k hk => hi k (DirectSum.support_smul _ _ hk), by simp [LinearMap.map_smul, hxi]⟩
open Classical in
/-- A component that corresponds to zero in the direct limit is already zero in some
bigger module in the directed system. -/
theorem of.zero_exact [IsDirected ι (· ≤ ·)] {i x} (H : of R ι G f i x = 0) :
∃ j hij, f i j hij x = (0 : G j) :=
haveI : Nonempty ι := ⟨i⟩
let ⟨j, hj, hxj⟩ := of.zero_exact_aux H
if hx0 : x = 0 then ⟨i, le_rfl, by simp [hx0]⟩
else
have hij : i ≤ j := hj _ <| by simp [DirectSum.apply_eq_component, hx0]
⟨j, hij, by
-- Porting note: this had been
-- simpa [totalize_of_le hij] using hxj
simp only [DirectSum.toModule_lof] at hxj
rwa [totalize_of_le hij] at hxj⟩
end DirectLimit
end Module
namespace AddCommGroup
variable [∀ i, AddCommGroup (G i)]
/-- The direct limit of a directed system is the abelian groups glued together along the maps. -/
def DirectLimit [DecidableEq ι] (f : ∀ i j, i ≤ j → G i →+ G j) : Type _ :=
@Module.DirectLimit ℤ _ ι _ G _ _ (fun i j hij => (f i j hij).toIntLinearMap) _
namespace DirectLimit
variable (f : ∀ i j, i ≤ j → G i →+ G j)
protected theorem directedSystem [h : DirectedSystem G fun i j h => f i j h] :
DirectedSystem G fun i j hij => (f i j hij).toIntLinearMap :=
h
attribute [local instance] DirectLimit.directedSystem
variable [DecidableEq ι]
instance : AddCommGroup (DirectLimit G f) :=
Module.DirectLimit.addCommGroup G fun i j hij => (f i j hij).toIntLinearMap
instance : Inhabited (DirectLimit G f) :=
⟨0⟩
instance [IsEmpty ι] : Unique (DirectLimit G f) := Module.DirectLimit.unique _ _
/-- The canonical map from a component to the direct limit. -/
def of (i) : G i →+ DirectLimit G f :=
(Module.DirectLimit.of ℤ ι G (fun i j hij => (f i j hij).toIntLinearMap) i).toAddMonoidHom
variable {G f}
@[simp]
theorem of_f {i j} (hij) (x) : of G f j (f i j hij x) = of G f i x :=
Module.DirectLimit.of_f
@[elab_as_elim]
protected theorem induction_on [Nonempty ι] [IsDirected ι (· ≤ ·)] {C : DirectLimit G f → Prop}
(z : DirectLimit G f) (ih : ∀ i x, C (of G f i x)) : C z :=
Module.DirectLimit.induction_on z ih
/-- A component that corresponds to zero in the direct limit is already zero in some
bigger module in the directed system. -/
theorem of.zero_exact [IsDirected ι (· ≤ ·)] [DirectedSystem G fun i j h => f i j h] (i x)
(h : of G f i x = 0) : ∃ j hij, f i j hij x = 0 :=
Module.DirectLimit.of.zero_exact h
variable (P : Type u₁) [AddCommGroup P]
variable (g : ∀ i, G i →+ P)
variable (Hg : ∀ i j hij x, g j (f i j hij x) = g i x)
variable (G f)
/-- The universal property of the direct limit: maps from the components to another abelian group
that respect the directed system structure (i.e. make some diagram commute) give rise
to a unique map out of the direct limit. -/
def lift : DirectLimit G f →+ P :=
(Module.DirectLimit.lift ℤ ι G (fun i j hij => (f i j hij).toIntLinearMap)
(fun i => (g i).toIntLinearMap) Hg).toAddMonoidHom
variable {G f}
@[simp]
theorem lift_of (i x) : lift G f P g Hg (of G f i x) = g i x :=
Module.DirectLimit.lift_of
-- Note: had to make these arguments explicit #8386
(f := (fun i j hij => (f i j hij).toIntLinearMap))
(fun i => (g i).toIntLinearMap)
Hg
x
theorem lift_unique [IsDirected ι (· ≤ ·)] (F : DirectLimit G f →+ P) (x) :
F x = lift G f P (fun i => F.comp (of G f i)) (fun i j hij x => by simp) x := by
cases isEmpty_or_nonempty ι
· simp_rw [Subsingleton.elim x 0, _root_.map_zero]
· exact DirectLimit.induction_on x fun i x => by simp
lemma lift_injective [IsDirected ι (· ≤ ·)]
(injective : ∀ i, Function.Injective <| g i) :
Function.Injective (lift G f P g Hg) := by
cases isEmpty_or_nonempty ι
· apply Function.injective_of_subsingleton
simp_rw [injective_iff_map_eq_zero] at injective ⊢
intros z hz
induction' z using DirectLimit.induction_on with _ g
rw [lift_of] at hz
rw [injective _ g hz, _root_.map_zero]
section functorial
variable {G' : ι → Type v'} [∀ i, AddCommGroup (G' i)]
variable {f' : ∀ i j, i ≤ j → G' i →+ G' j}
variable {G'' : ι → Type v''} [∀ i, AddCommGroup (G'' i)]
variable {f'' : ∀ i j, i ≤ j → G'' i →+ G'' j}
/--
Consider direct limits `lim G` and `lim G'` with direct system `f` and `f'` respectively, any
family of group homomorphisms `gᵢ : Gᵢ ⟶ G'ᵢ` such that `g ∘ f = f' ∘ g` induces a group
homomorphism `lim G ⟶ lim G'`.
-/
def map (g : (i : ι) → G i →+ G' i)
(hg : ∀ i j h, (g j).comp (f i j h) = (f' i j h).comp (g i)) :
DirectLimit G f →+ DirectLimit G' f' :=
lift _ _ _ (fun i ↦ (of _ _ _).comp (g i)) fun i j h g ↦ by
cases isEmpty_or_nonempty ι
· subsingleton
· have eq1 := DFunLike.congr_fun (hg i j h) g
simp only [AddMonoidHom.coe_comp, Function.comp_apply] at eq1 ⊢
rw [eq1, of_f]
@[simp] lemma map_apply_of (g : (i : ι) → G i →+ G' i)
(hg : ∀ i j h, (g j).comp (f i j h) = (f' i j h).comp (g i))
{i : ι} (x : G i) :
map g hg (of G f _ x) = of G' f' i (g i x) :=
lift_of _ _ _ _ _
@[simp] lemma map_id [IsDirected ι (· ≤ ·)] :
map (fun i ↦ AddMonoidHom.id _) (fun _ _ _ ↦ rfl) = AddMonoidHom.id (DirectLimit G f) :=
DFunLike.ext _ _ fun x ↦ (isEmpty_or_nonempty ι).elim (by subsingleton) fun _ ↦
x.induction_on fun i g ↦ by simp
lemma map_comp [IsDirected ι (· ≤ ·)]
(g₁ : (i : ι) → G i →+ G' i) (g₂ : (i : ι) → G' i →+ G'' i)
(hg₁ : ∀ i j h, (g₁ j).comp (f i j h) = (f' i j h).comp (g₁ i))
(hg₂ : ∀ i j h, (g₂ j).comp (f' i j h) = (f'' i j h).comp (g₂ i)) :
((map g₂ hg₂).comp (map g₁ hg₁) :
DirectLimit G f →+ DirectLimit G'' f'') =
(map (fun i ↦ (g₂ i).comp (g₁ i)) fun i j h ↦ by
rw [AddMonoidHom.comp_assoc, hg₁ i, ← AddMonoidHom.comp_assoc, hg₂ i,
AddMonoidHom.comp_assoc] :
DirectLimit G f →+ DirectLimit G'' f'') :=
DFunLike.ext _ _ fun x ↦ (isEmpty_or_nonempty ι).elim (by subsingleton) fun _ ↦
x.induction_on fun i g ↦ by simp
/--
Consider direct limits `lim G` and `lim G'` with direct system `f` and `f'` respectively, any
family of equivalences `eᵢ : Gᵢ ≅ G'ᵢ` such that `e ∘ f = f' ∘ e` induces an equivalence
`lim G ⟶ lim G'`.
-/
def congr [IsDirected ι (· ≤ ·)]
(e : (i : ι) → G i ≃+ G' i)
(he : ∀ i j h, (e j).toAddMonoidHom.comp (f i j h) = (f' i j h).comp (e i)) :
DirectLimit G f ≃+ DirectLimit G' f' :=
AddMonoidHom.toAddEquiv (map (e ·) he)
(map (fun i ↦ (e i).symm) fun i j h ↦ DFunLike.ext _ _ fun x ↦ by
have eq1 := DFunLike.congr_fun (he i j h) ((e i).symm x)
simp only [AddMonoidHom.coe_comp, AddEquiv.coe_toAddMonoidHom, Function.comp_apply,
AddMonoidHom.coe_coe, AddEquiv.apply_symm_apply] at eq1 ⊢
simp [← eq1, of_f])
(by rw [map_comp]; convert map_id <;> aesop)
(by rw [map_comp]; convert map_id <;> aesop)
lemma congr_apply_of [IsDirected ι (· ≤ ·)]
(e : (i : ι) → G i ≃+ G' i)
(he : ∀ i j h, (e j).toAddMonoidHom.comp (f i j h) = (f' i j h).comp (e i))
{i : ι} (g : G i) :
congr e he (of G f i g) = of G' f' i (e i g) :=
map_apply_of _ he _
lemma congr_symm_apply_of [IsDirected ι (· ≤ ·)]
(e : (i : ι) → G i ≃+ G' i)
(he : ∀ i j h, (e j).toAddMonoidHom.comp (f i j h) = (f' i j h).comp (e i))
{i : ι} (g : G' i) :
(congr e he).symm (of G' f' i g) = of G f i ((e i).symm g) := by
simp only [congr, AddMonoidHom.toAddEquiv_symm_apply, map_apply_of, AddMonoidHom.coe_coe]
end functorial
end DirectLimit
end AddCommGroup
namespace Ring
variable [∀ i, CommRing (G i)]
section
variable (f : ∀ i j, i ≤ j → G i → G j)
open FreeCommRing
/-- The direct limit of a directed system is the rings glued together along the maps. -/
def DirectLimit : Type max v w :=
FreeCommRing (Σi, G i) ⧸
Ideal.span
{ a |
(∃ i j H x, of (⟨j, f i j H x⟩ : Σi, G i) - of ⟨i, x⟩ = a) ∨
(∃ i, of (⟨i, 1⟩ : Σi, G i) - 1 = a) ∨
(∃ i x y, of (⟨i, x + y⟩ : Σi, G i) - (of ⟨i, x⟩ + of ⟨i, y⟩) = a) ∨
∃ i x y, of (⟨i, x * y⟩ : Σi, G i) - of ⟨i, x⟩ * of ⟨i, y⟩ = a }
namespace DirectLimit
instance commRing : CommRing (DirectLimit G f) :=
Ideal.Quotient.commRing _
instance ring : Ring (DirectLimit G f) :=
CommRing.toRing
-- Porting note: Added a `Zero` instance to get rid of `0` errors.
instance zero : Zero (DirectLimit G f) := by
unfold DirectLimit
exact ⟨0⟩
instance : Inhabited (DirectLimit G f) :=
⟨0⟩
/-- The canonical map from a component to the direct limit. -/
nonrec def of (i) : G i →+* DirectLimit G f :=
RingHom.mk'
{ toFun := fun x => Ideal.Quotient.mk _ (of (⟨i, x⟩ : Σi, G i))
map_one' := Ideal.Quotient.eq.2 <| subset_span <| Or.inr <| Or.inl ⟨i, rfl⟩
map_mul' := fun x y =>
Ideal.Quotient.eq.2 <| subset_span <| Or.inr <| Or.inr <| Or.inr ⟨i, x, y, rfl⟩ }
fun x y => Ideal.Quotient.eq.2 <| subset_span <| Or.inr <| Or.inr <| Or.inl ⟨i, x, y, rfl⟩
variable {G f}
-- Porting note: the @[simp] attribute would trigger a `simpNF` linter error:
-- failed to synthesize CommMonoidWithZero (Ring.DirectLimit G f)
theorem of_f {i j} (hij) (x) : of G f j (f i j hij x) = of G f i x :=
Ideal.Quotient.eq.2 <| subset_span <| Or.inl ⟨i, j, hij, x, rfl⟩
/-- Every element of the direct limit corresponds to some element in
some component of the directed system. -/
theorem exists_of [Nonempty ι] [IsDirected ι (· ≤ ·)] (z : DirectLimit G f) :
∃ i x, of G f i x = z :=
Nonempty.elim (by infer_instance) fun ind : ι =>
Quotient.inductionOn' z fun x =>
FreeAbelianGroup.induction_on x ⟨ind, 0, (of _ _ ind).map_zero⟩
(fun s =>
Multiset.induction_on s ⟨ind, 1, (of _ _ ind).map_one⟩ fun a s ih =>
let ⟨i, x⟩ := a
let ⟨j, y, hs⟩ := ih
let ⟨k, hik, hjk⟩ := exists_ge_ge i j
⟨k, f i k hik x * f j k hjk y, by
rw [(of G f k).map_mul, of_f, of_f, hs]
/- porting note: In Lean3, from here, this was `by refl`. I have added
the lemma `FreeCommRing.of_cons` to fix this proof. -/
apply congr_arg Quotient.mk''
symm
apply FreeCommRing.of_cons⟩)
(fun s ⟨i, x, ih⟩ => ⟨i, -x, by
rw [(of G _ _).map_neg, ih]
rfl⟩)
fun p q ⟨i, x, ihx⟩ ⟨j, y, ihy⟩ =>
let ⟨k, hik, hjk⟩ := exists_ge_ge i j
⟨k, f i k hik x + f j k hjk y, by rw [(of _ _ _).map_add, of_f, of_f, ihx, ihy]; rfl⟩
section
open Polynomial
variable {f' : ∀ i j, i ≤ j → G i →+* G j}
nonrec theorem Polynomial.exists_of [Nonempty ι] [IsDirected ι (· ≤ ·)]
(q : Polynomial (DirectLimit G fun i j h => f' i j h)) :
∃ i p, Polynomial.map (of G (fun i j h => f' i j h) i) p = q :=
Polynomial.induction_on q
(fun z =>
let ⟨i, x, h⟩ := exists_of z
⟨i, C x, by rw [map_C, h]⟩)
(fun q₁ q₂ ⟨i₁, p₁, ih₁⟩ ⟨i₂, p₂, ih₂⟩ =>
let ⟨i, h1, h2⟩ := exists_ge_ge i₁ i₂
⟨i, p₁.map (f' i₁ i h1) + p₂.map (f' i₂ i h2), by
rw [Polynomial.map_add, map_map, map_map, ← ih₁, ← ih₂]
congr 2 <;> ext x <;> simp_rw [RingHom.comp_apply, of_f]⟩)
fun n z _ =>
let ⟨i, x, h⟩ := exists_of z
⟨i, C x * X ^ (n + 1), by rw [Polynomial.map_mul, map_C, h, Polynomial.map_pow, map_X]⟩
end
@[elab_as_elim]
theorem induction_on [Nonempty ι] [IsDirected ι (· ≤ ·)] {C : DirectLimit G f → Prop}
(z : DirectLimit G f) (ih : ∀ i x, C (of G f i x)) : C z :=
let ⟨i, x, hx⟩ := exists_of z
hx ▸ ih i x
section OfZeroExact
variable (f' : ∀ i j, i ≤ j → G i →+* G j)
variable [DirectedSystem G fun i j h => f' i j h]
variable (G f)
theorem of.zero_exact_aux2 {x : FreeCommRing (Σi, G i)} {s t} [DecidablePred (· ∈ s)]
[DecidablePred (· ∈ t)] (hxs : IsSupported x s) {j k} (hj : ∀ z : Σi, G i, z ∈ s → z.1 ≤ j)
(hk : ∀ z : Σi, G i, z ∈ t → z.1 ≤ k) (hjk : j ≤ k) (hst : s ⊆ t) :
f' j k hjk (lift (fun ix : s => f' ix.1.1 j (hj ix ix.2) ix.1.2) (restriction s x)) =
lift (fun ix : t => f' ix.1.1 k (hk ix ix.2) ix.1.2) (restriction t x) := by
refine Subring.InClosure.recOn hxs ?_ ?_ ?_ ?_
· rw [(restriction _).map_one, (FreeCommRing.lift _).map_one, (f' j k hjk).map_one,
(restriction _).map_one, (FreeCommRing.lift _).map_one]
· -- Porting note: Lean 3 had `(FreeCommRing.lift _).map_neg` but I needed to replace it with
-- `RingHom.map_neg` to get the rewrite to compile
rw [(restriction _).map_neg, (restriction _).map_one, RingHom.map_neg,
(FreeCommRing.lift _).map_one, (f' j k hjk).map_neg, (f' j k hjk).map_one,
-- Porting note: similarly here I give strictly less information
(restriction _).map_neg, (restriction _).map_one, RingHom.map_neg,
(FreeCommRing.lift _).map_one]
· rintro _ ⟨p, hps, rfl⟩ n ih
rw [(restriction _).map_mul, (FreeCommRing.lift _).map_mul, (f' j k hjk).map_mul, ih,
(restriction _).map_mul, (FreeCommRing.lift _).map_mul, restriction_of, dif_pos hps, lift_of,
restriction_of, dif_pos (hst hps), lift_of]
dsimp only
-- Porting note: Lean 3 could get away with far fewer hints for inputs in the line below
have := DirectedSystem.map_map (fun i j h => f' i j h) (hj p hps) hjk
rw [this]
· rintro x y ihx ihy
rw [(restriction _).map_add, (FreeCommRing.lift _).map_add, (f' j k hjk).map_add, ihx, ihy,
(restriction _).map_add, (FreeCommRing.lift _).map_add]
variable {G f f'}
theorem of.zero_exact_aux [Nonempty ι] [IsDirected ι (· ≤ ·)] {x : FreeCommRing (Σi, G i)}
(H : (Ideal.Quotient.mk _ x : DirectLimit G fun i j h => f' i j h)
= (0 : DirectLimit G fun i j h => f' i j h)) :
∃ j s, ∃ H : ∀ k : Σ i, G i, k ∈ s → k.1 ≤ j,
IsSupported x s ∧
∀ [DecidablePred (· ∈ s)],
lift (fun ix : s => f' ix.1.1 j (H ix ix.2) ix.1.2) (restriction s x) = (0 : G j) := by
have := Classical.decEq
refine span_induction (Ideal.Quotient.eq_zero_iff_mem.1 H) ?_ ?_ ?_ ?_
· rintro x (⟨i, j, hij, x, rfl⟩ | ⟨i, rfl⟩ | ⟨i, x, y, rfl⟩ | ⟨i, x, y, rfl⟩)
· refine
⟨j, {⟨i, x⟩, ⟨j, f' i j hij x⟩}, ?_,
isSupported_sub (isSupported_of.2 <| Or.inr (Set.mem_singleton _))
(isSupported_of.2 <| Or.inl rfl), fun [_] => ?_⟩
· rintro k (rfl | ⟨rfl | _⟩)
· exact hij
· rfl
· rw [(restriction _).map_sub, RingHom.map_sub, restriction_of, dif_pos,
restriction_of, dif_pos, lift_of, lift_of]
on_goal 1 =>
dsimp only
have := DirectedSystem.map_map (fun i j h => f' i j h) hij (le_refl j : j ≤ j)
rw [this]
· exact sub_self _
exacts [Or.inl rfl, Or.inr rfl]
· refine ⟨i, {⟨i, 1⟩}, ?_, isSupported_sub (isSupported_of.2 (Set.mem_singleton _))
isSupported_one, fun [_] => ?_⟩
· rintro k (rfl | h)
rfl
-- Porting note: the Lean3 proof contained `rw [restriction_of]`, but this
-- lemma does not seem to work here
· rw [RingHom.map_sub, RingHom.map_sub]
erw [lift_of, dif_pos rfl, RingHom.map_one, lift_of, RingHom.map_one, sub_self]
· refine
⟨i, {⟨i, x + y⟩, ⟨i, x⟩, ⟨i, y⟩}, ?_,
isSupported_sub (isSupported_of.2 <| Or.inl rfl)
(isSupported_add (isSupported_of.2 <| Or.inr <| Or.inl rfl)
(isSupported_of.2 <| Or.inr <| Or.inr (Set.mem_singleton _))),
fun [_] => ?_⟩
· rintro k (rfl | ⟨rfl | ⟨rfl | hk⟩⟩) <;> rfl
· rw [(restriction _).map_sub, (restriction _).map_add, restriction_of, restriction_of,
restriction_of, dif_pos, dif_pos, dif_pos, RingHom.map_sub,
(FreeCommRing.lift _).map_add, lift_of, lift_of, lift_of]
on_goal 1 =>
dsimp only
rw [(f' i i _).map_add]
· exact sub_self _
all_goals tauto
· refine
⟨i, {⟨i, x * y⟩, ⟨i, x⟩, ⟨i, y⟩}, ?_,
isSupported_sub (isSupported_of.2 <| Or.inl rfl)
(isSupported_mul (isSupported_of.2 <| Or.inr <| Or.inl rfl)
(isSupported_of.2 <| Or.inr <| Or.inr (Set.mem_singleton _))), fun [_] => ?_⟩
· rintro k (rfl | ⟨rfl | ⟨rfl | hk⟩⟩) <;> rfl
· rw [(restriction _).map_sub, (restriction _).map_mul, restriction_of, restriction_of,
restriction_of, dif_pos, dif_pos, dif_pos, RingHom.map_sub,
(FreeCommRing.lift _).map_mul, lift_of, lift_of, lift_of]
on_goal 1 =>
dsimp only
rw [(f' i i _).map_mul]
· exact sub_self _
all_goals tauto
-- Porting note: was
--exacts [sub_self _, Or.inl rfl, Or.inr (Or.inr rfl), Or.inr (Or.inl rfl)]
· refine Nonempty.elim (by infer_instance) fun ind : ι => ?_
refine ⟨ind, ∅, fun _ => False.elim, isSupported_zero, fun [_] => ?_⟩
-- Porting note: `RingHom.map_zero` was `(restriction _).map_zero`
rw [RingHom.map_zero, (FreeCommRing.lift _).map_zero]
· intro x y ⟨i, s, hi, hxs, ihs⟩ ⟨j, t, hj, hyt, iht⟩
obtain ⟨k, hik, hjk⟩ := exists_ge_ge i j
have : ∀ z : Σi, G i, z ∈ s ∪ t → z.1 ≤ k := by
rintro z (hz | hz)
· exact le_trans (hi z hz) hik
· exact le_trans (hj z hz) hjk
refine
⟨k, s ∪ t, this,
isSupported_add (isSupported_upwards hxs Set.subset_union_left)
(isSupported_upwards hyt Set.subset_union_right), fun [_] => ?_⟩
-- Porting note: was `(restriction _).map_add`
classical rw [RingHom.map_add, (FreeCommRing.lift _).map_add, ←
of.zero_exact_aux2 G f' hxs hi this hik Set.subset_union_left, ←
of.zero_exact_aux2 G f' hyt hj this hjk Set.subset_union_right, ihs,
(f' i k hik).map_zero, iht, (f' j k hjk).map_zero, zero_add]
· rintro x y ⟨j, t, hj, hyt, iht⟩
rw [smul_eq_mul]
rcases exists_finset_support x with ⟨s, hxs⟩
rcases (s.image Sigma.fst).exists_le with ⟨i, hi⟩
obtain ⟨k, hik, hjk⟩ := exists_ge_ge i j
have : ∀ z : Σi, G i, z ∈ ↑s ∪ t → z.1 ≤ k := by
rintro z (hz | hz)
exacts [(hi z.1 <| Finset.mem_image.2 ⟨z, hz, rfl⟩).trans hik, (hj z hz).trans hjk]
refine
⟨k, ↑s ∪ t, this,
isSupported_mul (isSupported_upwards hxs Set.subset_union_left)
(isSupported_upwards hyt Set.subset_union_right), fun [_] => ?_⟩
-- Porting note: RingHom.map_mul was `(restriction _).map_mul`
classical rw [RingHom.map_mul, (FreeCommRing.lift _).map_mul, ←
of.zero_exact_aux2 G f' hyt hj this hjk Set.subset_union_right, iht,
(f' j k hjk).map_zero, mul_zero]
/-- A component that corresponds to zero in the direct limit is already zero in some
bigger module in the directed system. -/
theorem of.zero_exact [IsDirected ι (· ≤ ·)] {i x} (hix : of G (fun i j h => f' i j h) i x = 0) :
∃ (j : _) (hij : i ≤ j), f' i j hij x = 0 := by
haveI : Nonempty ι := ⟨i⟩
let ⟨j, s, H, hxs, hx⟩ := of.zero_exact_aux hix
have hixs : (⟨i, x⟩ : Σi, G i) ∈ s := isSupported_of.1 hxs
classical specialize @hx _
exact ⟨j, H ⟨i, x⟩ hixs, by classical rw [restriction_of, dif_pos hixs, lift_of] at hx; exact hx⟩
end OfZeroExact
variable (f' : ∀ i j, i ≤ j → G i →+* G j)
/-- If the maps in the directed system are injective, then the canonical maps
from the components to the direct limits are injective. -/
theorem of_injective [IsDirected ι (· ≤ ·)] [DirectedSystem G fun i j h => f' i j h]
(hf : ∀ i j hij, Function.Injective (f' i j hij)) (i) :
Function.Injective (of G (fun i j h => f' i j h) i) := by
suffices ∀ x, of G (fun i j h => f' i j h) i x = 0 → x = 0 by
intro x y hxy
rw [← sub_eq_zero]
apply this
rw [(of G _ i).map_sub, hxy, sub_self]
intro x hx
rcases of.zero_exact hx with ⟨j, hij, hfx⟩
apply hf i j hij
rw [hfx, (f' i j hij).map_zero]
variable (P : Type u₁) [CommRing P]
variable (g : ∀ i, G i →+* P)
variable (Hg : ∀ i j hij x, g j (f i j hij x) = g i x)
open FreeCommRing
variable (G f)
/-- The universal property of the direct limit: maps from the components to another ring
that respect the directed system structure (i.e. make some diagram commute) give rise
to a unique map out of the direct limit.
-/
def lift : DirectLimit G f →+* P :=
Ideal.Quotient.lift _ (FreeCommRing.lift fun x : Σi, G i => g x.1 x.2)
(by
suffices Ideal.span _ ≤
Ideal.comap (FreeCommRing.lift fun x : Σi : ι, G i => g x.fst x.snd) ⊥ by
intro x hx
exact (mem_bot P).1 (this hx)
rw [Ideal.span_le]
intro x hx
rw [SetLike.mem_coe, Ideal.mem_comap, mem_bot]
rcases hx with (⟨i, j, hij, x, rfl⟩ | ⟨i, rfl⟩ | ⟨i, x, y, rfl⟩ | ⟨i, x, y, rfl⟩) <;>
simp only [RingHom.map_sub, lift_of, Hg, RingHom.map_one, RingHom.map_add, RingHom.map_mul,
(g i).map_one, (g i).map_add, (g i).map_mul, sub_self])
variable {G f}
-- Porting note: the @[simp] attribute would trigger a `simpNF` linter error:
-- failed to synthesize CommMonoidWithZero (Ring.DirectLimit G f)
theorem lift_of (i x) : lift G f P g Hg (of G f i x) = g i x :=
FreeCommRing.lift_of _ _
theorem lift_unique [IsDirected ι (· ≤ ·)] (F : DirectLimit G f →+* P) (x) :
F x = lift G f P (fun i => F.comp <| of G f i) (fun i j hij x => by simp [of_f]) x := by
cases isEmpty_or_nonempty ι
· apply DFunLike.congr_fun
apply Ideal.Quotient.ringHom_ext
refine FreeCommRing.hom_ext fun ⟨i, _⟩ ↦ ?_
exact IsEmpty.elim' inferInstance i
· exact DirectLimit.induction_on x fun i x => by simp [lift_of]
lemma lift_injective [Nonempty ι] [IsDirected ι (· ≤ ·)]
(injective : ∀ i, Function.Injective <| g i) :
Function.Injective (lift G f P g Hg) := by
simp_rw [injective_iff_map_eq_zero] at injective ⊢
intros z hz
induction' z using DirectLimit.induction_on with _ g
rw [lift_of] at hz
rw [injective _ g hz, _root_.map_zero]
section functorial
variable {f : ∀ i j, i ≤ j → G i →+* G j}
variable {G' : ι → Type v'} [∀ i, CommRing (G' i)]
variable {f' : ∀ i j, i ≤ j → G' i →+* G' j}
variable {G'' : ι → Type v''} [∀ i, CommRing (G'' i)]
variable {f'' : ∀ i j, i ≤ j → G'' i →+* G'' j}
/--
Consider direct limits `lim G` and `lim G'` with direct system `f` and `f'` respectively, any
family of ring homomorphisms `gᵢ : Gᵢ ⟶ G'ᵢ` such that `g ∘ f = f' ∘ g` induces a ring
homomorphism `lim G ⟶ lim G'`.
-/
def map (g : (i : ι) → G i →+* G' i)
(hg : ∀ i j h, (g j).comp (f i j h) = (f' i j h).comp (g i)) :
DirectLimit G (fun _ _ h ↦ f _ _ h) →+* DirectLimit G' fun _ _ h ↦ f' _ _ h :=
lift _ _ _ (fun i ↦ (of _ _ _).comp (g i)) fun i j h g ↦ by
have eq1 := DFunLike.congr_fun (hg i j h) g
simp only [RingHom.coe_comp, Function.comp_apply] at eq1 ⊢
rw [eq1, of_f]
@[simp] lemma map_apply_of (g : (i : ι) → G i →+* G' i)
(hg : ∀ i j h, (g j).comp (f i j h) = (f' i j h).comp (g i))
{i : ι} (x : G i) :
map g hg (of G _ _ x) = of G' (fun _ _ h ↦ f' _ _ h) i (g i x) :=
lift_of _ _ _ _ _
variable [Nonempty ι]
@[simp] lemma map_id [IsDirected ι (· ≤ ·)] :
map (fun i ↦ RingHom.id _) (fun _ _ _ ↦ rfl) =
RingHom.id (DirectLimit G fun _ _ h ↦ f _ _ h) :=
DFunLike.ext _ _ fun x ↦ x.induction_on fun i g ↦ by simp
lemma map_comp [IsDirected ι (· ≤ ·)]
(g₁ : (i : ι) → G i →+* G' i) (g₂ : (i : ι) → G' i →+* G'' i)
(hg₁ : ∀ i j h, (g₁ j).comp (f i j h) = (f' i j h).comp (g₁ i))
(hg₂ : ∀ i j h, (g₂ j).comp (f' i j h) = (f'' i j h).comp (g₂ i)) :
((map g₂ hg₂).comp (map g₁ hg₁) :
DirectLimit G (fun _ _ h ↦ f _ _ h) →+* DirectLimit G'' fun _ _ h ↦ f'' _ _ h) =
(map (fun i ↦ (g₂ i).comp (g₁ i)) fun i j h ↦ by
rw [RingHom.comp_assoc, hg₁ i, ← RingHom.comp_assoc, hg₂ i, RingHom.comp_assoc] :
DirectLimit G (fun _ _ h ↦ f _ _ h) →+* DirectLimit G'' fun _ _ h ↦ f'' _ _ h) :=
DFunLike.ext _ _ fun x ↦ x.induction_on fun i g ↦ by simp
/--
Consider direct limits `lim G` and `lim G'` with direct system `f` and `f'` respectively, any
family of equivalences `eᵢ : Gᵢ ≅ G'ᵢ` such that `e ∘ f = f' ∘ e` induces an equivalence
`lim G ⟶ lim G'`.
-/
def congr [IsDirected ι (· ≤ ·)]
(e : (i : ι) → G i ≃+* G' i)
(he : ∀ i j h, (e j).toRingHom.comp (f i j h) = (f' i j h).comp (e i)) :
DirectLimit G (fun _ _ h ↦ f _ _ h) ≃+* DirectLimit G' fun _ _ h ↦ f' _ _ h :=
RingEquiv.ofHomInv
(map (e ·) he)
(map (fun i ↦ (e i).symm) fun i j h ↦ DFunLike.ext _ _ fun x ↦ by
have eq1 := DFunLike.congr_fun (he i j h) ((e i).symm x)
simp only [RingEquiv.toRingHom_eq_coe, RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply,
RingEquiv.apply_symm_apply] at eq1 ⊢
simp [← eq1, of_f])
(DFunLike.ext _ _ fun x ↦ x.induction_on <| by simp)
(DFunLike.ext _ _ fun x ↦ x.induction_on <| by simp)
lemma congr_apply_of [IsDirected ι (· ≤ ·)]
(e : (i : ι) → G i ≃+* G' i)
(he : ∀ i j h, (e j).toRingHom.comp (f i j h) = (f' i j h).comp (e i))
{i : ι} (g : G i) :
congr e he (of G _ i g) = of G' (fun _ _ h ↦ f' _ _ h) i (e i g) :=
map_apply_of _ he _
lemma congr_symm_apply_of [IsDirected ι (· ≤ ·)]
(e : (i : ι) → G i ≃+* G' i)
(he : ∀ i j h, (e j).toRingHom.comp (f i j h) = (f' i j h).comp (e i))
{i : ι} (g : G' i) :
(congr e he).symm (of G' _ i g) = of G (fun _ _ h ↦ f _ _ h) i ((e i).symm g) := by
simp only [congr, RingEquiv.ofHomInv_symm_apply, map_apply_of, RingHom.coe_coe]
end functorial
end DirectLimit
end
end Ring
namespace Field
variable [Nonempty ι] [IsDirected ι (· ≤ ·)] [∀ i, Field (G i)]
variable (f : ∀ i j, i ≤ j → G i → G j)
variable (f' : ∀ i j, i ≤ j → G i →+* G j)
namespace DirectLimit
instance nontrivial [DirectedSystem G fun i j h => f' i j h] :
Nontrivial (Ring.DirectLimit G fun i j h => f' i j h) :=
⟨⟨0, 1,
Nonempty.elim (by infer_instance) fun i : ι => by
change (0 : Ring.DirectLimit G fun i j h => f' i j h) ≠ 1
rw [← (Ring.DirectLimit.of _ _ _).map_one]
· intro H; rcases Ring.DirectLimit.of.zero_exact H.symm with ⟨j, hij, hf⟩
rw [(f' i j hij).map_one] at hf
exact one_ne_zero hf⟩⟩
theorem exists_inv {p : Ring.DirectLimit G f} : p ≠ 0 → ∃ y, p * y = 1 :=
Ring.DirectLimit.induction_on p fun i x H =>
⟨Ring.DirectLimit.of G f i x⁻¹, by
erw [← (Ring.DirectLimit.of _ _ _).map_mul,
mul_inv_cancel fun h : x = 0 => H <| by rw [h, (Ring.DirectLimit.of _ _ _).map_zero],
(Ring.DirectLimit.of _ _ _).map_one]⟩
section
open Classical in
/-- Noncomputable multiplicative inverse in a direct limit of fields. -/
noncomputable def inv (p : Ring.DirectLimit G f) : Ring.DirectLimit G f :=
if H : p = 0 then 0 else Classical.choose (DirectLimit.exists_inv G f H)
protected theorem mul_inv_cancel {p : Ring.DirectLimit G f} (hp : p ≠ 0) : p * inv G f p = 1 := by
rw [inv, dif_neg hp, Classical.choose_spec (DirectLimit.exists_inv G f hp)]
protected theorem inv_mul_cancel {p : Ring.DirectLimit G f} (hp : p ≠ 0) : inv G f p * p = 1 := by
rw [_root_.mul_comm, DirectLimit.mul_inv_cancel G f hp]
/-- Noncomputable field structure on the direct limit of fields.
See note [reducible non-instances]. -/
protected noncomputable abbrev field [DirectedSystem G fun i j h => f' i j h] :
Field (Ring.DirectLimit G fun i j h => f' i j h) where
-- This used to include the parent CommRing and Nontrivial instances,
-- but leaving them implicit avoids a very expensive (2-3 minutes!) eta expansion.
inv := inv G fun i j h => f' i j h
mul_inv_cancel := fun p => DirectLimit.mul_inv_cancel G fun i j h => f' i j h
inv_zero := dif_pos rfl
nnqsmul := _
qsmul := _
end
end DirectLimit
end Field
|
Algebra\DualNumber.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.TrivSqZeroExt
/-!
# Dual numbers
The dual numbers over `R` are of the form `a + bε`, where `a` and `b` are typically elements of a
commutative ring `R`, and `ε` is a symbol satisfying `ε^2 = 0` that commutes with every other
element. They are a special case of `TrivSqZeroExt R M` with `M = R`.
## Notation
In the `DualNumber` locale:
* `R[ε]` is a shorthand for `DualNumber R`
* `ε` is a shorthand for `DualNumber.eps`
## Main definitions
* `DualNumber`
* `DualNumber.eps`
* `DualNumber.lift`
## Implementation notes
Rather than duplicating the API of `TrivSqZeroExt`, this file reuses the functions there.
## References
* https://en.wikipedia.org/wiki/Dual_number
-/
variable {R A B : Type*}
/-- The type of dual numbers, numbers of the form $a + bε$ where $ε^2 = 0$.
`R[ε]` is notation for `DualNumber R`. -/
abbrev DualNumber (R : Type*) : Type _ :=
TrivSqZeroExt R R
/-- The unit element $ε$ that squares to zero, with notation `ε`. -/
def DualNumber.eps [Zero R] [One R] : DualNumber R :=
TrivSqZeroExt.inr 1
@[inherit_doc]
scoped[DualNumber] notation "ε" => DualNumber.eps
@[inherit_doc]
scoped[DualNumber] postfix:1024 "[ε]" => DualNumber
open DualNumber
namespace DualNumber
open TrivSqZeroExt
@[simp]
theorem fst_eps [Zero R] [One R] : fst ε = (0 : R) :=
fst_inr _ _
@[simp]
theorem snd_eps [Zero R] [One R] : snd ε = (1 : R) :=
snd_inr _ _
/-- A version of `TrivSqZeroExt.snd_mul` with `*` instead of `•`. -/
@[simp]
theorem snd_mul [Semiring R] (x y : R[ε]) : snd (x * y) = fst x * snd y + snd x * fst y :=
TrivSqZeroExt.snd_mul _ _
@[simp]
theorem eps_mul_eps [Semiring R] : (ε * ε : R[ε]) = 0 :=
inr_mul_inr _ _ _
@[simp]
theorem inv_eps [DivisionRing R] : (ε : R[ε])⁻¹ = 0 :=
TrivSqZeroExt.inv_inr 1
@[simp]
theorem inr_eq_smul_eps [MulZeroOneClass R] (r : R) : inr r = (r • ε : R[ε]) :=
ext (mul_zero r).symm (mul_one r).symm
/-- `ε` commutes with every element of the algebra. -/
theorem commute_eps_left [Semiring R] (x : DualNumber R) : Commute ε x := by
ext <;> simp
/-- `ε` commutes with every element of the algebra. -/
theorem commute_eps_right [Semiring R] (x : DualNumber R) : Commute x ε := (commute_eps_left x).symm
variable {A : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]
/-- For two `R`-algebra morphisms out of `A[ε]` to agree, it suffices for them to agree on the
elements of `A` and the `A`-multiples of `ε`. -/
@[ext 1100]
nonrec theorem algHom_ext' ⦃f g : A[ε] →ₐ[R] B⦄
(hinl : f.comp (inlAlgHom _ _ _) = g.comp (inlAlgHom _ _ _))
(hinr : f.toLinearMap ∘ₗ (LinearMap.toSpanSingleton A A[ε] ε).restrictScalars R =
g.toLinearMap ∘ₗ (LinearMap.toSpanSingleton A A[ε] ε).restrictScalars R) :
f = g :=
algHom_ext' hinl (by
ext a
show f (inr a) = g (inr a)
simpa only [inr_eq_smul_eps] using DFunLike.congr_fun hinr a)
/-- For two `R`-algebra morphisms out of `R[ε]` to agree, it suffices for them to agree on `ε`. -/
@[ext 1200]
nonrec theorem algHom_ext ⦃f g : R[ε] →ₐ[R] A⦄ (hε : f ε = g ε) : f = g := by
ext
dsimp
simp only [one_smul, hε]
/-- A universal property of the dual numbers, providing a unique `A[ε] →ₐ[R] B` for every map
`f : A →ₐ[R] B` and a choice of element `e : B` which squares to `0` and commutes with the range of
`f`.
This isomorphism is named to match the similar `Complex.lift`.
Note that when `f : R →ₐ[R] B := Algebra.ofId R B`, the commutativity assumption is automatic, and
we are free to choose any element `e : B`. -/
def lift :
{fe : (A →ₐ[R] B) × B // fe.2 * fe.2 = 0 ∧ ∀ a, Commute fe.2 (fe.1 a)} ≃ (A[ε] →ₐ[R] B) := by
refine Equiv.trans ?_ TrivSqZeroExt.liftEquiv
exact {
toFun := fun fe => ⟨
(fe.val.1, MulOpposite.op fe.val.2 • fe.val.1.toLinearMap),
fun x y => show (fe.val.1 x * fe.val.2) * (fe.val.1 y * fe.val.2) = 0 by
rw [(fe.prop.2 _).mul_mul_mul_comm, fe.prop.1, mul_zero],
fun r x => show fe.val.1 (r * x) * fe.val.2 = fe.val.1 r * (fe.val.1 x * fe.val.2) by
rw [map_mul, mul_assoc],
fun r x => show fe.val.1 (x * r) * fe.val.2 = (fe.val.1 x * fe.val.2) * fe.val.1 r by
rw [map_mul, (fe.prop.2 _).right_comm]⟩
invFun := fun fg => ⟨
(fg.val.1, fg.val.2 1),
fg.prop.1 _ _,
fun a => show fg.val.2 1 * fg.val.1 a = fg.val.1 a * fg.val.2 1 by
rw [← fg.prop.2.1, ← fg.prop.2.2, smul_eq_mul, op_smul_eq_mul, mul_one, one_mul]⟩
left_inv := fun fe => Subtype.ext <| Prod.ext rfl <|
show fe.val.1 1 * fe.val.2 = fe.val.2 by
rw [map_one, one_mul]
right_inv := fun fg => Subtype.ext <| Prod.ext rfl <| LinearMap.ext fun x =>
show fg.val.1 x * fg.val.2 1 = fg.val.2 x by
rw [← fg.prop.2.1, smul_eq_mul, mul_one] }
theorem lift_apply_apply (fe : {_fe : (A →ₐ[R] B) × B // _}) (a : A[ε]) :
lift fe a = fe.val.1 a.fst + fe.val.1 a.snd * fe.val.2 := rfl
@[simp] theorem coe_lift_symm_apply (F : A[ε] →ₐ[R] B) :
(lift.symm F).val = (F.comp (inlAlgHom _ _ _), F ε) := rfl
/-- When applied to `inl`, `DualNumber.lift` applies the map `f : A →ₐ[R] B`. -/
@[simp] theorem lift_apply_inl (fe : {fe : (A →ₐ[R] B) × B // _}) (a : A) :
lift fe (inl a : A[ε]) = fe.val.1 a := by
rw [lift_apply_apply, fst_inl, snd_inl, map_zero, zero_mul, add_zero]
/-- Scaling on the left is sent by `DualNumber.lift` to multiplication on the left -/
@[simp] theorem lift_smul (fe : {fe : (A →ₐ[R] B) × B // _}) (a : A) (ad : A[ε]) :
lift fe (a • ad) = fe.val.1 a * lift fe ad := by
rw [← inl_mul_eq_smul, map_mul, lift_apply_inl]
/-- Scaling on the right is sent by `DualNumber.lift` to multiplication on the right -/
@[simp] theorem lift_op_smul (fe : {fe : (A →ₐ[R] B) × B // _}) (a : A) (ad : A[ε]) :
lift fe (MulOpposite.op a • ad) = lift fe ad * fe.val.1 a := by
rw [← mul_inl_eq_op_smul, map_mul, lift_apply_inl]
/-- When applied to `ε`, `DualNumber.lift` produces the element of `B` that squares to 0. -/
@[simp] theorem lift_apply_eps
(fe : {fe : (A →ₐ[R] B) × B // fe.2 * fe.2 = 0 ∧ ∀ a, Commute fe.2 (fe.1 a)}) :
lift fe (ε : A[ε]) = fe.val.2 := by
simp only [lift_apply_apply, fst_eps, map_zero, snd_eps, map_one, one_mul, zero_add]
/-- Lifting `DualNumber.eps` itself gives the identity. -/
@[simp]
theorem lift_inlAlgHom_eps :
lift ⟨(inlAlgHom _ _ _, ε), eps_mul_eps, fun _ => commute_eps_left _⟩ = AlgHom.id R A[ε] :=
lift.apply_symm_apply <| AlgHom.id R A[ε]
/-- Show DualNumber with values x and y as an "x + y*ε" string -/
instance instRepr [Repr R] : Repr (DualNumber R) where
reprPrec f p :=
(if p > 65 then (Std.Format.bracket "(" · ")") else (·)) <|
reprPrec f.fst 65 ++ " + " ++ reprPrec f.snd 70 ++ "*ε"
end DualNumber
|
Algebra\DualQuaternion.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.Algebra.DualNumber
import Mathlib.Algebra.Quaternion
/-!
# Dual quaternions
Similar to the way that rotations in 3D space can be represented by quaternions of unit length,
rigid motions in 3D space can be represented by dual quaternions of unit length.
## Main results
* `Quaternion.dualNumberEquiv`: quaternions over dual numbers or dual
numbers over quaternions are equivalent constructions.
## References
* <https://en.wikipedia.org/wiki/Dual_quaternion>
-/
variable {R : Type*} [CommRing R]
namespace Quaternion
/-- The dual quaternions can be equivalently represented as a quaternion with dual coefficients,
or as a dual number with quaternion coefficients.
See also `Matrix.dualNumberEquiv` for a similar result. -/
def dualNumberEquiv : Quaternion (DualNumber R) ≃ₐ[R] DualNumber (Quaternion R) where
toFun q :=
(⟨q.re.fst, q.imI.fst, q.imJ.fst, q.imK.fst⟩, ⟨q.re.snd, q.imI.snd, q.imJ.snd, q.imK.snd⟩)
invFun d :=
⟨(d.fst.re, d.snd.re), (d.fst.imI, d.snd.imI), (d.fst.imJ, d.snd.imJ), (d.fst.imK, d.snd.imK)⟩
left_inv := fun ⟨⟨r, rε⟩, ⟨i, iε⟩, ⟨j, jε⟩, ⟨k, kε⟩⟩ => rfl
right_inv := fun ⟨⟨r, i, j, k⟩, ⟨rε, iε, jε, kε⟩⟩ => rfl
map_mul' := by
rintro ⟨⟨xr, xrε⟩, ⟨xi, xiε⟩, ⟨xj, xjε⟩, ⟨xk, xkε⟩⟩
rintro ⟨⟨yr, yrε⟩, ⟨yi, yiε⟩, ⟨yj, yjε⟩, ⟨yk, ykε⟩⟩
ext : 1
· rfl
· dsimp
congr 1 <;> simp <;> ring
map_add' := by
rintro ⟨⟨xr, xrε⟩, ⟨xi, xiε⟩, ⟨xj, xjε⟩, ⟨xk, xkε⟩⟩
rintro ⟨⟨yr, yrε⟩, ⟨yi, yiε⟩, ⟨yj, yjε⟩, ⟨yk, ykε⟩⟩
rfl
commutes' r := rfl
/-! Lemmas characterizing `Quaternion.dualNumberEquiv`. -/
-- `simps` can't work on `DualNumber` because it's not a structure
@[simp]
theorem re_fst_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).fst.re = q.re.fst :=
rfl
@[simp]
theorem imI_fst_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).fst.imI = q.imI.fst :=
rfl
@[simp]
theorem imJ_fst_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).fst.imJ = q.imJ.fst :=
rfl
@[simp]
theorem imK_fst_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).fst.imK = q.imK.fst :=
rfl
@[simp]
theorem re_snd_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).snd.re = q.re.snd :=
rfl
@[simp]
theorem imI_snd_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).snd.imI = q.imI.snd :=
rfl
@[simp]
theorem imJ_snd_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).snd.imJ = q.imJ.snd :=
rfl
@[simp]
theorem imK_snd_dualNumberEquiv (q : Quaternion (DualNumber R)) :
(dualNumberEquiv q).snd.imK = q.imK.snd :=
rfl
@[simp]
theorem fst_re_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).re.fst = d.fst.re :=
rfl
@[simp]
theorem fst_imI_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).imI.fst = d.fst.imI :=
rfl
@[simp]
theorem fst_imJ_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).imJ.fst = d.fst.imJ :=
rfl
@[simp]
theorem fst_imK_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).imK.fst = d.fst.imK :=
rfl
@[simp]
theorem snd_re_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).re.snd = d.snd.re :=
rfl
@[simp]
theorem snd_imI_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).imI.snd = d.snd.imI :=
rfl
@[simp]
theorem snd_imJ_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).imJ.snd = d.snd.imJ :=
rfl
@[simp]
theorem snd_imK_dualNumberEquiv_symm (d : DualNumber (Quaternion R)) :
(dualNumberEquiv.symm d).imK.snd = d.snd.imK :=
rfl
end Quaternion
|
Algebra\Exact.lean | /-
Copyright (c) 2023 Antoine Chambert-Loir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Chambert-Loir
-/
import Mathlib.Algebra.Module.Submodule.Range
import Mathlib.LinearAlgebra.Prod
import Mathlib.LinearAlgebra.Quotient
/-! # Exactness of a pair
* For two maps `f : M → N` and `g : N → P`, with `Zero P`,
`Function.Exact f g` says that `Set.range f = Set.preimage g {0}`
* For additive maps `f : M →+ N` and `g : N →+ P`,
`Exact f g` says that `range f = ker g`
* For linear maps `f : M →ₗ[R] N` and `g : N →ₗ[R] P`,
`Exact f g` says that `range f = ker g`
## TODO :
* generalize to `SemilinearMap`, even `SemilinearMapClass`
* add the multiplicative case (`Function.Exact` will become `Function.AddExact`?)
-/
variable {R M M' N N' P P' : Type*}
namespace Function
variable (f : M → N) (g : N → P) (g' : P → P')
/-- The maps `f` and `g` form an exact pair :
`g y = 0` iff `y` belongs to the image of `f` -/
def Exact [Zero P] : Prop := ∀ y, g y = 0 ↔ y ∈ Set.range f
variable {f g}
namespace Exact
lemma apply_apply_eq_zero [Zero P] (h : Exact f g) (x : M) :
g (f x) = 0 := (h _).mpr <| Set.mem_range_self _
lemma comp_eq_zero [Zero P] (h : Exact f g) : g.comp f = 0 :=
funext h.apply_apply_eq_zero
lemma of_comp_of_mem_range [Zero P] (h1 : g ∘ f = 0)
(h2 : ∀ x, g x = 0 → x ∈ Set.range f) : Exact f g :=
fun y => Iff.intro (h2 y) <|
Exists.rec ((forall_apply_eq_imp_iff (p := (g · = 0))).mpr (congrFun h1) y)
lemma comp_injective [Zero P] [Zero P'] (exact : Exact f g)
(inj : Function.Injective g') (h0 : g' 0 = 0) :
Exact f (g' ∘ g) := by
intro x
refine ⟨fun H => exact x |>.mp <| inj <| h0 ▸ H, ?_⟩
intro H
rw [Function.comp_apply, exact x |>.mpr H, h0]
lemma of_comp_eq_zero_of_ker_in_range [Zero P] (hc : g.comp f = 0)
(hr : ∀ y, g y = 0 → y ∈ Set.range f) :
Exact f g :=
fun y ↦ ⟨hr y, fun ⟨x, hx⟩ ↦ hx ▸ congrFun hc x⟩
end Exact
end Function
section AddMonoidHom
variable [AddGroup M] [AddGroup N] [AddGroup P] {f : M →+ N} {g : N →+ P}
namespace AddMonoidHom
open Function
lemma exact_iff :
Exact f g ↔ ker g = range f :=
Iff.symm SetLike.ext_iff
lemma exact_of_comp_eq_zero_of_ker_le_range
(h1 : g.comp f = 0) (h2 : ker g ≤ range f) : Exact f g :=
Exact.of_comp_of_mem_range (congrArg DFunLike.coe h1) h2
lemma exact_of_comp_of_mem_range
(h1 : g.comp f = 0) (h2 : ∀ x, g x = 0 → x ∈ range f) : Exact f g :=
exact_of_comp_eq_zero_of_ker_le_range h1 h2
end AddMonoidHom
namespace Function.Exact
open AddMonoidHom
lemma addMonoidHom_ker_eq (hfg : Exact f g) :
ker g = range f :=
SetLike.ext hfg
lemma addMonoidHom_comp_eq_zero (h : Exact f g) : g.comp f = 0 :=
DFunLike.coe_injective h.comp_eq_zero
section
variable {X₁ X₂ X₃ Y₁ Y₂ Y₃ : Type*} [AddCommMonoid X₁] [AddCommMonoid X₂] [AddCommMonoid X₃]
[AddCommMonoid Y₁] [AddCommMonoid Y₂] [AddCommMonoid Y₃]
(e₁ : X₁ ≃+ Y₁) (e₂ : X₂ ≃+ Y₂) (e₃ : X₃ ≃+ Y₃)
{f₁₂ : X₁ →+ X₂} {f₂₃ : X₂ →+ X₃} {g₁₂ : Y₁ →+ Y₂} {g₂₃ : Y₂ →+ Y₃}
lemma of_ladder_addEquiv_of_exact (comm₁₂ : g₁₂.comp e₁ = AddMonoidHom.comp e₂ f₁₂)
(comm₂₃ : g₂₃.comp e₂ = AddMonoidHom.comp e₃ f₂₃) (H : Exact f₁₂ f₂₃) : Exact g₁₂ g₂₃ := by
have h₁₂ := DFunLike.congr_fun comm₁₂
have h₂₃ := DFunLike.congr_fun comm₂₃
dsimp at h₁₂ h₂₃
apply of_comp_eq_zero_of_ker_in_range
· ext y₁
obtain ⟨x₁, rfl⟩ := e₁.surjective y₁
dsimp
rw [h₁₂, h₂₃, H.apply_apply_eq_zero, map_zero]
· intro y₂ hx₂
obtain ⟨x₂, rfl⟩ := e₂.surjective y₂
obtain ⟨x₁, rfl⟩ := (H x₂).1 (e₃.injective (by rw [← h₂₃, hx₂, map_zero]))
exact ⟨e₁ x₁, by rw [h₁₂]⟩
lemma of_ladder_addEquiv_of_exact' (comm₁₂ : g₁₂.comp e₁ = AddMonoidHom.comp e₂ f₁₂)
(comm₂₃ : g₂₃.comp e₂ = AddMonoidHom.comp e₃ f₂₃) (H : Exact g₁₂ g₂₃) : Exact f₁₂ f₂₃ := by
refine of_ladder_addEquiv_of_exact e₁.symm e₂.symm e₃.symm ?_ ?_ H
· ext y₁
obtain ⟨x₁, rfl⟩ := e₁.surjective y₁
apply e₂.injective
simpa using DFunLike.congr_fun comm₁₂.symm x₁
· ext y₂
obtain ⟨x₂, rfl⟩ := e₂.surjective y₂
apply e₃.injective
simpa using DFunLike.congr_fun comm₂₃.symm x₂
lemma iff_of_ladder_addEquiv (comm₁₂ : g₁₂.comp e₁ = AddMonoidHom.comp e₂ f₁₂)
(comm₂₃ : g₂₃.comp e₂ = AddMonoidHom.comp e₃ f₂₃) : Exact g₁₂ g₂₃ ↔ Exact f₁₂ f₂₃ := by
constructor
· exact of_ladder_addEquiv_of_exact' e₁ e₂ e₃ comm₁₂ comm₂₃
· exact of_ladder_addEquiv_of_exact e₁ e₂ e₃ comm₁₂ comm₂₃
end
end Function.Exact
end AddMonoidHom
section LinearMap
open Function
variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid N]
[AddCommMonoid N'] [AddCommMonoid P] [AddCommMonoid P'] [Module R M]
[Module R M'] [Module R N] [Module R N'] [Module R P] [Module R P']
variable {f : M →ₗ[R] N} {g : N →ₗ[R] P}
namespace LinearMap
lemma exact_iff :
Exact f g ↔ LinearMap.ker g = LinearMap.range f :=
Iff.symm SetLike.ext_iff
lemma exact_of_comp_eq_zero_of_ker_le_range
(h1 : g ∘ₗ f = 0) (h2 : ker g ≤ range f) : Exact f g :=
Exact.of_comp_of_mem_range (congrArg DFunLike.coe h1) h2
lemma exact_of_comp_of_mem_range
(h1 : g ∘ₗ f = 0) (h2 : ∀ x, g x = 0 → x ∈ range f) : Exact f g :=
exact_of_comp_eq_zero_of_ker_le_range h1 h2
variable {R M N P : Type*} [CommRing R]
[AddCommGroup M] [AddCommGroup N] [AddCommGroup P] [Module R M] [Module R N] [Module R P]
lemma exact_subtype_mkQ (Q : Submodule R N) :
Exact (Submodule.subtype Q) (Submodule.mkQ Q) := by
rw [exact_iff, Submodule.ker_mkQ, Submodule.range_subtype Q]
lemma exact_map_mkQ_range (f : M →ₗ[R] N) :
Exact f (Submodule.mkQ (range f)) :=
exact_iff.mpr <| Submodule.ker_mkQ _
lemma exact_subtype_ker_map (g : N →ₗ[R] P) :
Exact (Submodule.subtype (ker g)) g :=
exact_iff.mpr <| (Submodule.range_subtype _).symm
end LinearMap
variable (f g) in
lemma LinearEquiv.conj_exact_iff_exact (e : N ≃ₗ[R] N') :
Function.Exact (e ∘ₗ f) (g ∘ₗ (e.symm : N' →ₗ[R] N)) ↔ Exact f g := by
simp_rw [LinearMap.exact_iff, LinearMap.ker_comp, ← e.map_eq_comap, LinearMap.range_comp]
exact (Submodule.map_injective_of_injective e.injective).eq_iff
namespace Function
open LinearMap
lemma Exact.linearMap_ker_eq (hfg : Exact f g) : ker g = range f :=
SetLike.ext hfg
lemma Exact.linearMap_comp_eq_zero (h : Exact f g) : g.comp f = 0 :=
DFunLike.coe_injective h.comp_eq_zero
lemma Surjective.comp_exact_iff_exact {p : M' →ₗ[R] M} (h : Surjective p) :
Exact (f ∘ₗ p) g ↔ Exact f g :=
iff_of_eq <| forall_congr fun x =>
congrArg (g x = 0 ↔ x ∈ ·) (h.range_comp f)
lemma Injective.comp_exact_iff_exact {i : P →ₗ[R] P'} (h : Injective i) :
Exact f (i ∘ₗ g) ↔ Exact f g :=
forall_congr' fun _ => iff_congr (LinearMap.map_eq_zero_iff _ h) Iff.rfl
variable
{f₁₂ : M →ₗ[R] N} {f₂₃ : N →ₗ[R] P} {g₁₂ : M' →ₗ[R] N'}
{g₂₃ : N' →ₗ[R] P'} {e₁ : M ≃ₗ[R] M'} {e₂ : N ≃ₗ[R] N'} {e₃ : P ≃ₗ[R] P'}
lemma Exact.iff_of_ladder_linearEquiv
(h₁₂ : g₁₂ ∘ₗ e₁ = e₂ ∘ₗ f₁₂) (h₂₃ : g₂₃ ∘ₗ e₂ = e₃ ∘ₗ f₂₃) :
Exact g₁₂ g₂₃ ↔ Exact f₁₂ f₂₃ :=
iff_of_ladder_addEquiv e₁.toAddEquiv e₂.toAddEquiv e₃.toAddEquiv
(f₁₂ := f₁₂) (f₂₃ := f₂₃) (g₁₂ := g₁₂) (g₂₃ := g₂₃)
(congr_arg LinearMap.toAddMonoidHom h₁₂) (congr_arg LinearMap.toAddMonoidHom h₂₃)
lemma Exact.of_ladder_linearEquiv_of_exact
(h₁₂ : g₁₂ ∘ₗ e₁ = e₂ ∘ₗ f₁₂) (h₂₃ : g₂₃ ∘ₗ e₂ = e₃ ∘ₗ f₂₃)
(H : Exact f₁₂ f₂₃) : Exact g₁₂ g₂₃ := by
rwa [iff_of_ladder_linearEquiv h₁₂ h₂₃]
end Function
end LinearMap
namespace Function
section split
variable [Semiring R]
variable [AddCommGroup M] [AddCommGroup N] [AddCommGroup P] [Module R M] [Module R N] [Module R P]
variable {f : M →ₗ[R] N} {g : N →ₗ[R] P}
open LinearMap
/-- Given an exact sequence `0 → M → N → P`, giving a section `P → N` is equivalent to giving a
splitting `N ≃ M × P`. -/
noncomputable
def Exact.splitSurjectiveEquiv (h : Function.Exact f g) (hf : Function.Injective f) :
{ l // g ∘ₗ l = .id } ≃
{ e : N ≃ₗ[R] M × P // f = e.symm ∘ₗ inl R M P ∧ g = snd R M P ∘ₗ e } := by
refine
{ toFun := fun l ↦ ⟨(LinearEquiv.ofBijective (f ∘ₗ fst R M P + l.1 ∘ₗ snd R M P) ?_).symm, ?_⟩
invFun := fun e ↦ ⟨e.1.symm ∘ₗ inr R M P, ?_⟩
left_inv := ?_
right_inv := ?_ }
· have h₁ : ∀ x, g (l.1 x) = x := LinearMap.congr_fun l.2
have h₂ : ∀ x, g (f x) = 0 := congr_fun h.comp_eq_zero
constructor
· intros x y e
simp only [add_apply, coe_comp, comp_apply, fst_apply, snd_apply] at e
suffices x.2 = y.2 from Prod.ext (hf (by rwa [this, add_left_inj] at e)) this
simpa [h₁, h₂] using DFunLike.congr_arg g e
· intro x
obtain ⟨y, hy⟩ := (h (x - l.1 (g x))).mp (by simp [h₁, g.map_sub])
exact ⟨⟨y, g x⟩, by simp [hy]⟩
· have h₁ : ∀ x, g (l.1 x) = x := LinearMap.congr_fun l.2
have h₂ : ∀ x, g (f x) = 0 := congr_fun h.comp_eq_zero
constructor
· ext; simp
· rw [LinearEquiv.eq_comp_toLinearMap_symm]
ext <;> simp [h₁, h₂]
· rw [← LinearMap.comp_assoc, (LinearEquiv.eq_comp_toLinearMap_symm _ _).mp e.2.2]; rfl
· intro; ext; simp
· rintro ⟨e, rfl, rfl⟩
ext1
apply LinearEquiv.symm_bijective.injective
ext
apply e.injective
ext <;> simp
/-- Given an exact sequence `M → N → P → 0`, giving a retraction `N → M` is equivalent to giving a
splitting `N ≃ M × P`. -/
noncomputable
def Exact.splitInjectiveEquiv
{R M N P} [Semiring R] [AddCommGroup M] [AddCommGroup N]
[AddCommGroup P] [Module R M] [Module R N] [Module R P] {f : M →ₗ[R] N} {g : N →ₗ[R] P}
(h : Function.Exact f g) (hg : Function.Surjective g) :
{ l // l ∘ₗ f = .id } ≃
{ e : N ≃ₗ[R] M × P // f = e.symm ∘ₗ inl R M P ∧ g = snd R M P ∘ₗ e } := by
refine
{ toFun := fun l ↦ ⟨(LinearEquiv.ofBijective (l.1.prod g) ?_), ?_⟩
invFun := fun e ↦ ⟨fst R M P ∘ₗ e.1, ?_⟩
left_inv := ?_
right_inv := ?_ }
· have h₁ : ∀ x, l.1 (f x) = x := LinearMap.congr_fun l.2
have h₂ : ∀ x, g (f x) = 0 := congr_fun h.comp_eq_zero
constructor
· intros x y e
simp only [prod_apply, Pi.prod, Prod.mk.injEq] at e
obtain ⟨z, hz⟩ := (h (x - y)).mp (by simpa [sub_eq_zero] using e.2)
suffices z = 0 by rw [← sub_eq_zero, ← hz, this, map_zero]
rw [← h₁ z, hz, map_sub, e.1, sub_self]
· rintro ⟨x, y⟩
obtain ⟨y, rfl⟩ := hg y
refine ⟨f x + y - f (l.1 y), by ext <;> simp [h₁, h₂]⟩
· have h₁ : ∀ x, l.1 (f x) = x := LinearMap.congr_fun l.2
have h₂ : ∀ x, g (f x) = 0 := congr_fun h.comp_eq_zero
constructor
· rw [LinearEquiv.eq_toLinearMap_symm_comp]
ext <;> simp [h₁, h₂]
· ext; simp
· rw [LinearMap.comp_assoc, (LinearEquiv.eq_toLinearMap_symm_comp _ _).mp e.2.1]; rfl
· intro; ext; simp
· rintro ⟨e, rfl, rfl⟩
ext x <;> simp
theorem Exact.split_tfae' (h : Function.Exact f g) :
List.TFAE [
Function.Injective f ∧ ∃ l, g ∘ₗ l = LinearMap.id,
Function.Surjective g ∧ ∃ l, l ∘ₗ f = LinearMap.id,
∃ e : N ≃ₗ[R] M × P, f = e.symm ∘ₗ LinearMap.inl R M P ∧ g = LinearMap.snd R M P ∘ₗ e] := by
tfae_have 1 → 3
· rintro ⟨hf, l, hl⟩
exact ⟨_, (h.splitSurjectiveEquiv hf ⟨l, hl⟩).2⟩
tfae_have 2 → 3
· rintro ⟨hg, l, hl⟩
exact ⟨_, (h.splitInjectiveEquiv hg ⟨l, hl⟩).2⟩
tfae_have 3 → 1
· rintro ⟨e, e₁, e₂⟩
have : Function.Injective f := e₁ ▸ e.symm.injective.comp LinearMap.inl_injective
refine ⟨this, ⟨_, ((h.splitSurjectiveEquiv this).symm ⟨e, e₁, e₂⟩).2⟩⟩
tfae_have 3 → 2
· rintro ⟨e, e₁, e₂⟩
have : Function.Surjective g := e₂ ▸ Prod.snd_surjective.comp e.surjective
refine ⟨this, ⟨_, ((h.splitInjectiveEquiv this).symm ⟨e, e₁, e₂⟩).2⟩⟩
tfae_finish
/-- Equivalent characterizations of split exact sequences. Also known as the **Splitting lemma**. -/
theorem Exact.split_tfae
{R M N P} [Semiring R] [AddCommGroup M] [AddCommGroup N]
[AddCommGroup P] [Module R M] [Module R N] [Module R P] {f : M →ₗ[R] N} {g : N →ₗ[R] P}
(h : Function.Exact f g) (hf : Function.Injective f) (hg : Function.Surjective g) :
List.TFAE [
∃ l, g ∘ₗ l = LinearMap.id,
∃ l, l ∘ₗ f = LinearMap.id,
∃ e : N ≃ₗ[R] M × P, f = e.symm ∘ₗ LinearMap.inl R M P ∧ g = LinearMap.snd R M P ∘ₗ e] := by
tfae_have 1 ↔ 3
· simpa using (h.splitSurjectiveEquiv hf).nonempty_congr
tfae_have 2 ↔ 3
· simpa using (h.splitInjectiveEquiv hg).nonempty_congr
tfae_finish
end split
section Prod
variable [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N]
lemma Exact.inr_fst : Function.Exact (LinearMap.inr R M N) (LinearMap.fst R M N) := by
rintro ⟨x, y⟩
simp only [LinearMap.fst_apply, @eq_comm _ x, LinearMap.coe_inr, Set.mem_range, Prod.mk.injEq,
exists_eq_right]
lemma Exact.inl_snd : Function.Exact (LinearMap.inl R M N) (LinearMap.snd R M N) := by
rintro ⟨x, y⟩
simp only [LinearMap.snd_apply, @eq_comm _ y, LinearMap.coe_inl, Set.mem_range, Prod.mk.injEq,
exists_eq_left]
end Prod
section Ring
open LinearMap Submodule
variable [Ring R] [AddCommGroup M] [AddCommGroup N] [AddCommGroup P]
[Module R M] [Module R N] [Module R P]
/-- A necessary and sufficient condition for an exact sequence to descend to a quotient. -/
lemma Exact.exact_mapQ_iff {f : M →ₗ[R] N} {g : N →ₗ[R] P}
(hfg : Exact f g) {p q r} (hpq : p ≤ comap f q) (hqr : q ≤ comap g r) :
Exact (mapQ p q f hpq) (mapQ q r g hqr) ↔ range g ⊓ r ≤ map g q := by
rw [exact_iff, ← (comap_injective_of_surjective (mkQ_surjective _)).eq_iff]
dsimp only [mapQ]
rw [← ker_comp, range_liftQ, liftQ_mkQ, ker_comp, range_comp, comap_map_eq,
ker_mkQ, ker_mkQ, ← hfg.linearMap_ker_eq, sup_comm,
← LE.le.le_iff_eq (sup_le hqr (ker_le_comap g)),
← comap_map_eq, ← map_le_iff_le_comap, map_comap_eq]
end Ring
end Function
|
Algebra\Expr.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.Algebra.Group.ZeroOne
import Qq
/-! # Helpers to invoke functions involving algebra at tactic time
This file provides instances on `x y : Q($α)` such that `x + y = q($x + $y)`.
Porting note: This has been rewritten to use `Qq` instead of `Expr`.
-/
open Qq
/-- Produce a `One` instance for `Q($α)` such that `1 : Q($α)` is `q(1 : $α)`. -/
def Expr.instOne {u : Lean.Level} (α : Q(Type u)) (_ : Q(One $α)) : One Q($α) where
one := q(1 : $α)
/-- Produce a `Zero` instance for `Q($α)` such that `0 : Q($α)` is `q(0 : $α)`. -/
def Expr.instZero {u : Lean.Level} (α : Q(Type u)) (_ : Q(Zero $α)) : Zero Q($α) where
zero := q(0 : $α)
/-- Produce a `Mul` instance for `Q($α)` such that `x * y : Q($α)` is `q($x * $y)`. -/
def Expr.instMul {u : Lean.Level} (α : Q(Type u)) (_ : Q(Mul $α)) : Mul Q($α) where
mul x y := q($x * $y)
/-- Produce an `Add` instance for `Q($α)` such that `x + y : Q($α)` is `q($x + $y)`. -/
def Expr.instAdd {u : Lean.Level} (α : Q(Type u)) (_ : Q(Add $α)) : Add Q($α) where
add x y := q($x + $y)
|
Algebra\Free.lean | /-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.Control.Applicative
import Mathlib.Control.Traversable.Basic
import Mathlib.Data.List.Basic
import Mathlib.Logic.Equiv.Defs
import Mathlib.Tactic.AdaptationNote
/-!
# Free constructions
## Main definitions
* `FreeMagma α`: free magma (structure with binary operation without any axioms) over alphabet `α`,
defined inductively, with traversable instance and decidable equality.
* `MagmaAssocQuotient α`: quotient of a magma `α` by the associativity equivalence relation.
* `FreeSemigroup α`: free semigroup over alphabet `α`, defined as a structure with two fields
`head : α` and `tail : List α` (i.e. nonempty lists), with traversable instance and decidable
equality.
* `FreeMagmaAssocQuotientEquiv α`: isomorphism between `MagmaAssocQuotient (FreeMagma α)` and
`FreeSemigroup α`.
* `FreeMagma.lift`: the universal property of the free magma, expressing its adjointness.
-/
universe u v l
/-- Free nonabelian additive magma over a given alphabet. -/
inductive FreeAddMagma (α : Type u) : Type u
| of : α → FreeAddMagma α
| add : FreeAddMagma α → FreeAddMagma α → FreeAddMagma α
deriving DecidableEq
compile_inductive% FreeAddMagma
/-- Free magma over a given alphabet. -/
@[to_additive]
inductive FreeMagma (α : Type u) : Type u
| of : α → FreeMagma α
| mul : FreeMagma α → FreeMagma α → FreeMagma α
deriving DecidableEq
compile_inductive% FreeMagma
namespace FreeMagma
variable {α : Type u}
@[to_additive]
instance [Inhabited α] : Inhabited (FreeMagma α) := ⟨of default⟩
@[to_additive]
instance : Mul (FreeMagma α) := ⟨FreeMagma.mul⟩
-- Porting note: invalid attribute 'match_pattern', declaration is in an imported module
-- attribute [match_pattern] Mul.mul
@[to_additive (attr := simp)]
theorem mul_eq (x y : FreeMagma α) : mul x y = x * y := rfl
/- Porting note: these lemmas are autogenerated by the inductive definition and due to
the existence of mul_eq not in simp normal form -/
attribute [nolint simpNF] FreeAddMagma.add.sizeOf_spec
attribute [nolint simpNF] FreeMagma.mul.sizeOf_spec
attribute [nolint simpNF] FreeAddMagma.add.injEq
attribute [nolint simpNF] FreeMagma.mul.injEq
/-- Recursor for `FreeMagma` using `x * y` instead of `FreeMagma.mul x y`. -/
@[to_additive (attr := elab_as_elim, induction_eliminator)
"Recursor for `FreeAddMagma` using `x + y` instead of `FreeAddMagma.add x y`."]
def recOnMul {C : FreeMagma α → Sort l} (x) (ih1 : ∀ x, C (of x))
(ih2 : ∀ x y, C x → C y → C (x * y)) : C x :=
FreeMagma.recOn x ih1 ih2
@[to_additive (attr := ext 1100)]
theorem hom_ext {β : Type v} [Mul β] {f g : FreeMagma α →ₙ* β} (h : f ∘ of = g ∘ of) : f = g :=
(DFunLike.ext _ _) fun x ↦ recOnMul x (congr_fun h) <| by intros; simp only [map_mul, *]
end FreeMagma
#adaptation_note /-- around nightly-2024-02-25, we need to write `mul x y` in the second pattern,
instead of `x * y`. --/
/-- Lifts a function `α → β` to a magma homomorphism `FreeMagma α → β` given a magma `β`. -/
def FreeMagma.liftAux {α : Type u} {β : Type v} [Mul β] (f : α → β) : FreeMagma α → β
| FreeMagma.of x => f x
| mul x y => liftAux f x * liftAux f y
/-- Lifts a function `α → β` to an additive magma homomorphism `FreeAddMagma α → β` given
an additive magma `β`. -/
def FreeAddMagma.liftAux {α : Type u} {β : Type v} [Add β] (f : α → β) : FreeAddMagma α → β
| FreeAddMagma.of x => f x
| x + y => liftAux f x + liftAux f y
attribute [to_additive existing] FreeMagma.liftAux
namespace FreeMagma
section lift
variable {α : Type u} {β : Type v} [Mul β] (f : α → β)
/-- The universal property of the free magma expressing its adjointness. -/
@[to_additive (attr := simps symm_apply)
"The universal property of the free additive magma expressing its adjointness."]
def lift : (α → β) ≃ (FreeMagma α →ₙ* β) where
toFun f :=
{ toFun := liftAux f
map_mul' := fun x y ↦ rfl }
invFun F := F ∘ of
left_inv f := rfl
right_inv F := by ext; rfl
@[to_additive (attr := simp)]
theorem lift_of (x) : lift f (of x) = f x := rfl
@[to_additive (attr := simp)]
theorem lift_comp_of : lift f ∘ of = f := rfl
@[to_additive (attr := simp)]
theorem lift_comp_of' (f : FreeMagma α →ₙ* β) : lift (f ∘ of) = f := lift.apply_symm_apply f
end lift
section Map
variable {α : Type u} {β : Type v} (f : α → β)
/-- The unique magma homomorphism `FreeMagma α →ₙ* FreeMagma β` that sends
each `of x` to `of (f x)`. -/
@[to_additive "The unique additive magma homomorphism `FreeAddMagma α → FreeAddMagma β` that sends
each `of x` to `of (f x)`."]
def map (f : α → β) : FreeMagma α →ₙ* FreeMagma β := lift (of ∘ f)
@[to_additive (attr := simp)]
theorem map_of (x) : map f (of x) = of (f x) := rfl
end Map
section Category
variable {α β : Type u}
@[to_additive]
instance : Monad FreeMagma where
pure := of
bind x f := lift f x
/-- Recursor on `FreeMagma` using `pure` instead of `of`. -/
@[to_additive (attr := elab_as_elim) "Recursor on `FreeAddMagma` using `pure` instead of `of`."]
protected def recOnPure {C : FreeMagma α → Sort l} (x) (ih1 : ∀ x, C (pure x))
(ih2 : ∀ x y, C x → C y → C (x * y)) : C x :=
FreeMagma.recOnMul x ih1 ih2
@[to_additive (attr := simp)]
theorem map_pure (f : α → β) (x) : (f <$> pure x : FreeMagma β) = pure (f x) := rfl
@[to_additive (attr := simp)]
theorem map_mul' (f : α → β) (x y : FreeMagma α) : f <$> (x * y) = f <$> x * f <$> y := rfl
@[to_additive (attr := simp)]
theorem pure_bind (f : α → FreeMagma β) (x) : pure x >>= f = f x := rfl
@[to_additive (attr := simp)]
theorem mul_bind (f : α → FreeMagma β) (x y : FreeMagma α) : x * y >>= f = (x >>= f) * (y >>= f) :=
rfl
@[to_additive (attr := simp)]
theorem pure_seq {α β : Type u} {f : α → β} {x : FreeMagma α} : pure f <*> x = f <$> x := rfl
@[to_additive (attr := simp)]
theorem mul_seq {α β : Type u} {f g : FreeMagma (α → β)} {x : FreeMagma α} :
f * g <*> x = (f <*> x) * (g <*> x) := rfl
@[to_additive]
instance instLawfulMonad : LawfulMonad FreeMagma.{u} := LawfulMonad.mk'
(pure_bind := fun f x ↦ rfl)
(bind_assoc := fun x f g ↦ FreeMagma.recOnPure x (fun x ↦ rfl) fun x y ih1 ih2 ↦ by
rw [mul_bind, mul_bind, mul_bind, ih1, ih2])
(id_map := fun x ↦ FreeMagma.recOnPure x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by
rw [map_mul', ih1, ih2])
end Category
end FreeMagma
#adaptation_note /-- around nightly-2024-02-25, we need to write `mul x y` in the second pattern,
instead of `x * y`. -/
/-- `FreeMagma` is traversable. -/
protected def FreeMagma.traverse {m : Type u → Type u} [Applicative m] {α β : Type u}
(F : α → m β) : FreeMagma α → m (FreeMagma β)
| FreeMagma.of x => FreeMagma.of <$> F x
| mul x y => (· * ·) <$> x.traverse F <*> y.traverse F
/-- `FreeAddMagma` is traversable. -/
protected def FreeAddMagma.traverse {m : Type u → Type u} [Applicative m] {α β : Type u}
(F : α → m β) : FreeAddMagma α → m (FreeAddMagma β)
| FreeAddMagma.of x => FreeAddMagma.of <$> F x
| x + y => (· + ·) <$> x.traverse F <*> y.traverse F
attribute [to_additive existing] FreeMagma.traverse
namespace FreeMagma
variable {α : Type u}
section Category
variable {β : Type u}
@[to_additive]
instance : Traversable FreeMagma := ⟨@FreeMagma.traverse⟩
variable {m : Type u → Type u} [Applicative m] (F : α → m β)
@[to_additive (attr := simp)]
theorem traverse_pure (x) : traverse F (pure x : FreeMagma α) = pure <$> F x := rfl
@[to_additive (attr := simp)]
theorem traverse_pure' : traverse F ∘ pure = fun x ↦ (pure <$> F x : m (FreeMagma β)) := rfl
@[to_additive (attr := simp)]
theorem traverse_mul (x y : FreeMagma α) :
traverse F (x * y) = (· * ·) <$> traverse F x <*> traverse F y := rfl
@[to_additive (attr := simp)]
theorem traverse_mul' :
Function.comp (traverse F) ∘ (HMul.hMul : FreeMagma α → FreeMagma α → FreeMagma α) = fun x y ↦
(· * ·) <$> traverse F x <*> traverse F y := rfl
@[to_additive (attr := simp)]
theorem traverse_eq (x) : FreeMagma.traverse F x = traverse F x := rfl
-- Porting note (#10675): dsimp can not prove this
@[to_additive (attr := simp, nolint simpNF)]
theorem mul_map_seq (x y : FreeMagma α) :
((· * ·) <$> x <*> y : Id (FreeMagma α)) = (x * y : FreeMagma α) := rfl
@[to_additive]
instance : LawfulTraversable FreeMagma.{u} :=
{ instLawfulMonad with
id_traverse := fun x ↦
FreeMagma.recOnPure x (fun x ↦ rfl) fun x y ih1 ih2 ↦ by
rw [traverse_mul, ih1, ih2, mul_map_seq]
comp_traverse := fun f g x ↦
FreeMagma.recOnPure x
(fun x ↦ by simp only [(· ∘ ·), traverse_pure, traverse_pure', functor_norm])
(fun x y ih1 ih2 ↦ by
rw [traverse_mul, ih1, ih2, traverse_mul]
simp [Functor.Comp.map_mk, Functor.map_map, (· ∘ ·), Comp.seq_mk, seq_map_assoc,
map_seq, traverse_mul])
naturality := fun η α β f x ↦
FreeMagma.recOnPure x
(fun x ↦ by simp only [traverse_pure, functor_norm, Function.comp_apply])
(fun x y ih1 ih2 ↦ by simp only [traverse_mul, functor_norm, ih1, ih2])
traverse_eq_map_id := fun f x ↦
FreeMagma.recOnPure x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by
rw [traverse_mul, ih1, ih2, map_mul', mul_map_seq]; rfl }
end Category
end FreeMagma
-- Porting note: changed String to Lean.Format
#adaptation_note /-- around nightly-2024-02-25, we need to write `mul x y` in the second pattern,
instead of `x * y`. -/
/-- Representation of an element of a free magma. -/
protected def FreeMagma.repr {α : Type u} [Repr α] : FreeMagma α → Lean.Format
| FreeMagma.of x => repr x
| mul x y => "( " ++ x.repr ++ " * " ++ y.repr ++ " )"
/-- Representation of an element of a free additive magma. -/
protected def FreeAddMagma.repr {α : Type u} [Repr α] : FreeAddMagma α → Lean.Format
| FreeAddMagma.of x => repr x
| x + y => "( " ++ x.repr ++ " + " ++ y.repr ++ " )"
attribute [to_additive existing] FreeMagma.repr
@[to_additive]
instance {α : Type u} [Repr α] : Repr (FreeMagma α) := ⟨fun o _ => FreeMagma.repr o⟩
#adaptation_note /-- around nightly-2024-02-25, we need to write `mul x y` in the second pattern,
instead of `x * y`. -/
/-- Length of an element of a free magma. -/
def FreeMagma.length {α : Type u} : FreeMagma α → ℕ
| FreeMagma.of _x => 1
| mul x y => x.length + y.length
/-- Length of an element of a free additive magma. -/
def FreeAddMagma.length {α : Type u} : FreeAddMagma α → ℕ
| FreeAddMagma.of _x => 1
| x + y => x.length + y.length
attribute [to_additive existing (attr := simp)] FreeMagma.length
/-- The length of an element of a free magma is positive. -/
@[to_additive "The length of an element of a free additive magma is positive."]
lemma FreeMagma.length_pos {α : Type u} (x : FreeMagma α) : 0 < x.length :=
match x with
| FreeMagma.of _ => Nat.succ_pos 0
| mul y z => Nat.add_pos_left (length_pos y) z.length
/-- Associativity relations for an additive magma. -/
inductive AddMagma.AssocRel (α : Type u) [Add α] : α → α → Prop
| intro : ∀ x y z, AddMagma.AssocRel α (x + y + z) (x + (y + z))
| left : ∀ w x y z, AddMagma.AssocRel α (w + (x + y + z)) (w + (x + (y + z)))
/-- Associativity relations for a magma. -/
@[to_additive AddMagma.AssocRel "Associativity relations for an additive magma."]
inductive Magma.AssocRel (α : Type u) [Mul α] : α → α → Prop
| intro : ∀ x y z, Magma.AssocRel α (x * y * z) (x * (y * z))
| left : ∀ w x y z, Magma.AssocRel α (w * (x * y * z)) (w * (x * (y * z)))
namespace Magma
/-- Semigroup quotient of a magma. -/
@[to_additive AddMagma.FreeAddSemigroup "Additive semigroup quotient of an additive magma."]
def AssocQuotient (α : Type u) [Mul α] : Type u :=
Quot <| AssocRel α
namespace AssocQuotient
variable {α : Type u} [Mul α]
@[to_additive]
theorem quot_mk_assoc (x y z : α) : Quot.mk (AssocRel α) (x * y * z) = Quot.mk _ (x * (y * z)) :=
Quot.sound (AssocRel.intro _ _ _)
@[to_additive]
theorem quot_mk_assoc_left (x y z w : α) :
Quot.mk (AssocRel α) (x * (y * z * w)) = Quot.mk _ (x * (y * (z * w))) :=
Quot.sound (AssocRel.left _ _ _ _)
@[to_additive]
instance : Semigroup (AssocQuotient α) where
mul x y := by
refine Quot.liftOn₂ x y (fun x y ↦ Quot.mk _ (x * y)) ?_ ?_
· rintro a b₁ b₂ (⟨c, d, e⟩ | ⟨c, d, e, f⟩) <;> simp only
· exact quot_mk_assoc_left _ _ _ _
· rw [← quot_mk_assoc, quot_mk_assoc_left, quot_mk_assoc]
· rintro a₁ a₂ b (⟨c, d, e⟩ | ⟨c, d, e, f⟩) <;> simp only
· simp only [quot_mk_assoc, quot_mk_assoc_left]
· rw [quot_mk_assoc, quot_mk_assoc, quot_mk_assoc_left, quot_mk_assoc_left,
quot_mk_assoc_left, ← quot_mk_assoc c d, ← quot_mk_assoc c d, quot_mk_assoc_left]
mul_assoc x y z :=
Quot.induction_on₃ x y z fun a b c ↦ quot_mk_assoc a b c
/-- Embedding from magma to its free semigroup. -/
@[to_additive "Embedding from additive magma to its free additive semigroup."]
def of : α →ₙ* AssocQuotient α where toFun := Quot.mk _; map_mul' _x _y := rfl
@[to_additive]
instance [Inhabited α] : Inhabited (AssocQuotient α) := ⟨of default⟩
@[to_additive (attr := elab_as_elim, induction_eliminator)]
protected theorem induction_on {C : AssocQuotient α → Prop} (x : AssocQuotient α)
(ih : ∀ x, C (of x)) : C x := Quot.induction_on x ih
section lift
variable {β : Type v} [Semigroup β] (f : α →ₙ* β)
@[to_additive (attr := ext 1100)]
theorem hom_ext {f g : AssocQuotient α →ₙ* β} (h : f.comp of = g.comp of) : f = g :=
(DFunLike.ext _ _) fun x => AssocQuotient.induction_on x <| DFunLike.congr_fun h
/-- Lifts a magma homomorphism `α → β` to a semigroup homomorphism `Magma.AssocQuotient α → β`
given a semigroup `β`. -/
@[to_additive (attr := simps symm_apply) "Lifts an additive magma homomorphism `α → β` to an
additive semigroup homomorphism `AddMagma.AssocQuotient α → β` given an additive semigroup `β`."]
def lift : (α →ₙ* β) ≃ (AssocQuotient α →ₙ* β) where
toFun f :=
{ toFun := fun x ↦
Quot.liftOn x f <| by rintro a b (⟨c, d, e⟩ | ⟨c, d, e, f⟩) <;> simp only [map_mul, mul_assoc]
map_mul' := fun x y ↦ Quot.induction_on₂ x y (map_mul f) }
invFun f := f.comp of
left_inv f := (DFunLike.ext _ _) fun x ↦ rfl
right_inv f := hom_ext <| (DFunLike.ext _ _) fun x ↦ rfl
@[to_additive (attr := simp)]
theorem lift_of (x : α) : lift f (of x) = f x := rfl
@[to_additive (attr := simp)]
theorem lift_comp_of : (lift f).comp of = f := lift.symm_apply_apply f
@[to_additive (attr := simp)]
theorem lift_comp_of' (f : AssocQuotient α →ₙ* β) : lift (f.comp of) = f := lift.apply_symm_apply f
end lift
variable {β : Type v} [Mul β] (f : α →ₙ* β)
/-- From a magma homomorphism `α →ₙ* β` to a semigroup homomorphism
`Magma.AssocQuotient α →ₙ* Magma.AssocQuotient β`. -/
@[to_additive "From an additive magma homomorphism `α → β` to an additive semigroup homomorphism
`AddMagma.AssocQuotient α → AddMagma.AssocQuotient β`."]
def map : AssocQuotient α →ₙ* AssocQuotient β := lift (of.comp f)
@[to_additive (attr := simp)]
theorem map_of (x) : map f (of x) = of (f x) := rfl
end AssocQuotient
end Magma
/-- Free additive semigroup over a given alphabet. -/
structure FreeAddSemigroup (α : Type u) where
/-- The head of the element -/
head : α
/-- The tail of the element -/
tail : List α
compile_inductive% FreeAddSemigroup
/-- Free semigroup over a given alphabet. -/
@[to_additive (attr := ext)]
structure FreeSemigroup (α : Type u) where
/-- The head of the element -/
head : α
/-- The tail of the element -/
tail : List α
compile_inductive% FreeSemigroup
namespace FreeSemigroup
variable {α : Type u}
@[to_additive]
instance : Semigroup (FreeSemigroup α) where
mul L1 L2 := ⟨L1.1, L1.2 ++ L2.1 :: L2.2⟩
mul_assoc _L1 _L2 _L3 := FreeSemigroup.ext rfl <| List.append_assoc _ _ _
@[to_additive (attr := simp)]
theorem head_mul (x y : FreeSemigroup α) : (x * y).1 = x.1 := rfl
@[to_additive (attr := simp)]
theorem tail_mul (x y : FreeSemigroup α) : (x * y).2 = x.2 ++ y.1 :: y.2 := rfl
@[to_additive (attr := simp)]
theorem mk_mul_mk (x y : α) (L1 L2 : List α) : mk x L1 * mk y L2 = mk x (L1 ++ y :: L2) := rfl
/-- The embedding `α → FreeSemigroup α`. -/
@[to_additive (attr := simps) "The embedding `α → FreeAddSemigroup α`."]
def of (x : α) : FreeSemigroup α := ⟨x, []⟩
/-- Length of an element of free semigroup. -/
@[to_additive "Length of an element of free additive semigroup"]
def length (x : FreeSemigroup α) : ℕ := x.tail.length + 1
@[to_additive (attr := simp)]
theorem length_mul (x y : FreeSemigroup α) : (x * y).length = x.length + y.length := by
simp [length, Nat.add_right_comm, List.length, List.length_append]
@[to_additive (attr := simp)]
theorem length_of (x : α) : (of x).length = 1 := rfl
@[to_additive]
instance [Inhabited α] : Inhabited (FreeSemigroup α) := ⟨of default⟩
/-- Recursor for free semigroup using `of` and `*`. -/
@[to_additive (attr := elab_as_elim, induction_eliminator)
"Recursor for free additive semigroup using `of` and `+`."]
protected def recOnMul {C : FreeSemigroup α → Sort l} (x) (ih1 : ∀ x, C (of x))
(ih2 : ∀ x y, C (of x) → C y → C (of x * y)) : C x :=
FreeSemigroup.recOn x fun f s ↦
List.recOn s ih1 (fun hd tl ih f ↦ ih2 f ⟨hd, tl⟩ (ih1 f) (ih hd)) f
@[to_additive (attr := ext 1100)]
theorem hom_ext {β : Type v} [Mul β] {f g : FreeSemigroup α →ₙ* β} (h : f ∘ of = g ∘ of) : f = g :=
(DFunLike.ext _ _) fun x ↦
FreeSemigroup.recOnMul x (congr_fun h) fun x y hx hy ↦ by simp only [map_mul, *]
section lift
variable {β : Type v} [Semigroup β] (f : α → β)
/-- Lifts a function `α → β` to a semigroup homomorphism `FreeSemigroup α → β` given
a semigroup `β`. -/
@[to_additive (attr := simps symm_apply) "Lifts a function `α → β` to an additive semigroup
homomorphism `FreeAddSemigroup α → β` given an additive semigroup `β`."]
def lift : (α → β) ≃ (FreeSemigroup α →ₙ* β) where
toFun f :=
{ toFun := fun x ↦ x.2.foldl (fun a b ↦ a * f b) (f x.1)
map_mul' := fun x y ↦ by
simp [head_mul, tail_mul, ← List.foldl_map, List.foldl_append, List.foldl_cons,
List.foldl_assoc] }
invFun f := f ∘ of
left_inv f := rfl
right_inv f := hom_ext rfl
@[to_additive (attr := simp)]
theorem lift_of (x : α) : lift f (of x) = f x := rfl
@[to_additive (attr := simp)]
theorem lift_comp_of : lift f ∘ of = f := rfl
@[to_additive (attr := simp)]
theorem lift_comp_of' (f : FreeSemigroup α →ₙ* β) : lift (f ∘ of) = f := hom_ext rfl
@[to_additive]
theorem lift_of_mul (x y) : lift f (of x * y) = f x * lift f y := by rw [map_mul, lift_of]
end lift
section Map
variable {β : Type v} (f : α → β)
/-- The unique semigroup homomorphism that sends `of x` to `of (f x)`. -/
@[to_additive "The unique additive semigroup homomorphism that sends `of x` to `of (f x)`."]
def map : FreeSemigroup α →ₙ* FreeSemigroup β :=
lift <| of ∘ f
@[to_additive (attr := simp)]
theorem map_of (x) : map f (of x) = of (f x) := rfl
@[to_additive (attr := simp)]
theorem length_map (x) : (map f x).length = x.length :=
FreeSemigroup.recOnMul x (fun x ↦ rfl) (fun x y hx hy ↦ by simp only [map_mul, length_mul, *])
end Map
section Category
variable {β : Type u}
@[to_additive]
instance : Monad FreeSemigroup where
pure := of
bind x f := lift f x
/-- Recursor that uses `pure` instead of `of`. -/
@[to_additive (attr := elab_as_elim) "Recursor that uses `pure` instead of `of`."]
def recOnPure {C : FreeSemigroup α → Sort l} (x) (ih1 : ∀ x, C (pure x))
(ih2 : ∀ x y, C (pure x) → C y → C (pure x * y)) : C x :=
FreeSemigroup.recOnMul x ih1 ih2
@[to_additive (attr := simp)]
theorem map_pure (f : α → β) (x) : (f <$> pure x : FreeSemigroup β) = pure (f x) := rfl
@[to_additive (attr := simp)]
theorem map_mul' (f : α → β) (x y : FreeSemigroup α) : f <$> (x * y) = f <$> x * f <$> y :=
map_mul (map f) _ _
@[to_additive (attr := simp)]
theorem pure_bind (f : α → FreeSemigroup β) (x) : pure x >>= f = f x := rfl
@[to_additive (attr := simp)]
theorem mul_bind (f : α → FreeSemigroup β) (x y : FreeSemigroup α) :
x * y >>= f = (x >>= f) * (y >>= f) := map_mul (lift f) _ _
@[to_additive (attr := simp)]
theorem pure_seq {f : α → β} {x : FreeSemigroup α} : pure f <*> x = f <$> x := rfl
@[to_additive (attr := simp)]
theorem mul_seq {f g : FreeSemigroup (α → β)} {x : FreeSemigroup α} :
f * g <*> x = (f <*> x) * (g <*> x) := mul_bind _ _ _
@[to_additive]
instance instLawfulMonad : LawfulMonad FreeSemigroup.{u} := LawfulMonad.mk'
(pure_bind := fun _ _ ↦ rfl)
(bind_assoc := fun x g f ↦
recOnPure x (fun x ↦ rfl) fun x y ih1 ih2 ↦ by rw [mul_bind, mul_bind, mul_bind, ih1, ih2])
(id_map := fun x ↦ recOnPure x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by rw [map_mul', ih1, ih2])
/-- `FreeSemigroup` is traversable. -/
@[to_additive "`FreeAddSemigroup` is traversable."]
protected def traverse {m : Type u → Type u} [Applicative m] {α β : Type u}
(F : α → m β) (x : FreeSemigroup α) : m (FreeSemigroup β) :=
recOnPure x (fun x ↦ pure <$> F x) fun _x _y ihx ihy ↦ (· * ·) <$> ihx <*> ihy
@[to_additive]
instance : Traversable FreeSemigroup := ⟨@FreeSemigroup.traverse⟩
variable {m : Type u → Type u} [Applicative m] (F : α → m β)
@[to_additive (attr := simp)]
theorem traverse_pure (x) : traverse F (pure x : FreeSemigroup α) = pure <$> F x := rfl
@[to_additive (attr := simp)]
theorem traverse_pure' : traverse F ∘ pure = fun x ↦ (pure <$> F x : m (FreeSemigroup β)) := rfl
section
variable [LawfulApplicative m]
@[to_additive (attr := simp)]
theorem traverse_mul (x y : FreeSemigroup α) :
traverse F (x * y) = (· * ·) <$> traverse F x <*> traverse F y :=
let ⟨x, L1⟩ := x
let ⟨y, L2⟩ := y
List.recOn L1 (fun x ↦ rfl)
(fun hd tl ih x ↦ show
(· * ·) <$> pure <$> F x <*> traverse F (mk hd tl * mk y L2) =
(· * ·) <$> ((· * ·) <$> pure <$> F x <*> traverse F (mk hd tl)) <*> traverse F (mk y L2)
by rw [ih]; simp only [(· ∘ ·), (mul_assoc _ _ _).symm, functor_norm])
x
@[to_additive (attr := simp)]
theorem traverse_mul' :
Function.comp (traverse F) ∘ (HMul.hMul : FreeSemigroup α → FreeSemigroup α → FreeSemigroup α) =
fun x y ↦ (· * ·) <$> traverse F x <*> traverse F y :=
funext fun x ↦ funext fun y ↦ traverse_mul F x y
end
@[to_additive (attr := simp)]
theorem traverse_eq (x) : FreeSemigroup.traverse F x = traverse F x := rfl
-- Porting note (#10675): dsimp can not prove this
@[to_additive (attr := simp, nolint simpNF)]
theorem mul_map_seq (x y : FreeSemigroup α) :
((· * ·) <$> x <*> y : Id (FreeSemigroup α)) = (x * y : FreeSemigroup α) := rfl
@[to_additive]
instance : LawfulTraversable FreeSemigroup.{u} :=
{ instLawfulMonad with
id_traverse := fun x ↦
FreeSemigroup.recOnMul x (fun x ↦ rfl) fun x y ih1 ih2 ↦ by
rw [traverse_mul, ih1, ih2, mul_map_seq]
comp_traverse := fun f g x ↦
recOnPure x (fun x ↦ by simp only [traverse_pure, functor_norm, (· ∘ ·)])
fun x y ih1 ih2 ↦ by (rw [traverse_mul, ih1, ih2,
traverse_mul, Functor.Comp.map_mk]; simp only [Function.comp, functor_norm, traverse_mul])
naturality := fun η α β f x ↦
recOnPure x (fun x ↦ by simp only [traverse_pure, functor_norm, Function.comp])
(fun x y ih1 ih2 ↦ by simp only [traverse_mul, functor_norm, ih1, ih2])
traverse_eq_map_id := fun f x ↦
FreeSemigroup.recOnMul x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by
rw [traverse_mul, ih1, ih2, map_mul', mul_map_seq]; rfl }
end Category
@[to_additive]
instance [DecidableEq α] : DecidableEq (FreeSemigroup α) :=
fun _ _ ↦ decidable_of_iff' _ FreeSemigroup.ext_iff
end FreeSemigroup
namespace FreeMagma
variable {α : Type u} {β : Type v}
/-- The canonical multiplicative morphism from `FreeMagma α` to `FreeSemigroup α`. -/
@[to_additive "The canonical additive morphism from `FreeAddMagma α` to `FreeAddSemigroup α`."]
def toFreeSemigroup : FreeMagma α →ₙ* FreeSemigroup α := FreeMagma.lift FreeSemigroup.of
@[to_additive (attr := simp)]
theorem toFreeSemigroup_of (x : α) : toFreeSemigroup (of x) = FreeSemigroup.of x := rfl
@[to_additive (attr := simp)]
theorem toFreeSemigroup_comp_of : @toFreeSemigroup α ∘ of = FreeSemigroup.of := rfl
@[to_additive]
theorem toFreeSemigroup_comp_map (f : α → β) :
toFreeSemigroup.comp (map f) = (FreeSemigroup.map f).comp toFreeSemigroup := by ext1; rfl
@[to_additive]
theorem toFreeSemigroup_map (f : α → β) (x : FreeMagma α) :
toFreeSemigroup (map f x) = FreeSemigroup.map f (toFreeSemigroup x) :=
DFunLike.congr_fun (toFreeSemigroup_comp_map f) x
@[to_additive (attr := simp)]
theorem length_toFreeSemigroup (x : FreeMagma α) : (toFreeSemigroup x).length = x.length :=
FreeMagma.recOnMul x (fun x ↦ rfl) fun x y hx hy ↦ by
rw [map_mul, FreeSemigroup.length_mul, hx, hy]; rfl
end FreeMagma
/-- Isomorphism between `Magma.AssocQuotient (FreeMagma α)` and `FreeSemigroup α`. -/
@[to_additive "Isomorphism between `AddMagma.AssocQuotient (FreeAddMagma α)` and
`FreeAddSemigroup α`."]
def FreeMagmaAssocQuotientEquiv (α : Type u) :
Magma.AssocQuotient (FreeMagma α) ≃* FreeSemigroup α :=
(Magma.AssocQuotient.lift FreeMagma.toFreeSemigroup).toMulEquiv
(FreeSemigroup.lift (Magma.AssocQuotient.of ∘ FreeMagma.of))
(by ext; rfl)
(by ext1; rfl)
|
Algebra\FreeAlgebra.lean | /-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Adam Topaz, Eric Wieser
-/
import Mathlib.Algebra.Algebra.Subalgebra.Basic
import Mathlib.Algebra.Algebra.Tower
import Mathlib.Algebra.MonoidAlgebra.NoZeroDivisors
import Mathlib.RingTheory.Adjoin.Basic
/-!
# Free Algebras
Given a commutative semiring `R`, and a type `X`, we construct the free unital, associative
`R`-algebra on `X`.
## Notation
1. `FreeAlgebra R X` is the free algebra itself. It is endowed with an `R`-algebra structure.
2. `FreeAlgebra.ι R` is the function `X → FreeAlgebra R X`.
3. Given a function `f : X → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an
`R`-algebra morphism `FreeAlgebra R X → A`.
## Theorems
1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`.
2. `lift_unique` states that whenever an R-algebra morphism `g : FreeAlgebra R X → A` is
given whose composition with `ι R` is `f`, then one has `g = lift R f`.
3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem.
4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift
of the composition of an algebra morphism with `ι` is the algebra morphism itself.
5. `equivMonoidAlgebraFreeMonoid : FreeAlgebra R X ≃ₐ[R] MonoidAlgebra R (FreeMonoid X)`
6. An inductive principle `induction`.
## Implementation details
We construct the free algebra on `X` as a quotient of an inductive type `FreeAlgebra.Pre` by an
inductively defined relation `FreeAlgebra.Rel`. Explicitly, the construction involves three steps:
1. We construct an inductive type `FreeAlgebra.Pre R X`, the terms of which should be thought
of as representatives for the elements of `FreeAlgebra R X`.
It is the free type with maps from `R` and `X`, and with two binary operations `add` and `mul`.
2. We construct an inductive relation `FreeAlgebra.Rel R X` on `FreeAlgebra.Pre R X`.
This is the smallest relation for which the quotient is an `R`-algebra where addition resp.
multiplication are induced by `add` resp. `mul` from 1., and for which the map from `R` is the
structure map for the algebra.
3. The free algebra `FreeAlgebra R X` is the quotient of `FreeAlgebra.Pre R X` by
the relation `FreeAlgebra.Rel R X`.
-/
variable (R : Type*) [CommSemiring R]
variable (X : Type*)
namespace FreeAlgebra
/-- This inductive type is used to express representatives of the free algebra.
-/
inductive Pre
| of : X → Pre
| ofScalar : R → Pre
| add : Pre → Pre → Pre
| mul : Pre → Pre → Pre
namespace Pre
instance : Inhabited (Pre R X) := ⟨ofScalar 0⟩
-- Note: These instances are only used to simplify the notation.
/-- Coercion from `X` to `Pre R X`. Note: Used for notation only. -/
def hasCoeGenerator : Coe X (Pre R X) := ⟨of⟩
/-- Coercion from `R` to `Pre R X`. Note: Used for notation only. -/
def hasCoeSemiring : Coe R (Pre R X) := ⟨ofScalar⟩
/-- Multiplication in `Pre R X` defined as `Pre.mul`. Note: Used for notation only. -/
def hasMul : Mul (Pre R X) := ⟨mul⟩
/-- Addition in `Pre R X` defined as `Pre.add`. Note: Used for notation only. -/
def hasAdd : Add (Pre R X) := ⟨add⟩
/-- Zero in `Pre R X` defined as the image of `0` from `R`. Note: Used for notation only. -/
def hasZero : Zero (Pre R X) := ⟨ofScalar 0⟩
/-- One in `Pre R X` defined as the image of `1` from `R`. Note: Used for notation only. -/
def hasOne : One (Pre R X) := ⟨ofScalar 1⟩
/-- Scalar multiplication defined as multiplication by the image of elements from `R`.
Note: Used for notation only.
-/
def hasSMul : SMul R (Pre R X) := ⟨fun r m ↦ mul (ofScalar r) m⟩
end Pre
attribute [local instance] Pre.hasCoeGenerator Pre.hasCoeSemiring Pre.hasMul Pre.hasAdd
Pre.hasZero Pre.hasOne Pre.hasSMul
/-- Given a function from `X` to an `R`-algebra `A`, `lift_fun` provides a lift of `f` to a function
from `Pre R X` to `A`. This is mainly used in the construction of `FreeAlgebra.lift`.
-/
-- Porting note: recOn was replaced to preserve computability, see lean4#2049
def liftFun {A : Type*} [Semiring A] [Algebra R A] (f : X → A) :
Pre R X → A
| .of t => f t
| .add a b => liftFun f a + liftFun f b
| .mul a b => liftFun f a * liftFun f b
| .ofScalar c => algebraMap _ _ c
/-- An inductively defined relation on `Pre R X` used to force the initial algebra structure on
the associated quotient.
-/
inductive Rel : Pre R X → Pre R X → Prop
-- force `ofScalar` to be a central semiring morphism
| add_scalar {r s : R} : Rel (↑(r + s)) (↑r + ↑s)
| mul_scalar {r s : R} : Rel (↑(r * s)) (↑r * ↑s)
| central_scalar {r : R} {a : Pre R X} : Rel (r * a) (a * r)
-- commutative additive semigroup
| add_assoc {a b c : Pre R X} : Rel (a + b + c) (a + (b + c))
| add_comm {a b : Pre R X} : Rel (a + b) (b + a)
| zero_add {a : Pre R X} : Rel (0 + a) a
-- multiplicative monoid
| mul_assoc {a b c : Pre R X} : Rel (a * b * c) (a * (b * c))
| one_mul {a : Pre R X} : Rel (1 * a) a
| mul_one {a : Pre R X} : Rel (a * 1) a
-- distributivity
| left_distrib {a b c : Pre R X} : Rel (a * (b + c)) (a * b + a * c)
| right_distrib {a b c : Pre R X} :
Rel ((a + b) * c) (a * c + b * c)
-- other relations needed for semiring
| zero_mul {a : Pre R X} : Rel (0 * a) 0
| mul_zero {a : Pre R X} : Rel (a * 0) 0
-- compatibility
| add_compat_left {a b c : Pre R X} : Rel a b → Rel (a + c) (b + c)
| add_compat_right {a b c : Pre R X} : Rel a b → Rel (c + a) (c + b)
| mul_compat_left {a b c : Pre R X} : Rel a b → Rel (a * c) (b * c)
| mul_compat_right {a b c : Pre R X} : Rel a b → Rel (c * a) (c * b)
end FreeAlgebra
/-- The free algebra for the type `X` over the commutative semiring `R`.
-/
def FreeAlgebra :=
Quot (FreeAlgebra.Rel R X)
namespace FreeAlgebra
attribute [local instance] Pre.hasCoeGenerator Pre.hasCoeSemiring Pre.hasMul Pre.hasAdd
Pre.hasZero Pre.hasOne Pre.hasSMul
/-! Define the basic operations-/
instance instSMul {A} [CommSemiring A] [Algebra R A] : SMul R (FreeAlgebra A X) where
smul r := Quot.map (HMul.hMul (algebraMap R A r : Pre A X)) fun _ _ ↦ Rel.mul_compat_right
instance instZero : Zero (FreeAlgebra R X) where zero := Quot.mk _ 0
instance instOne : One (FreeAlgebra R X) where one := Quot.mk _ 1
instance instAdd : Add (FreeAlgebra R X) where
add := Quot.map₂ HAdd.hAdd (fun _ _ _ ↦ Rel.add_compat_right) fun _ _ _ ↦ Rel.add_compat_left
instance instMul : Mul (FreeAlgebra R X) where
mul := Quot.map₂ HMul.hMul (fun _ _ _ ↦ Rel.mul_compat_right) fun _ _ _ ↦ Rel.mul_compat_left
-- `Quot.mk` is an implementation detail of `FreeAlgebra`, so this lemma is private
private theorem mk_mul (x y : Pre R X) :
Quot.mk (Rel R X) (x * y) = (HMul.hMul (self := instHMul (α := FreeAlgebra R X))
(Quot.mk (Rel R X) x) (Quot.mk (Rel R X) y)) :=
rfl
/-! Build the semiring structure. We do this one piece at a time as this is convenient for proving
the `nsmul` fields. -/
instance instMonoidWithZero : MonoidWithZero (FreeAlgebra R X) where
mul_assoc := by
rintro ⟨⟩ ⟨⟩ ⟨⟩
exact Quot.sound Rel.mul_assoc
one := Quot.mk _ 1
one_mul := by
rintro ⟨⟩
exact Quot.sound Rel.one_mul
mul_one := by
rintro ⟨⟩
exact Quot.sound Rel.mul_one
zero_mul := by
rintro ⟨⟩
exact Quot.sound Rel.zero_mul
mul_zero := by
rintro ⟨⟩
exact Quot.sound Rel.mul_zero
instance instDistrib : Distrib (FreeAlgebra R X) where
left_distrib := by
rintro ⟨⟩ ⟨⟩ ⟨⟩
exact Quot.sound Rel.left_distrib
right_distrib := by
rintro ⟨⟩ ⟨⟩ ⟨⟩
exact Quot.sound Rel.right_distrib
instance instAddCommMonoid : AddCommMonoid (FreeAlgebra R X) where
add_assoc := by
rintro ⟨⟩ ⟨⟩ ⟨⟩
exact Quot.sound Rel.add_assoc
zero_add := by
rintro ⟨⟩
exact Quot.sound Rel.zero_add
add_zero := by
rintro ⟨⟩
change Quot.mk _ _ = _
rw [Quot.sound Rel.add_comm, Quot.sound Rel.zero_add]
add_comm := by
rintro ⟨⟩ ⟨⟩
exact Quot.sound Rel.add_comm
nsmul := (· • ·)
nsmul_zero := by
rintro ⟨⟩
change Quot.mk _ (_ * _) = _
rw [map_zero]
exact Quot.sound Rel.zero_mul
nsmul_succ n := by
rintro ⟨a⟩
dsimp only [HSMul.hSMul, instSMul, Quot.map]
rw [map_add, map_one, mk_mul, mk_mul, ← add_one_mul (_ : FreeAlgebra R X)]
congr 1
exact Quot.sound Rel.add_scalar
instance : Semiring (FreeAlgebra R X) where
__ := instMonoidWithZero R X
__ := instAddCommMonoid R X
__ := instDistrib R X
natCast n := Quot.mk _ (n : R)
natCast_zero := by simp; rfl
natCast_succ n := by simpa using Quot.sound Rel.add_scalar
instance : Inhabited (FreeAlgebra R X) :=
⟨0⟩
instance instAlgebra {A} [CommSemiring A] [Algebra R A] : Algebra R (FreeAlgebra A X) where
toRingHom := ({
toFun := fun r => Quot.mk _ r
map_one' := rfl
map_mul' := fun _ _ => Quot.sound Rel.mul_scalar
map_zero' := rfl
map_add' := fun _ _ => Quot.sound Rel.add_scalar } : A →+* FreeAlgebra A X).comp
(algebraMap R A)
commutes' _ := by
rintro ⟨⟩
exact Quot.sound Rel.central_scalar
smul_def' _ _ := rfl
-- verify there is no diamond at `default` transparency but we will need
-- `reducible_and_instances` which currently fails #10906
variable (S : Type) [CommSemiring S] in
example : (Semiring.toNatAlgebra : Algebra ℕ (FreeAlgebra S X)) = instAlgebra _ _ := rfl
instance {R S A} [CommSemiring R] [CommSemiring S] [CommSemiring A]
[SMul R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] :
IsScalarTower R S (FreeAlgebra A X) where
smul_assoc r s x := by
change algebraMap S A (r • s) • x = algebraMap R A _ • (algebraMap S A _ • x)
rw [← smul_assoc]
congr
simp only [Algebra.algebraMap_eq_smul_one, smul_eq_mul]
rw [smul_assoc, ← smul_one_mul]
instance {R S A} [CommSemiring R] [CommSemiring S] [CommSemiring A] [Algebra R A] [Algebra S A] :
SMulCommClass R S (FreeAlgebra A X) where
smul_comm r s x := smul_comm (algebraMap R A r) (algebraMap S A s) x
instance {S : Type*} [CommRing S] : Ring (FreeAlgebra S X) :=
Algebra.semiringToRing S
-- verify there is no diamond but we will need
-- `reducible_and_instances` which currently fails #10906
variable (S : Type) [CommRing S] in
example : (Ring.toIntAlgebra _ : Algebra ℤ (FreeAlgebra S X)) = instAlgebra _ _ := rfl
variable {X}
/-- The canonical function `X → FreeAlgebra R X`.
-/
irreducible_def ι : X → FreeAlgebra R X := fun m ↦ Quot.mk _ m
@[simp]
theorem quot_mk_eq_ι (m : X) : Quot.mk (FreeAlgebra.Rel R X) m = ι R m := by rw [ι_def]
variable {A : Type*} [Semiring A] [Algebra R A]
/-- Internal definition used to define `lift` -/
private def liftAux (f : X → A) : FreeAlgebra R X →ₐ[R] A where
toFun a :=
Quot.liftOn a (liftFun _ _ f) fun a b h ↦ by
induction' h
· exact (algebraMap R A).map_add _ _
· exact (algebraMap R A).map_mul _ _
· apply Algebra.commutes
· change _ + _ + _ = _ + (_ + _)
rw [add_assoc]
· change _ + _ = _ + _
rw [add_comm]
· change algebraMap _ _ _ + liftFun R X f _ = liftFun R X f _
simp
· change _ * _ * _ = _ * (_ * _)
rw [mul_assoc]
· change algebraMap _ _ _ * liftFun R X f _ = liftFun R X f _
simp
· change liftFun R X f _ * algebraMap _ _ _ = liftFun R X f _
simp
· change _ * (_ + _) = _ * _ + _ * _
rw [left_distrib]
· change (_ + _) * _ = _ * _ + _ * _
rw [right_distrib]
· change algebraMap _ _ _ * _ = algebraMap _ _ _
simp
· change _ * algebraMap _ _ _ = algebraMap _ _ _
simp
repeat
change liftFun R X f _ + liftFun R X f _ = _
simp only [*]
rfl
repeat
change liftFun R X f _ * liftFun R X f _ = _
simp only [*]
rfl
map_one' := by
change algebraMap _ _ _ = _
simp
map_mul' := by
rintro ⟨⟩ ⟨⟩
rfl
map_zero' := by
dsimp
change algebraMap _ _ _ = _
simp
map_add' := by
rintro ⟨⟩ ⟨⟩
rfl
commutes' := by tauto
/-- Given a function `f : X → A` where `A` is an `R`-algebra, `lift R f` is the unique lift
of `f` to a morphism of `R`-algebras `FreeAlgebra R X → A`.
-/
@[irreducible]
def lift : (X → A) ≃ (FreeAlgebra R X →ₐ[R] A) :=
{ toFun := liftAux R
invFun := fun F ↦ F ∘ ι R
left_inv := fun f ↦ by
ext
simp only [Function.comp_apply, ι_def]
rfl
right_inv := fun F ↦ by
ext t
rcases t with ⟨x⟩
induction x with
| of =>
change ((F : FreeAlgebra R X → A) ∘ ι R) _ = _
simp only [Function.comp_apply, ι_def]
| ofScalar x =>
change algebraMap _ _ x = F (algebraMap _ _ x)
rw [AlgHom.commutes F _]
| add a b ha hb =>
-- Porting note: it is necessary to declare fa and fb explicitly otherwise Lean refuses
-- to consider `Quot.mk (Rel R X) ·` as element of FreeAlgebra R X
let fa : FreeAlgebra R X := Quot.mk (Rel R X) a
let fb : FreeAlgebra R X := Quot.mk (Rel R X) b
change liftAux R (F ∘ ι R) (fa + fb) = F (fa + fb)
rw [map_add, map_add, ha, hb]
| mul a b ha hb =>
let fa : FreeAlgebra R X := Quot.mk (Rel R X) a
let fb : FreeAlgebra R X := Quot.mk (Rel R X) b
change liftAux R (F ∘ ι R) (fa * fb) = F (fa * fb)
rw [map_mul, map_mul, ha, hb] }
@[simp]
theorem liftAux_eq (f : X → A) : liftAux R f = lift R f := by
rw [lift]
rfl
@[simp]
theorem lift_symm_apply (F : FreeAlgebra R X →ₐ[R] A) : (lift R).symm F = F ∘ ι R := by
rw [lift]
rfl
variable {R}
@[simp]
theorem ι_comp_lift (f : X → A) : (lift R f : FreeAlgebra R X → A) ∘ ι R = f := by
ext
rw [Function.comp_apply, ι_def, lift]
rfl
@[simp]
theorem lift_ι_apply (f : X → A) (x) : lift R f (ι R x) = f x := by
rw [ι_def, lift]
rfl
@[simp]
theorem lift_unique (f : X → A) (g : FreeAlgebra R X →ₐ[R] A) :
(g : FreeAlgebra R X → A) ∘ ι R = f ↔ g = lift R f := by
rw [← (lift R).symm_apply_eq, lift]
rfl
/-!
Since we have set the basic definitions as `@[Irreducible]`, from this point onwards one
should only use the universal properties of the free algebra, and consider the actual implementation
as a quotient of an inductive type as completely hidden. -/
-- Marking `FreeAlgebra` irreducible makes `Ring` instances inaccessible on quotients.
-- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241
-- For now, we avoid this by not marking it irreducible.
@[simp]
theorem lift_comp_ι (g : FreeAlgebra R X →ₐ[R] A) :
lift R ((g : FreeAlgebra R X → A) ∘ ι R) = g := by
rw [← lift_symm_apply]
exact (lift R).apply_symm_apply g
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem hom_ext {f g : FreeAlgebra R X →ₐ[R] A}
(w : (f : FreeAlgebra R X → A) ∘ ι R = (g : FreeAlgebra R X → A) ∘ ι R) : f = g := by
rw [← lift_symm_apply, ← lift_symm_apply] at w
exact (lift R).symm.injective w
/-- The free algebra on `X` is "just" the monoid algebra on the free monoid on `X`.
This would be useful when constructing linear maps out of a free algebra,
for example.
-/
noncomputable def equivMonoidAlgebraFreeMonoid :
FreeAlgebra R X ≃ₐ[R] MonoidAlgebra R (FreeMonoid X) :=
AlgEquiv.ofAlgHom (lift R fun x ↦ (MonoidAlgebra.of R (FreeMonoid X)) (FreeMonoid.of x))
((MonoidAlgebra.lift R (FreeMonoid X) (FreeAlgebra R X)) (FreeMonoid.lift (ι R)))
(by
apply MonoidAlgebra.algHom_ext; intro x
refine FreeMonoid.recOn x ?_ ?_
· simp
rfl
· intro x y ih
simp at ih
simp [ih])
(by
ext
simp)
/-- `FreeAlgebra R X` is nontrivial when `R` is. -/
instance [Nontrivial R] : Nontrivial (FreeAlgebra R X) :=
equivMonoidAlgebraFreeMonoid.surjective.nontrivial
/-- `FreeAlgebra R X` has no zero-divisors when `R` has no zero-divisors. -/
instance instNoZeroDivisors [NoZeroDivisors R] : NoZeroDivisors (FreeAlgebra R X) :=
equivMonoidAlgebraFreeMonoid.toMulEquiv.noZeroDivisors
/-- `FreeAlgebra R X` is a domain when `R` is an integral domain. -/
instance instIsDomain {R X} [CommRing R] [IsDomain R] : IsDomain (FreeAlgebra R X) :=
NoZeroDivisors.to_isDomain _
section
/-- The left-inverse of `algebraMap`. -/
def algebraMapInv : FreeAlgebra R X →ₐ[R] R :=
lift R (0 : X → R)
theorem algebraMap_leftInverse :
Function.LeftInverse algebraMapInv (algebraMap R <| FreeAlgebra R X) := fun x ↦ by
simp [algebraMapInv]
@[simp]
theorem algebraMap_inj (x y : R) :
algebraMap R (FreeAlgebra R X) x = algebraMap R (FreeAlgebra R X) y ↔ x = y :=
algebraMap_leftInverse.injective.eq_iff
@[simp]
theorem algebraMap_eq_zero_iff (x : R) : algebraMap R (FreeAlgebra R X) x = 0 ↔ x = 0 :=
map_eq_zero_iff (algebraMap _ _) algebraMap_leftInverse.injective
@[simp]
theorem algebraMap_eq_one_iff (x : R) : algebraMap R (FreeAlgebra R X) x = 1 ↔ x = 1 :=
map_eq_one_iff (algebraMap _ _) algebraMap_leftInverse.injective
-- this proof is copied from the approach in `FreeAbelianGroup.of_injective`
theorem ι_injective [Nontrivial R] : Function.Injective (ι R : X → FreeAlgebra R X) :=
fun x y hoxy ↦
by_contradiction <| by
classical exact fun hxy : x ≠ y ↦
let f : FreeAlgebra R X →ₐ[R] R := lift R fun z ↦ if x = z then (1 : R) else 0
have hfx1 : f (ι R x) = 1 := (lift_ι_apply _ _).trans <| if_pos rfl
have hfy1 : f (ι R y) = 1 := hoxy ▸ hfx1
have hfy0 : f (ι R y) = 0 := (lift_ι_apply _ _).trans <| if_neg hxy
one_ne_zero <| hfy1.symm.trans hfy0
@[simp]
theorem ι_inj [Nontrivial R] (x y : X) : ι R x = ι R y ↔ x = y :=
ι_injective.eq_iff
@[simp]
theorem ι_ne_algebraMap [Nontrivial R] (x : X) (r : R) : ι R x ≠ algebraMap R _ r := fun h ↦ by
let f0 : FreeAlgebra R X →ₐ[R] R := lift R 0
let f1 : FreeAlgebra R X →ₐ[R] R := lift R 1
have hf0 : f0 (ι R x) = 0 := lift_ι_apply _ _
have hf1 : f1 (ι R x) = 1 := lift_ι_apply _ _
rw [h, f0.commutes, Algebra.id.map_eq_self] at hf0
rw [h, f1.commutes, Algebra.id.map_eq_self] at hf1
exact zero_ne_one (hf0.symm.trans hf1)
@[simp]
theorem ι_ne_zero [Nontrivial R] (x : X) : ι R x ≠ 0 :=
ι_ne_algebraMap x 0
@[simp]
theorem ι_ne_one [Nontrivial R] (x : X) : ι R x ≠ 1 :=
ι_ne_algebraMap x 1
end
end FreeAlgebra
/- There is something weird in the above namespace that breaks the typeclass resolution of
`CoeSort` below. Closing it and reopening it fixes it... -/
namespace FreeAlgebra
/-- An induction principle for the free algebra.
If `C` holds for the `algebraMap` of `r : R` into `FreeAlgebra R X`, the `ι` of `x : X`, and is
preserved under addition and muliplication, then it holds for all of `FreeAlgebra R X`.
-/
@[elab_as_elim, induction_eliminator]
theorem induction {C : FreeAlgebra R X → Prop}
(h_grade0 : ∀ r, C (algebraMap R (FreeAlgebra R X) r)) (h_grade1 : ∀ x, C (ι R x))
(h_mul : ∀ a b, C a → C b → C (a * b)) (h_add : ∀ a b, C a → C b → C (a + b))
(a : FreeAlgebra R X) : C a := by
-- the arguments are enough to construct a subalgebra, and a mapping into it from X
let s : Subalgebra R (FreeAlgebra R X) :=
{ carrier := C
mul_mem' := h_mul _ _
add_mem' := h_add _ _
algebraMap_mem' := h_grade0 }
let of : X → s := Subtype.coind (ι R) h_grade1
-- the mapping through the subalgebra is the identity
have of_id : AlgHom.id R (FreeAlgebra R X) = s.val.comp (lift R of) := by
ext
simp [of, Subtype.coind]
-- finding a proof is finding an element of the subalgebra
suffices a = lift R of a by
rw [this]
exact Subtype.prop (lift R of a)
simp [AlgHom.ext_iff] at of_id
exact of_id a
@[simp]
theorem adjoin_range_ι : Algebra.adjoin R (Set.range (ι R : X → FreeAlgebra R X)) = ⊤ := by
set S := Algebra.adjoin R (Set.range (ι R : X → FreeAlgebra R X))
refine top_unique fun x hx => ?_; clear hx
induction x with
| h_grade0 => exact S.algebraMap_mem _
| h_add x y hx hy => exact S.add_mem hx hy
| h_mul x y hx hy => exact S.mul_mem hx hy
| h_grade1 x => exact Algebra.subset_adjoin (Set.mem_range_self _)
variable {A : Type*} [Semiring A] [Algebra R A]
/-- Noncommutative version of `Algebra.adjoin_range_eq_range_aeval`. -/
theorem _root_.Algebra.adjoin_range_eq_range_freeAlgebra_lift (f : X → A) :
Algebra.adjoin R (Set.range f) = (FreeAlgebra.lift R f).range := by
simp only [← Algebra.map_top, ← adjoin_range_ι, AlgHom.map_adjoin, ← Set.range_comp,
(· ∘ ·), lift_ι_apply]
/-- Noncommutative version of `Algebra.adjoin_range_eq_range`. -/
theorem _root_.Algebra.adjoin_eq_range_freeAlgebra_lift (s : Set A) :
Algebra.adjoin R s = (FreeAlgebra.lift R ((↑) : s → A)).range := by
rw [← Algebra.adjoin_range_eq_range_freeAlgebra_lift, Subtype.range_coe]
end FreeAlgebra
|
Algebra\FreeNonUnitalNonAssocAlgebra.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.Algebra.Free
import Mathlib.Algebra.MonoidAlgebra.Basic
/-!
# Free algebras
Given a semiring `R` and a type `X`, we construct the free non-unital, non-associative algebra on
`X` with coefficients in `R`, together with its universal property. The construction is valuable
because it can be used to build free algebras with more structure, e.g., free Lie algebras.
Note that elsewhere we have a construction of the free unital, associative algebra. This is called
`FreeAlgebra`.
## Main definitions
* `FreeNonUnitalNonAssocAlgebra`
* `FreeNonUnitalNonAssocAlgebra.lift`
* `FreeNonUnitalNonAssocAlgebra.of`
## Implementation details
We construct the free algebra as the magma algebra, with coefficients in `R`, of the free magma on
`X`. However we regard this as an implementation detail and thus deliberately omit the lemmas
`of_apply` and `lift_apply`, and we mark `FreeNonUnitalNonAssocAlgebra` and `lift` as
irreducible once we have established the universal property.
## Tags
free algebra, non-unital, non-associative, free magma, magma algebra, universal property,
forgetful functor, adjoint functor
-/
universe u v w
noncomputable section
variable (R : Type u) (X : Type v) [Semiring R]
/-- The free non-unital, non-associative algebra on the type `X` with coefficients in `R`. -/
abbrev FreeNonUnitalNonAssocAlgebra :=
MonoidAlgebra R (FreeMagma X)
namespace FreeNonUnitalNonAssocAlgebra
variable {X}
/-- The embedding of `X` into the free algebra with coefficients in `R`. -/
def of : X → FreeNonUnitalNonAssocAlgebra R X :=
MonoidAlgebra.ofMagma R _ ∘ FreeMagma.of
variable {A : Type w} [NonUnitalNonAssocSemiring A]
variable [Module R A] [IsScalarTower R A A] [SMulCommClass R A A]
/-- The functor `X ↦ FreeNonUnitalNonAssocAlgebra R X` from the category of types to the
category of non-unital, non-associative algebras over `R` is adjoint to the forgetful functor in the
other direction. -/
def lift : (X → A) ≃ (FreeNonUnitalNonAssocAlgebra R X →ₙₐ[R] A) :=
FreeMagma.lift.trans (MonoidAlgebra.liftMagma R)
@[simp]
theorem lift_symm_apply (F : FreeNonUnitalNonAssocAlgebra R X →ₙₐ[R] A) :
(lift R).symm F = F ∘ of R := rfl
@[simp]
theorem of_comp_lift (f : X → A) : lift R f ∘ of R = f :=
(lift R).left_inv f
@[simp]
theorem lift_unique (f : X → A) (F : FreeNonUnitalNonAssocAlgebra R X →ₙₐ[R] A) :
F ∘ of R = f ↔ F = lift R f :=
(lift R).symm_apply_eq
@[simp]
theorem lift_of_apply (f : X → A) (x) : lift R f (of R x) = f x :=
congr_fun (of_comp_lift _ f) x
@[simp]
theorem lift_comp_of (F : FreeNonUnitalNonAssocAlgebra R X →ₙₐ[R] A) : lift R (F ∘ of R) = F :=
(lift R).apply_symm_apply F
@[ext]
theorem hom_ext {F₁ F₂ : FreeNonUnitalNonAssocAlgebra R X →ₙₐ[R] A}
(h : ∀ x, F₁ (of R x) = F₂ (of R x)) : F₁ = F₂ :=
(lift R).symm.injective <| funext h
end FreeNonUnitalNonAssocAlgebra
|
End of preview. Expand
in Data Studio
README.md exists but content is empty.
- Downloads last month
- 35