Typeclasses for (semi)groups and monoids #
In this file we define typeclasses for algebraic structures with one binary operation.
The classes are named (Add)?(Comm)?(Semigroup|Monoid|Group)
, where Add
means that
the class uses additive notation and Comm
means that the class assumes that the binary
operation is commutative.
The file does not contain any lemmas except for
- axioms of typeclasses restated in the root namespace;
- lemmas required for instances.
For basic lemmas about these classes see Algebra.Group.Basic
.
We also introduce notation classes SMul
and VAdd
for multiplicative and additive
actions and register the following instances:
Pow M ℕ
, for monoidsM
, andPow G ℤ
for groupsG
;SMul ℕ M
for additive monoidsM
, andSMul ℤ G
for additive groupsG
.
SMul
is typically, but not exclusively, used for scalar multiplication-like operators.
See the module Algebra.AddTorsor
for a motivating example for the name VAdd
(vector addition)`.
Notation #
+
,-
,*
,/
,^
: the usual arithmetic operations; the underlying functions areAdd.add
,Neg.neg
/Sub.sub
,Mul.mul
,Div.div
, andHPow.hPow
.a • b
is used as notation forHSMul.hSMul a b
.a +ᵥ b
is used as notation forHVAdd.hVAdd a b
.
The notation typeclass for heterogeneous additive actions.
This enables the notation a +ᵥ b : γ
where a : α
, b : β
.
- hVAdd : α → β → γ
a +ᵥ b
computes the sum ofa
andb
. The meaning of this notation is type-dependent.
Instances
The notation typeclass for heterogeneous scalar multiplication.
This enables the notation a • b : γ
where a : α
, b : β
.
It is assumed to represent a left action in some sense.
The notation a • b
is augmented with a macro (below) to have it elaborate as a left action.
Only the b
argument participates in the elaboration algorithm: the algorithm uses the type of b
when calculating the type of the surrounding arithmetic expression
and it tries to insert coercions into b
to get some b'
such that a • b'
has the same type as b'
.
See the module documentation near the macro for more details.
- hSMul : α → β → γ
a • b
computes the product ofa
andb
. The meaning of this notation is type-dependent, but it is intended to be used for left actions.
Instances
a +ᵥ b
computes the sum of a
and b
.
The meaning of this notation is type-dependent.
Equations
- «term_+ᵥ_» = Lean.ParserDescr.trailingNode `term_+ᵥ_ 65 65 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " +ᵥ ") (Lean.ParserDescr.cat `term 66))
Instances For
a -ᵥ b
computes the difference of a
and b
. The meaning of this notation is
type-dependent, but it is intended to be used for additive torsors.
Equations
- «term_-ᵥ_» = Lean.ParserDescr.trailingNode `term_-ᵥ_ 65 65 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " -ᵥ ") (Lean.ParserDescr.cat `term 66))
Instances For
a • b
computes the product of a
and b
.
The meaning of this notation is type-dependent, but it is intended to be used for left actions.
Equations
- «term_•_» = Lean.ParserDescr.trailingNode `term_•_ 73 74 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " • ") (Lean.ParserDescr.cat `term 73))
Instances For
We have a macro to make x • y
notation participate in the expression tree elaborator,
like other arithmetic expressions such as +
, *
, /
, ^
, =
, inequalities, etc.
The macro is using the leftact%
elaborator introduced in
this RFC.
As a concrete example of the effect of this macro, consider
variable [Ring R] [AddCommMonoid M] [Module R M] (r : R) (N : Submodule R M) (m : M) (n : N)
#check m + r • n
Without the macro, the expression would elaborate as m + ↑(r • n : ↑N) : M
.
With the macro, the expression elaborates as m + r • (↑n : M) : M
.
To get the first interpretation, one can write m + (r • n :)
.
Here is a quick review of the expression tree elaborator:
- It builds up an expression tree of all the immediately accessible operations
that are marked with
binop%
,unop%
,leftact%
,rightact%
,binrel%
, etc. - It elaborates every leaf term of this tree
(without an expected type, so as if it were temporarily wrapped in
(... :)
). - Using the types of each elaborated leaf, it computes a supremum type they can all be coerced to, if such a supremum exists.
- It inserts coercions around leaf terms wherever needed.
The hypothesis is that individual expression trees tend to be calculations with respect to a single algebraic structure.
Note(kmill): If we were to remove HSMul
and switch to using SMul
directly,
then the expression tree elaborator would not be able to insert coercions within the right operand;
they would likely appear as ↑(x • y)
rather than x • ↑y
, unlike other arithmetic operations.
Invert an element of α.
Equations
- «term_⁻¹» = Lean.ParserDescr.trailingNode `term_⁻¹ 1024 1024 (Lean.ParserDescr.symbol "⁻¹")
Instances For
A mixin for cancellative multiplication.
Instances
A mixin for cancellative addition.
Instances
A commutative semigroup is a type with an associative commutative (*)
.
- mul : G → G → G
Multiplication is commutative in a commutative multiplicative magma.
Instances
A commutative additive semigroup is a type with an associative commutative (+)
.
- add : G → G → G
Addition is commutative in an commutative additive magma.
Instances
Any AddCommMagma G
that satisfies
IsRightCancelAdd G
also satisfies IsLeftCancelAdd G
.
Any CommMagma G
that satisfies IsRightCancelMul G
also satisfies IsLeftCancelMul G
.
Any AddCommMagma G
that satisfies
IsLeftCancelAdd G
also satisfies IsRightCancelAdd G
.
Any CommMagma G
that satisfies IsLeftCancelMul G
also satisfies IsRightCancelMul G
.
Any AddCommMagma G
that satisfies
IsLeftCancelAdd G
also satisfies IsCancelAdd G
.
Any CommMagma G
that satisfies IsLeftCancelMul G
also satisfies IsCancelMul G
.
Any AddCommMagma G
that satisfies
IsRightCancelAdd G
also satisfies IsCancelAdd G
.
Any CommMagma G
that satisfies IsRightCancelMul G
also satisfies IsCancelMul G
.
An AddLeftCancelSemigroup
is an additive semigroup such that
a + b = a + c
implies b = c
.
- add : G → G → G
Instances
Any AddLeftCancelSemigroup
satisfies
IsLeftCancelAdd
.
Equations
- ⋯ = ⋯
Any LeftCancelSemigroup
satisfies IsLeftCancelMul
.
Equations
- ⋯ = ⋯
An AddRightCancelSemigroup
is an additive semigroup such that
a + b = c + b
implies a = c
.
- add : G → G → G
Instances
Any AddRightCancelSemigroup
satisfies
IsRightCancelAdd
.
Equations
- ⋯ = ⋯
Any RightCancelSemigroup
satisfies IsRightCancelMul
.
Equations
- ⋯ = ⋯
Typeclass for expressing that a type M
with multiplication and a one satisfies
1 * a = a
and a * 1 = a
for all a : M
.
- one : M
- mul : M → M → M
One is a left neutral element for multiplication
One is a right neutral element for multiplication
Instances
Typeclass for expressing that a type M
with addition and a zero satisfies
0 + a = a
and a + 0 = a
for all a : M
.
- zero : M
- add : M → M → M
Zero is a left neutral element for addition
Zero is a right neutral element for addition
Instances
Design note on AddMonoid
and Monoid
#
An AddMonoid
has a natural ℕ
-action, defined by n • a = a + ... + a
, that we want to declare
as an instance as it makes it possible to use the language of linear algebra. However, there are
often other natural ℕ
-actions. For instance, for any semiring R
, the space of polynomials
Polynomial R
has a natural R
-action defined by multiplication on the coefficients. This means
that Polynomial ℕ
would have two natural ℕ
-actions, which are equal but not defeq. The same
goes for linear maps, tensor products, and so on (and even for ℕ
itself).
To solve this issue, we embed an ℕ
-action in the definition of an AddMonoid
(which is by
default equal to the naive action a + ... + a
, but can be adjusted when needed), and declare
a SMul ℕ α
instance using this action. See Note [forgetful inheritance] for more
explanations on this pattern.
For example, when we define Polynomial R
, then we declare the ℕ
-action to be by multiplication
on each coefficient (using the ℕ
-action on R
that comes from the fact that R
is
an AddMonoid
). In this way, the two natural SMul ℕ (Polynomial ℕ)
instances are defeq.
The tactic to_additive
transfers definitions and results from multiplicative monoids to additive
monoids. To work, it has to map fields to fields. This means that we should also add corresponding
fields to the multiplicative structure Monoid
, which could solve defeq problems for powers if
needed. These problems do not come up in practice, so most of the time we will not need to adjust
the npow
field when defining multiplicative objects.
A basic theory for the power function on monoids and the ℕ
-action on additive monoids is built in
the file Algebra.GroupPower.Basic
. For now, we only register the most basic properties that we
need right away.
An AddMonoid
is an AddSemigroup
with an element 0
such that 0 + a = a + 0 = a
.
- add : M → M → M
- zero : M
Zero is a left neutral element for addition
Zero is a right neutral element for addition
- nsmul : ℕ → M → M
Multiplication by a natural number. Set this to
nsmulRec
unlessModule
diamonds are possible. - nsmul_zero : ∀ (x : M), AddMonoid.nsmul 0 x = 0
Multiplication by
(0 : ℕ)
gives0
. - nsmul_succ : ∀ (n : ℕ) (x : M), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
Multiplication by
(n + 1 : ℕ)
behaves as expected.
Instances
A Monoid
is a Semigroup
with an element 1
such that 1 * a = a * 1 = a
.
- mul : M → M → M
- one : M
One is a left neutral element for multiplication
One is a right neutral element for multiplication
- npow : ℕ → M → M
Raising to the power of a natural number.
- npow_zero : ∀ (x : M), Monoid.npow 0 x = 1
Raising to the power
(0 : ℕ)
gives1
. - npow_succ : ∀ (n : ℕ) (x : M), Monoid.npow (n + 1) x = x * Monoid.npow n x
Raising to the power
(n + 1 : ℕ)
behaves as expected.
Instances
Equations
- Monoid.toNatPow = { pow := fun (x : M) (n : ℕ) => Monoid.npow n x }
An additive commutative monoid is an additive monoid with commutative (+)
.
- add : M → M → M
- zero : M
- nsmul : ℕ → M → M
- nsmul_zero : ∀ (x : M), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : M), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
Addition is commutative in an commutative additive magma.
Instances
A commutative monoid is a monoid with commutative (*)
.
- mul : M → M → M
- one : M
- npow : ℕ → M → M
- npow_zero : ∀ (x : M), Monoid.npow 0 x = 1
- npow_succ : ∀ (n : ℕ) (x : M), Monoid.npow (n + 1) x = x * Monoid.npow n x
Multiplication is commutative in a commutative multiplicative magma.
Instances
An additive monoid in which addition is left-cancellative.
Main examples are ℕ
and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so AddLeftCancelSemigroup
is not enough.
- add : M → M → M
- zero : M
Zero is a left neutral element for addition
Zero is a right neutral element for addition
- nsmul : ℕ → M → M
Multiplication by a natural number. Set this to
nsmulRec
unlessModule
diamonds are possible. - nsmul_zero : ∀ (x : M), AddLeftCancelMonoid.nsmul 0 x = 0
Multiplication by
(0 : ℕ)
gives0
. - nsmul_succ : ∀ (n : ℕ) (x : M), AddLeftCancelMonoid.nsmul (n + 1) x = x + AddLeftCancelMonoid.nsmul n x
Multiplication by
(n + 1 : ℕ)
behaves as expected.
Instances
A monoid in which multiplication is left-cancellative.
- mul : M → M → M
- one : M
One is a left neutral element for multiplication
One is a right neutral element for multiplication
- npow : ℕ → M → M
Raising to the power of a natural number.
- npow_zero : ∀ (x : M), LeftCancelMonoid.npow 0 x = 1
Raising to the power
(0 : ℕ)
gives1
. - npow_succ : ∀ (n : ℕ) (x : M), LeftCancelMonoid.npow (n + 1) x = x * LeftCancelMonoid.npow n x
Raising to the power
(n + 1 : ℕ)
behaves as expected.
Instances
An additive monoid in which addition is right-cancellative.
Main examples are ℕ
and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so AddRightCancelSemigroup
is not enough.
- add : M → M → M
- zero : M
Zero is a left neutral element for addition
Zero is a right neutral element for addition
- nsmul : ℕ → M → M
Multiplication by a natural number. Set this to
nsmulRec
unlessModule
diamonds are possible. - nsmul_zero : ∀ (x : M), AddRightCancelMonoid.nsmul 0 x = 0
Multiplication by
(0 : ℕ)
gives0
. - nsmul_succ : ∀ (n : ℕ) (x : M), AddRightCancelMonoid.nsmul (n + 1) x = x + AddRightCancelMonoid.nsmul n x
Multiplication by
(n + 1 : ℕ)
behaves as expected.
Instances
A monoid in which multiplication is right-cancellative.
- mul : M → M → M
- one : M
One is a left neutral element for multiplication
One is a right neutral element for multiplication
- npow : ℕ → M → M
Raising to the power of a natural number.
- npow_zero : ∀ (x : M), RightCancelMonoid.npow 0 x = 1
Raising to the power
(0 : ℕ)
gives1
. - npow_succ : ∀ (n : ℕ) (x : M), RightCancelMonoid.npow (n + 1) x = x * RightCancelMonoid.npow n x
Raising to the power
(n + 1 : ℕ)
behaves as expected.
Instances
An additive monoid in which addition is cancellative on both sides.
Main examples are ℕ
and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so AddRightCancelMonoid
is not enough.
- add : M → M → M
- zero : M
- nsmul : ℕ → M → M
- nsmul_zero : ∀ (x : M), AddLeftCancelMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : M), AddLeftCancelMonoid.nsmul (n + 1) x = x + AddLeftCancelMonoid.nsmul n x
Instances
A monoid in which multiplication is cancellative.
- mul : M → M → M
- one : M
- npow : ℕ → M → M
- npow_zero : ∀ (x : M), LeftCancelMonoid.npow 0 x = 1
- npow_succ : ∀ (n : ℕ) (x : M), LeftCancelMonoid.npow (n + 1) x = x * LeftCancelMonoid.npow n x
Instances
Commutative version of AddCancelMonoid
.
- add : M → M → M
- zero : M
- nsmul : ℕ → M → M
- nsmul_zero : ∀ (x : M), AddLeftCancelMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : M), AddLeftCancelMonoid.nsmul (n + 1) x = x + AddLeftCancelMonoid.nsmul n x
Addition is commutative in an commutative additive magma.
Instances
Commutative version of CancelMonoid
.
- mul : M → M → M
- one : M
- npow : ℕ → M → M
- npow_zero : ∀ (x : M), LeftCancelMonoid.npow 0 x = 1
- npow_succ : ∀ (n : ℕ) (x : M), LeftCancelMonoid.npow (n + 1) x = x * LeftCancelMonoid.npow n x
Multiplication is commutative in a commutative multiplicative magma.
Instances
Equations
- AddCancelCommMonoid.toAddCancelMonoid M = let __src := ⋯; AddCancelMonoid.mk ⋯
Equations
- CancelCommMonoid.toCancelMonoid M = let __src := ⋯; CancelMonoid.mk ⋯
Any AddCancelMonoid G
satisfies IsCancelAdd G
.
Equations
- ⋯ = ⋯
Any CancelMonoid G
satisfies IsCancelMul G
.
Equations
- ⋯ = ⋯
The fundamental power operation in a group. zpowRec n a = a*a*...*a
n times, for integer n
.
Use instead a ^ n
, which has better definitional behavior.
Equations
Instances For
The fundamental scalar multiplication in an additive group. zpowRec n a = a+a+...+a
n
times, for integer n
. Use instead n • a
, which has better definitional behavior.
Equations
Instances For
Design note on DivInvMonoid
/SubNegMonoid
and DivisionMonoid
/SubtractionMonoid
#
Those two pairs of made-up classes fulfill slightly different roles.
DivInvMonoid
/SubNegMonoid
provides the minimum amount of information to define the
ℤ
action (zpow
or zsmul
). Further, it provides a div
field, matching the forgetful
inheritance pattern. This is useful to shorten extension clauses of stronger structures (Group
,
GroupWithZero
, DivisionRing
, Field
) and for a few structures with a rather weak
pseudo-inverse (Matrix
).
DivisionMonoid
/SubtractionMonoid
is targeted at structures with stronger pseudo-inverses. It
is an ad hoc collection of axioms that are mainly respected by three things:
- Groups
- Groups with zero
- The pointwise monoids
Set α
,Finset α
,Filter α
It acts as a middle ground for structures with an inversion operator that plays well with
multiplication, except for the fact that it might not be a true inverse (a / a ≠ 1
in general).
The axioms are pretty arbitrary (many other combinations are equivalent to it), but they are
independent:
- Without
DivisionMonoid.div_eq_mul_inv
, you can define/
arbitrarily. - Without
DivisionMonoid.inv_inv
, you can considerWithTop Unit
witha⁻¹ = ⊤
for alla
. - Without
DivisionMonoid.mul_inv_rev
, you can considerWithTop α
witha⁻¹ = a
for alla
whereα
non commutative. - Without
DivisionMonoid.inv_eq_of_mul
, you can consider anyCommMonoid
witha⁻¹ = a
for alla
.
As a consequence, a few natural structures do not fit in this framework. For example, ENNReal
respects everything except for the fact that (0 * ∞)⁻¹ = 0⁻¹ = ∞
while ∞⁻¹ * 0⁻¹ = 0 * ∞ = 0
.
In a class equipped with instances of both Monoid
and Inv
, this definition records what the
default definition for Div
would be: a * b⁻¹
. This is later provided as the default value for
the Div
instance in DivInvMonoid
.
We keep it as a separate definition rather than inlining it in DivInvMonoid
so that the Div
field of individual DivInvMonoid
s constructed using that default value will not be unfolded at
.instance
transparency.
Equations
- DivInvMonoid.div' a b = a * b⁻¹
Instances For
A DivInvMonoid
is a Monoid
with operations /
and ⁻¹
satisfying
div_eq_mul_inv : ∀ a b, a / b = a * b⁻¹
.
This deduplicates the name div_eq_mul_inv
.
The default for div
is such that a / b = a * b⁻¹
holds by definition.
Adding div
as a field rather than defining a / b := a * b⁻¹
allows us to
avoid certain classes of unification failures, for example:
Let Foo X
be a type with a ∀ X, Div (Foo X)
instance but no
∀ X, Inv (Foo X)
, e.g. when Foo X
is a EuclideanDomain
. Suppose we
also have an instance ∀ X [Cromulent X], GroupWithZero (Foo X)
. Then the
(/)
coming from GroupWithZero.div
cannot be definitionally equal to
the (/)
coming from Foo.Div
.
In the same way, adding a zpow
field makes it possible to avoid definitional failures
in diamonds. See the definition of Monoid
and Note [forgetful inheritance] for more
explanations on this.
- mul : G → G → G
- one : G
- npow : ℕ → G → G
- npow_zero : ∀ (x : G), Monoid.npow 0 x = 1
- npow_succ : ∀ (n : ℕ) (x : G), Monoid.npow (n + 1) x = x * Monoid.npow n x
- inv : G → G
- div : G → G → G
a / b := a * b⁻¹
- zpow : ℤ → G → G
The power operation:
a ^ n = a * ··· * a
;a ^ (-n) = a⁻¹ * ··· a⁻¹
(n
times) - zpow_zero' : ∀ (a : G), DivInvMonoid.zpow 0 a = 1
a ^ 0 = 1
- zpow_succ' : ∀ (n : ℕ) (a : G), DivInvMonoid.zpow (Int.ofNat (Nat.succ n)) a = a * DivInvMonoid.zpow (Int.ofNat n) a
a ^ (n + 1) = a * a ^ n
- zpow_neg' : ∀ (n : ℕ) (a : G), DivInvMonoid.zpow (Int.negSucc n) a = (DivInvMonoid.zpow (↑(Nat.succ n)) a)⁻¹
a ^ -(n + 1) = (a ^ (n + 1))⁻¹
Instances
In a class equipped with instances of both AddMonoid
and Neg
, this definition records what
the default definition for Sub
would be: a + -b
. This is later provided as the default value
for the Sub
instance in SubNegMonoid
.
We keep it as a separate definition rather than inlining it in SubNegMonoid
so that the Sub
field of individual SubNegMonoid
s constructed using that default value will not be unfolded at
.instance
transparency.
Equations
- SubNegMonoid.sub' a b = a + -b
Instances For
A SubNegMonoid
is an AddMonoid
with unary -
and binary -
operations
satisfying sub_eq_add_neg : ∀ a b, a - b = a + -b
.
The default for sub
is such that a - b = a + -b
holds by definition.
Adding sub
as a field rather than defining a - b := a + -b
allows us to
avoid certain classes of unification failures, for example:
Let foo X
be a type with a ∀ X, Sub (Foo X)
instance but no
∀ X, Neg (Foo X)
. Suppose we also have an instance
∀ X [Cromulent X], AddGroup (Foo X)
. Then the (-)
coming from
AddGroup.sub
cannot be definitionally equal to the (-)
coming from
Foo.Sub
.
In the same way, adding a zsmul
field makes it possible to avoid definitional failures
in diamonds. See the definition of AddMonoid
and Note [forgetful inheritance] for more
explanations on this.
- add : G → G → G
- zero : G
- nsmul : ℕ → G → G
- nsmul_zero : ∀ (x : G), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : G), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- neg : G → G
- sub : G → G → G
- zsmul : ℤ → G → G
Multiplication by an integer. Set this to
zsmulRec
unlessModule
diamonds are possible. - zsmul_zero' : ∀ (a : G), SubNegMonoid.zsmul 0 a = 0
- zsmul_succ' : ∀ (n : ℕ) (a : G), SubNegMonoid.zsmul (Int.ofNat (Nat.succ n)) a = a + SubNegMonoid.zsmul (Int.ofNat n) a
- zsmul_neg' : ∀ (n : ℕ) (a : G), SubNegMonoid.zsmul (Int.negSucc n) a = -SubNegMonoid.zsmul (↑(Nat.succ n)) a
Instances
Equations
- DivInvMonoid.Pow = { pow := fun (x : M) (n : ℤ) => DivInvMonoid.zpow n x }
Equations
- SubNegMonoid.SMulInt = { smul := SubNegMonoid.zsmul }
Alias of zpow_natCast
.
Alias of natCast_zsmul
.
Subtracting an element is the same as adding by its negative.
This is a duplicate of SubNegMonoid.sub_eq_mul_neg
ensuring that the types unfold better.
Dividing by an element is the same as multiplying by its inverse.
This is a duplicate of DivInvMonoid.div_eq_mul_inv
ensuring that the types unfold better.
Alias of div_eq_mul_inv
.
Dividing by an element is the same as multiplying by its inverse.
This is a duplicate of DivInvMonoid.div_eq_mul_inv
ensuring that the types unfold better.
A SubNegMonoid
where -0 = 0
.
- add : G → G → G
- zero : G
- nsmul : ℕ → G → G
- nsmul_zero : ∀ (x : G), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : G), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- neg : G → G
- sub : G → G → G
- zsmul : ℤ → G → G
- zsmul_zero' : ∀ (a : G), SubNegMonoid.zsmul 0 a = 0
- zsmul_succ' : ∀ (n : ℕ) (a : G), SubNegMonoid.zsmul (Int.ofNat (Nat.succ n)) a = a + SubNegMonoid.zsmul (Int.ofNat n) a
- zsmul_neg' : ∀ (n : ℕ) (a : G), SubNegMonoid.zsmul (Int.negSucc n) a = -SubNegMonoid.zsmul (↑(Nat.succ n)) a
- neg_zero : -0 = 0
Instances
A DivInvMonoid
where 1⁻¹ = 1
.
- mul : G → G → G
- one : G
- npow : ℕ → G → G
- npow_zero : ∀ (x : G), Monoid.npow 0 x = 1
- npow_succ : ∀ (n : ℕ) (x : G), Monoid.npow (n + 1) x = x * Monoid.npow n x
- inv : G → G
- div : G → G → G
- zpow : ℤ → G → G
- zpow_zero' : ∀ (a : G), DivInvMonoid.zpow 0 a = 1
- zpow_succ' : ∀ (n : ℕ) (a : G), DivInvMonoid.zpow (Int.ofNat (Nat.succ n)) a = a * DivInvMonoid.zpow (Int.ofNat n) a
- zpow_neg' : ∀ (n : ℕ) (a : G), DivInvMonoid.zpow (Int.negSucc n) a = (DivInvMonoid.zpow (↑(Nat.succ n)) a)⁻¹
Instances
A SubtractionMonoid
is a SubNegMonoid
with involutive negation and such that
-(a + b) = -b + -a
and a + b = 0 → -a = b
.
- add : G → G → G
- zero : G
- nsmul : ℕ → G → G
- nsmul_zero : ∀ (x : G), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : G), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- neg : G → G
- sub : G → G → G
- zsmul : ℤ → G → G
- zsmul_zero' : ∀ (a : G), SubNegMonoid.zsmul 0 a = 0
- zsmul_succ' : ∀ (n : ℕ) (a : G), SubNegMonoid.zsmul (Int.ofNat (Nat.succ n)) a = a + SubNegMonoid.zsmul (Int.ofNat n) a
- zsmul_neg' : ∀ (n : ℕ) (a : G), SubNegMonoid.zsmul (Int.negSucc n) a = -SubNegMonoid.zsmul (↑(Nat.succ n)) a
Instances
A DivisionMonoid
is a DivInvMonoid
with involutive inversion and such that
(a * b)⁻¹ = b⁻¹ * a⁻¹
and a * b = 1 → a⁻¹ = b
.
This is the immediate common ancestor of Group
and GroupWithZero
.
- mul : G → G → G
- one : G
- npow : ℕ → G → G
- npow_zero : ∀ (x : G), Monoid.npow 0 x = 1
- npow_succ : ∀ (n : ℕ) (x : G), Monoid.npow (n + 1) x = x * Monoid.npow n x
- inv : G → G
- div : G → G → G
- zpow : ℤ → G → G
- zpow_zero' : ∀ (a : G), DivInvMonoid.zpow 0 a = 1
- zpow_succ' : ∀ (n : ℕ) (a : G), DivInvMonoid.zpow (Int.ofNat (Nat.succ n)) a = a * DivInvMonoid.zpow (Int.ofNat n) a
- zpow_neg' : ∀ (n : ℕ) (a : G), DivInvMonoid.zpow (Int.negSucc n) a = (DivInvMonoid.zpow (↑(Nat.succ n)) a)⁻¹
Instances
Commutative SubtractionMonoid
.
- add : G → G → G
- zero : G
- nsmul : ℕ → G → G
- nsmul_zero : ∀ (x : G), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : G), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- neg : G → G
- sub : G → G → G
- zsmul : ℤ → G → G
- zsmul_zero' : ∀ (a : G), SubNegMonoid.zsmul 0 a = 0
- zsmul_succ' : ∀ (n : ℕ) (a : G), SubNegMonoid.zsmul (Int.ofNat (Nat.succ n)) a = a + SubNegMonoid.zsmul (Int.ofNat n) a
- zsmul_neg' : ∀ (n : ℕ) (a : G), SubNegMonoid.zsmul (Int.negSucc n) a = -SubNegMonoid.zsmul (↑(Nat.succ n)) a
Addition is commutative in an commutative additive magma.
Instances
Commutative DivisionMonoid
.
This is the immediate common ancestor of CommGroup
and CommGroupWithZero
.
- mul : G → G → G
- one : G
- npow : ℕ → G → G
- npow_zero : ∀ (x : G), Monoid.npow 0 x = 1
- npow_succ : ∀ (n : ℕ) (x : G), Monoid.npow (n + 1) x = x * Monoid.npow n x
- inv : G → G
- div : G → G → G
- zpow : ℤ → G → G
- zpow_zero' : ∀ (a : G), DivInvMonoid.zpow 0 a = 1
- zpow_succ' : ∀ (n : ℕ) (a : G), DivInvMonoid.zpow (Int.ofNat (Nat.succ n)) a = a * DivInvMonoid.zpow (Int.ofNat n) a
- zpow_neg' : ∀ (n : ℕ) (a : G), DivInvMonoid.zpow (Int.negSucc n) a = (DivInvMonoid.zpow (↑(Nat.succ n)) a)⁻¹
Multiplication is commutative in a commutative multiplicative magma.
Instances
A Group
is a Monoid
with an operation ⁻¹
satisfying a⁻¹ * a = 1
.
There is also a division operation /
such that a / b = a * b⁻¹
,
with a default so that a / b = a * b⁻¹
holds by definition.
Use Group.ofLeftAxioms
or Group.ofRightAxioms
to define a group structure
on a type with the minumum proof obligations.
- mul : G → G → G
- one : G
- npow : ℕ → G → G
- npow_zero : ∀ (x : G), Monoid.npow 0 x = 1
- npow_succ : ∀ (n : ℕ) (x : G), Monoid.npow (n + 1) x = x * Monoid.npow n x
- inv : G → G
- div : G → G → G
- zpow : ℤ → G → G
- zpow_zero' : ∀ (a : G), DivInvMonoid.zpow 0 a = 1
- zpow_succ' : ∀ (n : ℕ) (a : G), DivInvMonoid.zpow (Int.ofNat (Nat.succ n)) a = a * DivInvMonoid.zpow (Int.ofNat n) a
- zpow_neg' : ∀ (n : ℕ) (a : G), DivInvMonoid.zpow (Int.negSucc n) a = (DivInvMonoid.zpow (↑(Nat.succ n)) a)⁻¹
Instances
An AddGroup
is an AddMonoid
with a unary -
satisfying -a + a = 0
.
There is also a binary operation -
such that a - b = a + -b
,
with a default so that a - b = a + -b
holds by definition.
Use AddGroup.ofLeftAxioms
or AddGroup.ofRightAxioms
to define an
additive group structure on a type with the minumum proof obligations.
- add : A → A → A
- zero : A
- nsmul : ℕ → A → A
- nsmul_zero : ∀ (x : A), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : A), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- neg : A → A
- sub : A → A → A
- zsmul : ℤ → A → A
- zsmul_zero' : ∀ (a : A), SubNegMonoid.zsmul 0 a = 0
- zsmul_succ' : ∀ (n : ℕ) (a : A), SubNegMonoid.zsmul (Int.ofNat (Nat.succ n)) a = a + SubNegMonoid.zsmul (Int.ofNat n) a
- zsmul_neg' : ∀ (n : ℕ) (a : A), SubNegMonoid.zsmul (Int.negSucc n) a = -SubNegMonoid.zsmul (↑(Nat.succ n)) a
Instances
Equations
- AddGroup.toSubtractionMonoid = SubtractionMonoid.mk ⋯ ⋯ ⋯
Equations
- Group.toDivisionMonoid = DivisionMonoid.mk ⋯ ⋯ ⋯
Equations
- AddGroup.toAddCancelMonoid = let __src := inst; AddCancelMonoid.mk ⋯
Equations
- Group.toCancelMonoid = let __src := inst; CancelMonoid.mk ⋯
An additive commutative group is an additive group with commutative (+)
.
- add : G → G → G
- zero : G
- nsmul : ℕ → G → G
- nsmul_zero : ∀ (x : G), AddMonoid.nsmul 0 x = 0
- nsmul_succ : ∀ (n : ℕ) (x : G), AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
- neg : G → G
- sub : G → G → G
- zsmul : ℤ → G → G
- zsmul_zero' : ∀ (a : G), SubNegMonoid.zsmul 0 a = 0
- zsmul_succ' : ∀ (n : ℕ) (a : G), SubNegMonoid.zsmul (Int.ofNat (Nat.succ n)) a = a + SubNegMonoid.zsmul (Int.ofNat n) a
- zsmul_neg' : ∀ (n : ℕ) (a : G), SubNegMonoid.zsmul (Int.negSucc n) a = -SubNegMonoid.zsmul (↑(Nat.succ n)) a
Addition is commutative in an commutative additive magma.
Instances
A commutative group is a group with commutative (*)
.
- mul : G → G → G
- one : G
- npow : ℕ → G → G
- npow_zero : ∀ (x : G), Monoid.npow 0 x = 1
- npow_succ : ∀ (n : ℕ) (x : G), Monoid.npow (n + 1) x = x * Monoid.npow n x
- inv : G → G
- div : G → G → G
- zpow : ℤ → G → G
- zpow_zero' : ∀ (a : G), DivInvMonoid.zpow 0 a = 1
- zpow_succ' : ∀ (n : ℕ) (a : G), DivInvMonoid.zpow (Int.ofNat (Nat.succ n)) a = a * DivInvMonoid.zpow (Int.ofNat n) a
- zpow_neg' : ∀ (n : ℕ) (a : G), DivInvMonoid.zpow (Int.negSucc n) a = (DivInvMonoid.zpow (↑(Nat.succ n)) a)⁻¹
Multiplication is commutative in a commutative multiplicative magma.
Instances
Equations
- AddCommGroup.toAddCancelCommMonoid = let __src := inst; let __src_1 := AddGroup.toAddCancelMonoid; AddCancelCommMonoid.mk ⋯
Equations
- CommGroup.toCancelCommMonoid = let __src := inst; let __src_1 := Group.toCancelMonoid; CancelCommMonoid.mk ⋯
Equations
- AddCommGroup.toDivisionAddCommMonoid = let __src := inst; let __src_1 := AddGroup.toSubtractionMonoid; SubtractionCommMonoid.mk ⋯
Equations
- CommGroup.toDivisionCommMonoid = let __src := inst; let __src_1 := Group.toDivisionMonoid; DivisionCommMonoid.mk ⋯
We initialize all projections for @[simps]
here, so that we don't have to do it in later
files.
Note: the lemmas generated for the npow
/zpow
projections will not apply to x ^ y
, since the
argument order of these projections doesn't match the argument order of ^
.
The nsmul
/zsmul
lemmas will be correct.