mathlib documentation

algebra.group.defs

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

For basic lemmas about these classes see algebra.group.basic.

We also introduce notation classes has_scalar and has_vadd for multiplicative and additive actions and register the following instances:

Notation #

@[class]
structure has_vsub (G : out_param (Type u_1)) (P : Type u_2) :
Type (max u_1 u_2)
  • vsub : P → P → G

Type class for the -ᵥ notation.

Instances
@[ext, class]
structure has_scalar (M : Type u_1) (α : Type u_2) :
Type (max u_1 u_2)
  • smul : M → α → α

Typeclass for types with a scalar multiplication operation, denoted (\bu)

Instances
theorem has_scalar.ext {M : Type u_1} {α : Type u_2} (x y : has_scalar M α) (h : has_scalar.smul = has_scalar.smul) :
x = y
theorem has_scalar.ext_iff {M : Type u_1} {α : Type u_2} (x y : has_scalar M α) :

The simpset field_simps is used by the tactic field_simp to reduce an expression in a field to an expression of the form n / d where n and d are division-free.

def left_mul {G : Type u} [has_mul G] :
G → G → G

left_mul g denotes left multiplication by g

Equations
def left_add {G : Type u} [has_add G] :
G → G → G

left_add g denotes left addition by g

Equations
def right_add {G : Type u} [has_add G] :
G → G → G

right_add g denotes right addition by g

Equations
def right_mul {G : Type u} [has_mul G] :
G → G → G

right_mul g denotes right multiplication by g

Equations
theorem semigroup.ext_iff {G : Type u} (x y : semigroup G) :
theorem semigroup.ext {G : Type u} (x y : semigroup G) (h : semigroup.mul = semigroup.mul) :
x = y
@[instance]
def semigroup.to_has_mul (G : Type u) [self : semigroup G] :
@[instance]
def add_semigroup.to_has_add (G : Type u) [self : add_semigroup G] :
theorem add_semigroup.ext {G : Type u} (x y : add_semigroup G) (h : add_semigroup.add = add_semigroup.add) :
x = y
theorem add_assoc {G : Type u} [add_semigroup G] (a b c : G) :
a + b + c = a + (b + c)
theorem mul_assoc {G : Type u} [semigroup G] (a b c : G) :
(a * b) * c = a * b * c
@[protected, instance]
@[protected, instance]
@[instance]
def comm_semigroup.to_semigroup (G : Type u) [self : comm_semigroup G] :
theorem comm_semigroup.ext {G : Type u} (x y : comm_semigroup G) (h : comm_semigroup.mul = comm_semigroup.mul) :
x = y
@[instance]
theorem add_comm {G : Type u} [add_comm_semigroup G] (a b : G) :
a + b = b + a
theorem mul_comm {G : Type u} [comm_semigroup G] (a b : G) :
a * b = b * a
@[protected, instance]
@[instance]
@[ext, class]
structure left_cancel_semigroup (G : Type u) :
Type u
  • mul : G → G → G
  • mul_assoc : ∀ (a b c : G), (a * b) * c = a * b * c
  • mul_left_cancel : ∀ (a b c : G), a * b = a * cb = c

A left_cancel_semigroup is a semigroup such that a * b = a * c implies b = c.

Instances
@[ext, class]
structure add_left_cancel_semigroup (G : Type u) :
Type u
  • add : G → G → G
  • add_assoc : ∀ (a b c : G), a + b + c = a + (b + c)
  • add_left_cancel : ∀ (a b c : G), a + b = a + cb = c

An add_left_cancel_semigroup is an additive semigroup such that a + b = a + c implies b = c.

Instances
theorem mul_left_cancel {G : Type u} [left_cancel_semigroup G] {a b c : G} :
a * b = a * cb = c
theorem add_left_cancel {G : Type u} [add_left_cancel_semigroup G] {a b c : G} :
a + b = a + cb = c
theorem add_left_cancel_iff {G : Type u} [add_left_cancel_semigroup G] {a b c : G} :
a + b = a + c b = c
theorem mul_left_cancel_iff {G : Type u} [left_cancel_semigroup G] {a b c : G} :
a * b = a * c b = c
@[simp]
theorem mul_right_inj {G : Type u} [left_cancel_semigroup G] (a : G) {b c : G} :
a * b = a * c b = c
@[simp]
theorem add_right_inj {G : Type u} [add_left_cancel_semigroup G] (a : G) {b c : G} :
a + b = a + c b = c
theorem mul_ne_mul_right {G : Type u} [left_cancel_semigroup G] (a : G) {b c : G} :
a * b a * c b c
theorem add_ne_add_right {G : Type u} [add_left_cancel_semigroup G] (a : G) {b c : G} :
a + b a + c b c
@[ext, class]
structure right_cancel_semigroup (G : Type u) :
Type u
  • mul : G → G → G
  • mul_assoc : ∀ (a b c : G), (a * b) * c = a * b * c
  • mul_right_cancel : ∀ (a b c : G), a * b = c * ba = c

A right_cancel_semigroup is a semigroup such that a * b = c * b implies a = c.

Instances
@[instance]
@[ext, class]
structure add_right_cancel_semigroup (G : Type u) :
Type u
  • add : G → G → G
  • add_assoc : ∀ (a b c : G), a + b + c = a + (b + c)
  • add_right_cancel : ∀ (a b c : G), a + b = c + ba = c

An add_right_cancel_semigroup is an additive semigroup such that a + b = c + b implies a = c.

Instances
theorem mul_right_cancel {G : Type u} [right_cancel_semigroup G] {a b c : G} :
a * b = c * ba = c
theorem add_right_cancel {G : Type u} [add_right_cancel_semigroup G] {a b c : G} :
a + b = c + ba = c
theorem mul_right_cancel_iff {G : Type u} [right_cancel_semigroup G] {a b c : G} :
b * a = c * a b = c
theorem add_right_cancel_iff {G : Type u} [add_right_cancel_semigroup G] {a b c : G} :
b + a = c + a b = c
theorem add_left_injective {G : Type u} [add_right_cancel_semigroup G] (a : G) :
function.injective (λ (x : G), x + a)
theorem mul_left_injective {G : Type u} [right_cancel_semigroup G] (a : G) :
function.injective (λ (x : G), x * a)
@[simp]
theorem add_left_inj {G : Type u} [add_right_cancel_semigroup G] (a : G) {b c : G} :
b + a = c + a b = c
@[simp]
theorem mul_left_inj {G : Type u} [right_cancel_semigroup G] (a : G) {b c : G} :
b * a = c * a b = c
theorem mul_ne_mul_left {G : Type u} [right_cancel_semigroup G] (a : G) {b c : G} :
b * a c * a b c
theorem add_ne_add_left {G : Type u} [add_right_cancel_semigroup G] (a : G) {b c : G} :
b + a c + a b c
@[class]
structure mul_one_class (M : Type u) :
Type u
  • one : M
  • mul : M → M → M
  • one_mul : ∀ (a : M), 1 * a = a
  • mul_one : ∀ (a : M), a * 1 = a

Typeclass for expressing that a type M with multiplication and a one satisfies 1 * a = a and a * 1 = a for all a : M.

Instances
@[instance]
def mul_one_class.to_has_one (M : Type u) [self : mul_one_class M] :
@[instance]
def mul_one_class.to_has_mul (M : Type u) [self : mul_one_class M] :
@[instance]
def add_zero_class.to_has_add (M : Type u) [self : add_zero_class M] :
@[instance]
def add_zero_class.to_has_zero (M : Type u) [self : add_zero_class M] :
@[ext]
theorem mul_one_class.ext {M : Type u} ⦃m₁ m₂ : mul_one_class M⦄ :
theorem add_zero_class.ext {M : Type u} ⦃m₁ m₂ : add_zero_class M⦄ :
@[simp]
theorem one_mul {M : Type u} [mul_one_class M] (a : M) :
1 * a = a
@[simp]
theorem zero_add {M : Type u} [add_zero_class M] (a : M) :
0 + a = a
@[simp]
theorem add_zero {M : Type u} [add_zero_class M] (a : M) :
a + 0 = a
@[simp]
theorem mul_one {M : Type u} [mul_one_class M] (a : M) :
a * 1 = a
@[protected, instance]
@[protected, instance]
@[protected, instance]
@[protected, instance]
def npow_rec {M : Type u} [has_one M] [has_mul M] :
M → M

The fundamental power operation in a monoid. npow_rec n a = a*a*...*a n times. Use instead a ^ n, which has better definitional behavior.

Equations
def nsmul_rec {M : Type u} [has_zero M] [has_add M] :
M → M

The fundamental scalar multiplication in an additive monoid. nsmul_rec n a = a+a+...+a n times. Use instead n • a, which has better definitional behavior.

Equations
meta def try_refl_tac  :

try_refl_tac solves goals of the form ∀ a b, f a b = g a b, if they hold by definition.

Design note on add_monoid and monoid #

An add_monoid 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 add_monoid (which is by default equal to the naive action a + ... + a, but can be adjusted when needed), and declare a has_scalar ℕ α 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 add_monoid). In this way, the two natural has_scalar ℕ (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.group_power.basic. For now, we only register the most basic properties that we need right away.

In the definition, we use n.succ instead of n + 1 in the nsmul_succ' and npow_succ' fields to make sure that to_additive is not confused (otherwise, it would try to convert 1 : ℕ to 0 : ℕ).

@[instance]
def add_monoid.to_add_semigroup (M : Type u) [self : add_monoid M] :
@[instance]
def add_monoid.to_add_zero_class (M : Type u) [self : add_monoid M] :
@[instance]
def monoid.to_mul_one_class (M : Type u) [self : monoid M] :
@[instance]
def monoid.to_semigroup (M : Type u) [self : monoid M] :
@[protected, instance]
def monoid.has_pow {M : Type u_1} [monoid M] :
Equations
@[protected, instance]
def add_monoid.has_scalar_nat {M : Type u_1} [add_monoid M] :
Equations
@[simp]
theorem npow_eq_pow {M : Type u_1} [monoid M] (n : ) (x : M) :
monoid.npow n x = x ^ n
@[simp]
theorem nsmul_eq_smul {M : Type u_1} [add_monoid M] (n : ) (x : M) :
theorem zero_nsmul {M : Type u_1} [add_monoid M] (a : M) :
0 a = 0
@[simp]
theorem pow_zero {M : Type u_1} [monoid M] (a : M) :
a ^ 0 = 1
theorem succ_nsmul {M : Type u_1} [add_monoid M] (a : M) (n : ) :
(n + 1) a = a + n a
theorem pow_succ {M : Type u_1} [monoid M] (a : M) (n : ) :
a ^ (n + 1) = a * a ^ n
theorem left_inv_eq_right_inv {M : Type u} [monoid M] {a b c : M} (hba : b * a = 1) (hac : a * c = 1) :
b = c
theorem left_neg_eq_right_neg {M : Type u} [add_monoid M] {a b c : M} (hba : b + a = 0) (hac : a + c = 0) :
b = c
@[instance]
def add_comm_monoid.to_add_monoid (M : Type u) [self : add_comm_monoid M] :
@[class]
structure add_comm_monoid (M : Type u) :
Type u

An additive commutative monoid is an additive monoid with commutative (+).

Instances
@[instance]
def comm_monoid.to_comm_semigroup (M : Type u) [self : comm_monoid M] :
@[instance]
def comm_monoid.to_monoid (M : Type u) [self : comm_monoid M] :
@[instance]
@[class]
structure add_left_cancel_monoid (M : Type u) :
Type u

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 add_left_cancel_semigroup is not enough.

Instances
@[class]
structure left_cancel_monoid (M : Type u) :
Type u

A monoid in which multiplication is left-cancellative.

Instances
@[instance]
def left_cancel_monoid.to_monoid (M : Type u) [self : left_cancel_monoid M] :
@[class]
structure add_right_cancel_monoid (M : Type u) :
Type u

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 add_right_cancel_semigroup is not enough.

Instances
@[instance]
def right_cancel_monoid.to_monoid (M : Type u) [self : right_cancel_monoid M] :
@[class]
structure right_cancel_monoid (M : Type u) :
Type u

A monoid in which multiplication is right-cancellative.

Instances
@[class]
structure add_cancel_monoid (M : Type u) :
Type u

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 add_right_cancel_semigroup is not enough.

Instances
@[instance]
@[class]
structure cancel_monoid (M : Type u) :
Type u
  • mul : M → M → M
  • mul_assoc : ∀ (a b c : M), (a * b) * c = a * b * c
  • mul_left_cancel : ∀ (a b c : M), a * b = a * cb = c
  • one : M
  • one_mul : ∀ (a : M), 1 * a = a
  • mul_one : ∀ (a : M), a * 1 = a
  • npow : M → M
  • npow_zero' : (∀ (x : M), cancel_monoid.npow 0 x = 1) . "try_refl_tac"
  • npow_succ' : (∀ (n : ) (x : M), cancel_monoid.npow n.succ x = x * cancel_monoid.npow n x) . "try_refl_tac"
  • mul_right_cancel : ∀ (a b c : M), a * b = c * ba = c

A monoid in which multiplication is cancellative.

Instances
@[instance]
@[class]
structure add_cancel_comm_monoid (M : Type u) :
Type u

Commutative version of add_cancel_monoid.

Instances
@[instance]
@[class]
structure cancel_comm_monoid (M : Type u) :
Type u

Commutative version of cancel_monoid.

Instances
def zpow_rec {M : Type u_1} [has_one M] [has_mul M] [has_inv M] :
M → M

The fundamental power operation in a group. zpow_rec n a = a*a*...*a n times, for integer n. Use instead a ^ n, which has better definitional behavior.

Equations
def zsmul_rec {M : Type u_1} [has_zero M] [has_add M] [has_neg M] :
M → M

The fundamental scalar multiplication in an additive group. zsmul_rec n a = a+a+...+a n times, for integer n. Use instead n • a, which has better definitional behavior.

Equations
@[instance]
def div_inv_monoid.to_monoid (G : Type u) [self : div_inv_monoid G] :
@[instance]
def div_inv_monoid.to_has_div (G : Type u) [self : div_inv_monoid G] :
@[class]
structure div_inv_monoid (G : Type u) :
Type u

A div_inv_monoid is a monoid with operations / and ⁻¹ satisfying div_eq_mul_inv : ∀ a b, a / b = a * b⁻¹.

This is the immediate common ancestor of group and group_with_zero, in order to deduplicate 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, has_div (foo X) instance but no ∀ X, has_inv (foo X), e.g. when foo X is a euclidean_domain. Suppose we also have an instance ∀ X [cromulent X], group_with_zero (foo X). Then the (/) coming from group_with_zero_has_div cannot be definitionally equal to the (/) coming from foo.has_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.

Instances
@[instance]
def div_inv_monoid.to_has_inv (G : Type u) [self : div_inv_monoid G] :
@[instance]
def sub_neg_monoid.to_has_sub (G : Type u) [self : sub_neg_monoid G] :
@[instance]
def sub_neg_monoid.to_add_monoid (G : Type u) [self : sub_neg_monoid G] :
@[class]
structure sub_neg_monoid (G : Type u) :
Type u

A sub_neg_monoid is an add_monoid 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, has_sub (foo X) instance but no ∀ X, has_neg (foo X). Suppose we also have an instance ∀ X [cromulent X], add_group (foo X). Then the (-) coming from add_group.has_sub cannot be definitionally equal to the (-) coming from foo.has_sub.

In the same way, adding a zsmul field makes it possible to avoid definitional failures in diamonds. See the definition of add_monoid and Note [forgetful inheritance] for more explanations on this.

Instances
@[instance]
def sub_neg_monoid.to_has_neg (G : Type u) [self : sub_neg_monoid G] :
@[protected, instance]
def div_inv_monoid.has_pow {M : Type u_1} [div_inv_monoid M] :
Equations
@[protected, instance]
Equations
@[simp]
theorem zsmul_eq_smul {G : Type u_1} [sub_neg_monoid G] (n : ) (x : G) :
@[simp]
theorem zpow_eq_pow {G : Type u_1} [div_inv_monoid G] (n : ) (x : G) :
@[simp]
theorem zero_zsmul {G : Type u_1} [sub_neg_monoid G] (a : G) :
0 a = 0
@[simp]
theorem zpow_zero {G : Type u_1} [div_inv_monoid G] (a : G) :
a ^ 0 = 1
@[simp, norm_cast]
theorem coe_nat_zsmul {G : Type u_1} [sub_neg_monoid G] (a : G) (n : ) :
n a = n a
@[simp, norm_cast]
theorem zpow_coe_nat {G : Type u_1} [div_inv_monoid G] (a : G) (n : ) :
a ^ n = a ^ n
theorem of_nat_zsmul {G : Type u_1} [sub_neg_monoid G] (a : G) (n : ) :
theorem zpow_of_nat {G : Type u_1} [div_inv_monoid G] (a : G) (n : ) :
a ^ int.of_nat n = a ^ n
@[simp]
theorem zsmul_neg_succ_of_nat {G : Type u_1} [sub_neg_monoid G] (a : G) (n : ) :
-[1+ n] a = -((n + 1) a)
@[simp]
theorem zpow_neg_succ_of_nat {G : Type u_1} [div_inv_monoid G] (a : G) (n : ) :
a ^ -[1+ n] = (a ^ (n + 1))⁻¹
theorem div_eq_mul_inv {G : Type u} [div_inv_monoid G] (a b : G) :
a / b = a * b⁻¹
theorem sub_eq_add_neg {G : Type u} [sub_neg_monoid G] (a b : G) :
a - b = a + -b
@[instance]
def has_involutive_inv.to_has_inv (G : Type u_1) [self : has_involutive_inv G] :
@[instance]
def has_involutive_neg.to_has_neg (A : Type u_1) [self : has_involutive_neg A] :
@[simp]
theorem inv_inv {G : Type u_1} [has_involutive_inv G] (a : G) :
@[simp]
theorem neg_neg {G : Type u_1} [has_involutive_neg G] (a : G) :
--a = a
@[class]
structure group (G : Type u) :
Type u

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.

Instances
@[instance]
def group.to_div_inv_monoid (G : Type u) [self : group G] :
@[class]
structure add_group (A : Type u) :
Type u

An add_group is an add_monoid 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.

Instances
@[instance]
def add_group.to_sub_neg_monoid (A : Type u) [self : add_group A] :
def add_group.to_add_monoid (G : Type u) [add_group G] :

Abbreviation for @sub_neg_monoid.to_add_monoid _ (@add_group.to_sub_neg_monoid _ _).

Useful because it corresponds to the fact that AddGroup is a subcategory of AddMon. Not an instance since it duplicates @sub_neg_monoid.to_add_monoid _ (@add_group.to_sub_neg_monoid _ _).

Equations
def group.to_monoid (G : Type u) [group G] :

Abbreviation for @div_inv_monoid.to_monoid _ (@group.to_div_inv_monoid _ _).

Useful because it corresponds to the fact that Grp is a subcategory of Mon. Not an instance since it duplicates @div_inv_monoid.to_monoid _ (@group.to_div_inv_monoid _ _). See note [reducible non-instances].

Equations
@[simp]
theorem add_left_neg {G : Type u} [add_group G] (a : G) :
-a + a = 0
@[simp]
theorem mul_left_inv {G : Type u} [group G] (a : G) :
a⁻¹ * a = 1
theorem neg_add_self {G : Type u} [add_group G] (a : G) :
-a + a = 0
theorem inv_mul_self {G : Type u} [group G] (a : G) :
a⁻¹ * a = 1
@[simp]
theorem inv_mul_cancel_left {G : Type u} [group G] (a b : G) :
a⁻¹ * a * b = b
@[simp]
theorem neg_add_cancel_left {G : Type u} [add_group G] (a b : G) :
-a + (a + b) = b
@[simp]
theorem inv_eq_of_mul_eq_one {G : Type u} [group G] {a b : G} (h : a * b = 1) :
a⁻¹ = b
@[simp]
theorem neg_eq_of_add_eq_zero {G : Type u} [add_group G] {a b : G} (h : a + b = 0) :
-a = b
@[simp]
theorem mul_right_inv {G : Type u} [group G] (a : G) :
a * a⁻¹ = 1
@[simp]
theorem add_right_neg {G : Type u} [add_group G] (a : G) :
a + -a = 0
theorem add_neg_self {G : Type u} [add_group G] (a : G) :
a + -a = 0
theorem mul_inv_self {G : Type u} [group G] (a : G) :
a * a⁻¹ = 1
@[simp]
theorem add_neg_cancel_right {G : Type u} [add_group G] (a b : G) :
a + b + -b = a
@[simp]
theorem mul_inv_cancel_right {G : Type u} [group G] (a b : G) :
(a * b) * b⁻¹ = a
@[protected, instance]
def group.to_cancel_monoid {G : Type u} [group G] :
Equations
@[protected, instance]
Equations
@[instance]
def comm_group.to_group (G : Type u) [self : comm_group G] :
@[class]
structure comm_group (G : Type u) :
Type u

A commutative group is a group with commutative (*).

Instances
@[instance]
def comm_group.to_comm_monoid (G : Type u) [self : comm_group G] :
@[class]
structure add_comm_group (G : Type u) :
Type u

An additive commutative group is an additive group with commutative (+).

Instances
@[instance]
@[instance]
def add_comm_group.to_add_group (G : Type u) [self : add_comm_group G] :
@[protected, instance]
Equations