# Extending the interface of AbstractAlgebra.jl

In this section we will discuss on how to extend the interface of AbstractAlgebra.jl.

## Elements and parents

Any implementation with elements and parents should implement the following interface:

parentFunction
parent(a)

Return parent object of given element $a$.

Examples

julia> G = SymmetricGroup(5); g = Perm([3,4,5,2,1])
(1,3,5)(2,4)

julia> parent(g) == G
true

julia> S, x = laurent_series_ring(ZZ, 3, "x")
(Laurent series ring in x over Integers, x + O(x^4))

julia> parent(x) == S
true
elem_typeFunction
elem_type(::Type{T}) where T <: GAPGroup
elem_type(::T) where T <: GAPGroup

elem_type maps (the type of) a group to the type of its elements. For now, a group of type T has elements of type BasicGAPGroupElem{T}. So we provide it mostly for consistency with other parts of OSCAR. In the future, a more elaborate setup for group element types might also be needed.

source
elem_type(parent)
elem_type(parent_type)

Given a parent object (or its type), return the type of its elements.

Example

julia> S, x = power_series_ring(QQ, 2, "x")
(Univariate power series ring in x over Rationals, x + O(x^3))

julia> elem_type(S) == typeof(x)
true
parent_typeFunction
parent_type(element)
parent_type(element_type)

Given an element (or its type), return the type of its parent object.

Example

julia> R, x = polynomial_ring(ZZ, "x")
(Univariate Polynomial Ring in x over Integers, x)

julia> S = matrix_space(R, 2, 2)
Matrix Space of 2 rows and 2 columns over Univariate Polynomial Ring in x over Integers

julia> a = rand(S, 0:1, 0:1);

julia> parent_type(a) == typeof(S)
true

### Acquiring associated elements and parents

Further, if one has a base ring, like polynomials over the integers $\mathbb{Z}[x]$, then one should implement

base_ringFunction
base_ring(a)

Return base ring $R$ of given element or parent $a$.

Examples

julia> S, x = polynomial_ring(QQ, "x")
(Univariate Polynomial Ring in x over Rationals, x)

julia> base_ring(S) == QQ
true

julia> R = GF(7)
Finite field F_7

julia> base_ring(R)
Union{}

## Special elements

For rings, one has to extend the following methods:

oneFunction
one(a)

Return the multiplicative identity in the algebraic structure of $a$, which can be either an element or parent.

Examples

julia> S = matrix_space(ZZ, 2, 2)
Matrix Space of 2 rows and 2 columns over Integers

julia> one(S)
[1   0]
[0   1]

julia> R, x = PuiseuxSeriesField(QQ, 4, "x")
(Puiseux series field in x over Rationals, x + O(x^5))

julia> one(x)
1 + O(x^4)

julia> G = GF(5)
Finite field F_5

julia> one(G)
1
zeroFunction
zero(a)

Return the additive identity in the algebraic structure of $a$, which can be either an element or parent.

Examples

julia> S = MatrixAlgebra(QQ, 2)
Matrix Algebra of degree 2 over Rationals

julia> zero(S)
[0//1   0//1]
[0//1   0//1]

julia> R, x = polynomial_ring(ZZ, "x")
(Univariate Polynomial Ring in x over Integers, x)

julia> zero(x^3 + 2)
0

Groups should only extend at least one of these. The one that is required depends on if the group is additive (commutative) or multiplicative.

## Basic manipulation

If one would like to implement a ring, these are the basic manipulation methods that all rings should extend:

isoneFunction
isone(a)

Return true if $a$ is the multiplicative identity, else return false.

Examples

julia> S = matrix_space(ZZ, 2, 2); T = matrix_space(ZZ, 2, 3); U = matrix_space(ZZ, 3, 2);

julia> isone(S([1 0; 0 1]))
true

julia> isone(T([1 0 0; 0 1 0]))
false

julia> isone(U([1 0; 0 1; 0 0]))
false

julia> T, x = PuiseuxSeriesField(QQ, 10, "x")
(Puiseux series field in x over Rationals, x + O(x^11))

julia> isone(x), isone(T(1))
(false, true)
iszeroFunction
iszero(a)

Return true if $a$ is the additative identity, else return false.

Examples

julia> T, x = PuiseuxSeriesField(QQ, 10, "x")
(Puiseux series field in x over Rationals, x + O(x^11))

julia> a = T(0)
O(x^10)

julia> iszero(a)
true
is_unitFunction
is_unit(a::T) where {T <: NCRingElem}

Return true if $a$ is invertible, else return false.

Examples

julia> S, x = polynomial_ring(QQ, "x")
(Univariate Polynomial Ring in x over Rationals, x)

julia> is_unit(x), is_unit(S(1)), is_unit(S(4))
(false, true, true)

julia> is_unit(ZZ(-1)), is_unit(ZZ(4))
(true, false)

With the same logic as earlier, groups only need to extend one of the methods isone and iszero.