Semirings and rings #
This file defines semirings, rings and domains. This is analogous to Algebra.Group.Defs
and
Algebra.Group.Basic
, the difference being that the former is about +
and *
separately, while
the present file is about their interaction.
Main definitions #
Distrib
: Typeclass for distributivity of multiplication over addition.HasDistribNeg
: Typeclass for commutativity of negation and multiplication. This is useful when dealing with multiplicative submonoids which are closed under negation without being closed under addition, for exampleUnits
.(NonUnital)(NonAssoc)(Semi)Ring
: Typeclasses for possibly non-unital or non-associative rings and semirings. Some combinations are not defined yet because they haven't found use.
Tags #
Semiring
, CommSemiring
, Ring
, CommRing
, domain, IsDomain
, nonzero, units
- mul : R → R → R
- add : R → R → R
Multiplication is left distributive over addition
Multiplication is right distributive over addition
A typeclass stating that multiplication is left and right distributive over addition.
Instances
Classes of semirings and rings #
We make sure that the canonical path from NonAssocSemiring
to Ring
passes through Semiring
,
as this is a path which is followed all the time in linear algebra where the defining semilinear map
σ : R →+* S
depends on the NonAssocSemiring
structure of R
and S
while the module
definition depends on the Semiring
structure.
It is not currently possible to adjust priorities by hand (see lean4#2115). Instead, the last
declared instance is used, so we make sure that Semiring
is declared after NonAssocRing
, so
that Semiring -> NonAssocSemiring
is tried before NonAssocRing -> NonAssocSemiring
.
TODO: clean this once lean4#2115 is fixed
- add : α → α → α
- zero : α
- nsmul : ℕ → α → α
- nsmul_zero : ∀ (x : α), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : α), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- mul : α → α → α
Multiplication is left distributive over addition
Multiplication is right distributive over addition
Zero is a left absorbing element for multiplication
Zero is a right absorbing element for multiplication
A not-necessarily-unital, not-necessarily-associative semiring.
Instances
- add : α → α → α
- zero : α
- nsmul : ℕ → α → α
- nsmul_zero : ∀ (x : α), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : α), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- mul : α → α → α
Multiplication is associative
An associative but not-necessarily unital semiring.
Instances
- add : α → α → α
- zero : α
- nsmul : ℕ → α → α
- nsmul_zero : ∀ (x : α), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : α), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- mul : α → α → α
- one : α
One is a left neutral element for multiplication
One is a right neutral element for multiplication
- natCast : ℕ → α
- natCast_zero : NatCast.natCast 0 = 0
The canonical map
ℕ → R
sends0 : ℕ
to0 : R
. - natCast_succ : ∀ (n : ℕ), NatCast.natCast (n + 1) = NatCast.natCast n + 1
The canonical map
ℕ → R
is a homomorphism.
A unital but not-necessarily-associative semiring.
Instances
- add : α → α → α
- zero : α
- nsmul : ℕ → α → α
- nsmul_zero : ∀ (x : α), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : α), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- neg : α → α
- sub : α → α → α
- zsmul : ℤ → α → α
- zsmul_zero' : ∀ (a : α), SubNegMonoid.zsmul 0 a = 0
- zsmul_succ' : ∀ (n : ℕ) (a : α), SubNegMonoid.zsmul (Int.ofNat (Nat.succ n)) a = a + SubNegMonoid.zsmul (Int.ofNat n) a
- zsmul_neg' : ∀ (n : ℕ) (a : α), SubNegMonoid.zsmul (Int.negSucc n) a = -SubNegMonoid.zsmul (↑(Nat.succ n)) a
- mul : α → α → α
Multiplication is left distributive over addition
Multiplication is right distributive over addition
Zero is a left absorbing element for multiplication
Zero is a right absorbing element for multiplication
A not-necessarily-unital, not-necessarily-associative ring.
Instances
- add : α → α → α
- zero : α
- nsmul : ℕ → α → α
- nsmul_zero : ∀ (x : α), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : α), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- neg : α → α
- sub : α → α → α
- zsmul : ℤ → α → α
- zsmul_zero' : ∀ (a : α), SubNegMonoid.zsmul 0 a = 0
- zsmul_succ' : ∀ (n : ℕ) (a : α), SubNegMonoid.zsmul (Int.ofNat (Nat.succ n)) a = a + SubNegMonoid.zsmul (Int.ofNat n) a
- zsmul_neg' : ∀ (n : ℕ) (a : α), SubNegMonoid.zsmul (Int.negSucc n) a = -SubNegMonoid.zsmul (↑(Nat.succ n)) a
- mul : α → α → α
Multiplication is associative
An associative but not-necessarily unital ring.
Instances
- add : α → α → α
- zero : α
- nsmul : ℕ → α → α
- nsmul_zero : ∀ (x : α), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : α), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- neg : α → α
- sub : α → α → α
- zsmul : ℤ → α → α
- zsmul_zero' : ∀ (a : α), SubNegMonoid.zsmul 0 a = 0
- zsmul_succ' : ∀ (n : ℕ) (a : α), SubNegMonoid.zsmul (Int.ofNat (Nat.succ n)) a = a + SubNegMonoid.zsmul (Int.ofNat n) a
- zsmul_neg' : ∀ (n : ℕ) (a : α), SubNegMonoid.zsmul (Int.negSucc n) a = -SubNegMonoid.zsmul (↑(Nat.succ n)) a
- mul : α → α → α
- one : α
One is a left neutral element for multiplication
One is a right neutral element for multiplication
- natCast : ℕ → α
- natCast_zero : NatCast.natCast 0 = 0
The canonical map
ℕ → R
sends0 : ℕ
to0 : R
. - natCast_succ : ∀ (n : ℕ), NatCast.natCast (n + 1) = NatCast.natCast n + 1
The canonical map
ℕ → R
is a homomorphism. - intCast : ℤ → α
- intCast_ofNat : ∀ (n : ℕ), IntCast.intCast ↑n = ↑n
The canonical homorphism
ℤ → R
agrees with the one fromℕ → R
onℕ
. - intCast_negSucc : ∀ (n : ℕ), IntCast.intCast (Int.negSucc n) = -↑(n + 1)
The canonical homorphism
ℤ → R
for negative values is just the negation of the values of the canonical homomorphismℕ → R
.
A unital but not-necessarily-associative ring.
Instances
- add : α → α → α
- zero : α
- nsmul : ℕ → α → α
- nsmul_zero : ∀ (x : α), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : α), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- mul : α → α → α
- one : α
One is a left neutral element for multiplication
One is a right neutral element for multiplication
- natCast : ℕ → α
- natCast_zero : NatCast.natCast 0 = 0
The canonical map
ℕ → R
sends0 : ℕ
to0 : R
. - natCast_succ : ∀ (n : ℕ), NatCast.natCast (n + 1) = NatCast.natCast n + 1
The canonical map
ℕ → R
is a homomorphism. - npow : ℕ → α → α
Raising to the power of a natural number.
- npow_zero : ∀ (x : α), Semiring.npow 0 x = 1
Raising to the power
(0 : ℕ)
gives1
. - npow_succ : ∀ (n : ℕ) (x : α), Semiring.npow (n + 1) x = x * Semiring.npow n x
Raising to the power
(n + 1 : ℕ)
behaves as expected.
Instances
- add : R → R → R
- zero : R
- nsmul : ℕ → R → R
- nsmul_zero : ∀ (x : R), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : R), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- mul : R → R → R
- one : R
- natCast : ℕ → R
- natCast_zero : NatCast.natCast 0 = 0
- natCast_succ : ∀ (n : ℕ), NatCast.natCast (n + 1) = NatCast.natCast n + 1
- npow : ℕ → R → R
- npow_zero : ∀ (x : R), Semiring.npow 0 x = 1
- npow_succ : ∀ (n : ℕ) (x : R), Semiring.npow (n + 1) x = x * Semiring.npow n x
- neg : R → R
- sub : R → R → R
- zsmul : ℤ → R → R
- zsmul_zero' : ∀ (a : R), Ring.zsmul 0 a = 0
- zsmul_succ' : ∀ (n : ℕ) (a : R), Ring.zsmul (Int.ofNat (Nat.succ n)) a = a + Ring.zsmul (Int.ofNat n) a
- zsmul_neg' : ∀ (n : ℕ) (a : R), Ring.zsmul (Int.negSucc n) a = -Ring.zsmul (↑(Nat.succ n)) a
- intCast : ℤ → R
- intCast_ofNat : ∀ (n : ℕ), IntCast.intCast ↑n = ↑n
The canonical homorphism
ℤ → R
agrees with the one fromℕ → R
onℕ
. - intCast_negSucc : ∀ (n : ℕ), IntCast.intCast (Int.negSucc n) = -↑(n + 1)
The canonical homorphism
ℤ → R
for negative values is just the negation of the values of the canonical homomorphismℕ → R
.
Instances
Semirings #
- add : α → α → α
- zero : α
- nsmul : ℕ → α → α
- nsmul_zero : ∀ (x : α), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : α), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- mul : α → α → α
Multiplication is commutative in a commutative semigroup.
A non-unital commutative semiring is a NonUnitalSemiring
with commutative multiplication.
In other words, it is a type with the following structures: additive commutative monoid
(AddCommMonoid
), commutative semigroup (CommSemigroup
), distributive laws (Distrib
), and
multiplication by zero law (MulZeroClass
).
Instances
- add : R → R → R
- zero : R
- nsmul : ℕ → R → R
- nsmul_zero : ∀ (x : R), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : R), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- mul : R → R → R
- one : R
- natCast : ℕ → R
- natCast_zero : NatCast.natCast 0 = 0
- natCast_succ : ∀ (n : ℕ), NatCast.natCast (n + 1) = NatCast.natCast n + 1
- npow : ℕ → R → R
- npow_zero : ∀ (x : R), Semiring.npow 0 x = 1
- npow_succ : ∀ (n : ℕ) (x : R), Semiring.npow (n + 1) x = x * Semiring.npow n x
Multiplication is commutative in a commutative semigroup.
Instances
Equations
- CommSemiring.toNonUnitalCommSemiring = let src := inferInstanceAs (CommMonoid α); let src_1 := inferInstanceAs (CommSemiring α); NonUnitalCommSemiring.mk (_ : ∀ (a b : α), a * b = b * a)
Equations
- One or more equations did not get rendered due to their size.
- neg : α → α
Negation is left distributive over multiplication
Negation is right distributive over multiplication
Typeclass for a negation operator that distributes across multiplication.
This is useful for dealing with submonoids of a ring that contain -1
without having to duplicate
lemmas.
Instances
An element of a ring multiplied by the additive inverse of one is the element's additive inverse.
The additive inverse of one multiplied by an element of a ring is the element's additive inverse.
Equations
- MulZeroClass.negZeroClass = let src := inferInstanceAs (Zero α); let src_1 := inferInstanceAs (InvolutiveNeg α); NegZeroClass.mk (_ : -0 = 0)
Rings #
- add : α → α → α
- zero : α
- nsmul : ℕ → α → α
- nsmul_zero : ∀ (x : α), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : α), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- neg : α → α
- sub : α → α → α
- zsmul : ℤ → α → α
- zsmul_zero' : ∀ (a : α), SubNegMonoid.zsmul 0 a = 0
- zsmul_succ' : ∀ (n : ℕ) (a : α), SubNegMonoid.zsmul (Int.ofNat (Nat.succ n)) a = a + SubNegMonoid.zsmul (Int.ofNat n) a
- zsmul_neg' : ∀ (n : ℕ) (a : α), SubNegMonoid.zsmul (Int.negSucc n) a = -SubNegMonoid.zsmul (↑(Nat.succ n)) a
- mul : α → α → α
Multiplication is commutative in a commutative semigroup.
A non-unital commutative ring is a NonUnitalRing
with commutative multiplication.
Instances
Equations
- NonUnitalCommRing.toNonUnitalCommSemiring = NonUnitalCommSemiring.mk (_ : ∀ (a b : α), a * b = b * a)
- add : α → α → α
- zero : α
- nsmul : ℕ → α → α
- nsmul_zero : ∀ (x : α), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : α), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- mul : α → α → α
- one : α
- natCast : ℕ → α
- natCast_zero : NatCast.natCast 0 = 0
- natCast_succ : ∀ (n : ℕ), NatCast.natCast (n + 1) = NatCast.natCast n + 1
- npow : ℕ → α → α
- npow_zero : ∀ (x : α), Semiring.npow 0 x = 1
- npow_succ : ∀ (n : ℕ) (x : α), Semiring.npow (n + 1) x = x * Semiring.npow n x
- neg : α → α
- sub : α → α → α
- zsmul : ℤ → α → α
- zsmul_zero' : ∀ (a : α), Ring.zsmul 0 a = 0
- zsmul_succ' : ∀ (n : ℕ) (a : α), Ring.zsmul (Int.ofNat (Nat.succ n)) a = a + Ring.zsmul (Int.ofNat n) a
- zsmul_neg' : ∀ (n : ℕ) (a : α), Ring.zsmul (Int.negSucc n) a = -Ring.zsmul (↑(Nat.succ n)) a
- intCast : ℤ → α
- intCast_ofNat : ∀ (n : ℕ), IntCast.intCast ↑n = ↑n
- intCast_negSucc : ∀ (n : ℕ), IntCast.intCast (Int.negSucc n) = -↑(n + 1)
Multiplication is commutative in a commutative semigroup.
Instances
Equations
- CommRing.toCommSemiring = CommSemiring.mk (_ : ∀ (a b : α), a * b = b * a)
Equations
- CommRing.toNonUnitalCommRing = NonUnitalCommRing.mk (_ : ∀ (a b : α), a * b = b * a)
Equations
- CommRing.toAddCommGroupWithOne = AddCommGroupWithOne.mk
A domain is a nontrivial semiring such multiplication by a non zero element is cancellative,
on both sides. In other words, a nontrivial semiring R
satisfying
∀ {a b c : R}, a ≠ 0 → a * b = a * c → b = c
and
∀ {a b c : R}, b ≠ 0 → a * b = c * b → a = c
.
This is implemented as a mixin for Semiring α
.
To obtain an integral domain use [CommRing α] [IsDomain α]
.
Instances
Previously an import dependency on Mathlib.Algebra.Group.Basic
had crept in.
In general, the .Defs
files in the basic algebraic hierarchy should only depend on earlier .Defs
files, without importing .Basic
theory development.
These assert_not_exists
statements guard against this returning.