---
title: "Element Operations"
canonical: "https://docs.magma-maths.org/v2.30-1/Algebras/FinitelyPresentedAlgebras/operation-element.html"
source: "https://docs.magma-maths.org/v2.30-1/Algebras/FinitelyPresentedAlgebras/operation-element.md"
part: "Algebras"
chapter: "Finitely Presented Algebras"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Algebras", "source": "https://docs.magma-maths.org/v2.30-1/Algebras/index-algebras.md"}
  - {"title": "Finitely Presented Algebras", "source": "https://docs.magma-maths.org/v2.30-1/Algebras/FinitelyPresentedAlgebras/index-finitely-presented-algebras.md"}
prev: {"title": "Structure Operations", "source": "https://docs.magma-maths.org/v2.30-1/Algebras/FinitelyPresentedAlgebras/operation.md"}
next: {"title": "Ideals and Gröbner Bases", "source": "https://docs.magma-maths.org/v2.30-1/Algebras/FinitelyPresentedAlgebras/ideals.md"}
intrinsics:
  - {"name": "+", "signature": "+ a: AlgFrElt -> AlgFrElt"}
  - {"name": "-", "signature": "- a: AlgFrElt -> AlgFrElt"}
  - {"name": "+", "signature": "a + b: AlgFrElt, AlgFrElt -> AlgFrElt"}
  - {"name": "-", "signature": "a - b: AlgFrElt, AlgFrElt -> AlgFrElt"}
  - {"name": "*", "signature": "a * b: AlgFrElt, AlgFrElt -> AlgFrElt"}
  - {"name": "^", "signature": "a ^ k: AlgFrElt, RngIntElt -> AlgFrElt"}
  - {"name": "/", "signature": "a / b: AlgFrElt, AlgFrElt -> FldFunMElt"}
  - {"name": "div", "signature": "a div b: AlgFrElt, AlgFrElt -> AlgFrElt"}
  - {"name": "+:=", "signature": "a +:= b: AlgFrElt, AlgFrElt -> AlgFrElt"}
  - {"name": "-:=", "signature": "a -:= b: AlgFrElt, AlgFrElt -> AlgFrElt"}
  - {"name": "*:=", "signature": "a *:= b: AlgFrElt, AlgFrElt -> AlgFrElt"}
  - {"name": "div:=", "signature": "a div:= b: AlgFrElt, AlgFrElt -> AlgFrElt"}
  - {"name": "eq", "signature": "a eq b: AlgFrElt, AlgFrElt -> BoolElt"}
  - {"name": "ne", "signature": "a ne b: AlgFrElt, AlgFrElt -> BoolElt"}
  - {"name": "in", "signature": "a in R: AlgFrElt, Rng -> BoolElt"}
  - {"name": "notin", "signature": "a notin R: AlgFrElt, Rng -> BoolElt"}
  - {"name": "IsZero", "signature": "IsZero(f): AlgFrElt -> BoolElt"}
  - {"name": "IsOne", "signature": "IsOne(f): AlgFrElt -> BoolElt"}
  - {"name": "IsMinusOne", "signature": "IsMinusOne(f): AlgFrElt -> BoolElt"}
  - {"name": "IsNilpotent", "signature": "IsNilpotent(f): AlgFrElt -> BoolElt"}
  - {"name": "IsIdempotent", "signature": "IsIdempotent(f): AlgFrElt -> BoolElt"}
  - {"name": "IsUnit", "signature": "IsUnit(f): AlgFrElt -> BoolElt"}
  - {"name": "IsZeroDivisor", "signature": "IsZeroDivisor(f): AlgFrElt -> BoolElt"}
  - {"name": "IsRegular", "signature": "IsRegular(f): AlgFrElt -> BoolElt"}
  - {"name": "IsIrreducible", "signature": "IsIrreducible(f): AlgFrElt -> BoolElt"}
  - {"name": "IsPrime", "signature": "IsPrime(f): AlgFrElt -> BoolElt"}
  - {"name": "Coefficients", "signature": "Coefficients(f): AlgFrElt -> [ RngElt ]"}
  - {"name": "LeadingCoefficient", "signature": "LeadingCoefficient(f): AlgFrElt -> RngElt"}
  - {"name": "TrailingCoefficient", "signature": "TrailingCoefficient(f): AlgFrElt -> RngElt"}
  - {"name": "MonomialCoefficient", "signature": "MonomialCoefficient(f, m): AlgFrElt, AlgFrElt -> RngElt"}
  - {"name": "Monomials", "signature": "Monomials(f): AlgFrElt -> [ AlgFrElt ]"}
  - {"name": "LeadingMonomial", "signature": "LeadingMonomial(f): AlgFrElt -> AlgFrElt"}
  - {"name": "Terms", "signature": "Terms(f): AlgFrElt -> [ AlgFrElt ]"}
  - {"name": "LeadingTerm", "signature": "LeadingTerm(f): AlgFrElt -> AlgFrElt"}
  - {"name": "TrailingTerm", "signature": "TrailingTerm(f): AlgFrElt -> RngElt"}
  - {"name": "Length", "signature": "Length(m): AlgFrElt -> RngIntElt"}
  - {"name": "m[i]", "signature": "m[i]: AlgFrElt, RngIntElt -> AlgFrElt"}
  - {"name": "TotalDegree", "signature": "TotalDegree(f): AlgFrElt -> RngIntElt"}
  - {"name": "LeadingTotalDegree", "signature": "LeadingTotalDegree(f): AlgFrElt -> RngIntElt"}
  - {"name": "Evaluate", "signature": "Evaluate(f, s): AlgFrElt, [ RngElt ] -> RngElt"}
  - {"name": "Evaluate", "signature": "Evaluate(f, s): AlgFrElt, < RngElt, ..., RngElt > -> RngElt"}
examples:
  - "ex-4ecfe7"
  - "ex-88ec97"
---

# Element Operations

## Arithmetic Operators

The usual unary and binary ring operations are available for noncommutative polynomials, noting that multiplication is associative but noncommutative, of course.

<a id="operation-operation-algfrelt-algfrelt"></a>
### `+ a: AlgFrElt -> AlgFrElt`

<a id="operation-operation-algfrelt-algfrelt-2"></a>
### `- a: AlgFrElt -> AlgFrElt`

<a id="operation-op-plus-algfrelt-algfrelt"></a>
### `a + b: AlgFrElt, AlgFrElt -> AlgFrElt`

<a id="operation-op-minus-algfrelt-algfrelt"></a>
### `a - b: AlgFrElt, AlgFrElt -> AlgFrElt`

<a id="operation-op-times-algfrelt-algfrelt"></a>
### `a * b: AlgFrElt, AlgFrElt -> AlgFrElt`

<a id="operation-op-pow-algfrelt-rngintelt"></a>
### `a ^ k: AlgFrElt, RngIntElt -> AlgFrElt`

<a id="operation-op-div-algfrelt-algfrelt"></a>
### `a / b: AlgFrElt, AlgFrElt -> FldFunMElt`

<a id="operation-operation-div-algfrelt-algfrelt-algfrelt"></a>
### `a div b: AlgFrElt, AlgFrElt -> AlgFrElt`

<a id="operation-operation-algfrelt-algfrelt-algfrelt"></a>
### `a +:= b: AlgFrElt, AlgFrElt -> AlgFrElt`

<a id="operation-operation-algfrelt-algfrelt-algfrelt-2"></a>
### `a -:= b: AlgFrElt, AlgFrElt -> AlgFrElt`

<a id="operation-operation-algfrelt-algfrelt-algfrelt-3"></a>
### `a *:= b: AlgFrElt, AlgFrElt -> AlgFrElt`

<a id="operation-operation-div-algfrelt-algfrelt-algfrelt-2"></a>
### `a div:= b: AlgFrElt, AlgFrElt -> AlgFrElt`

## Equality and Membership

<a id="operation-op-eq-algfrelt-algfrelt"></a>
### `a eq b: AlgFrElt, AlgFrElt -> BoolElt`

<a id="operation-op-ne-algfrelt-algfrelt"></a>
### `a ne b: AlgFrElt, AlgFrElt -> BoolElt`

<a id="operation-op-in-algfrelt-rng"></a>
### `a in R: AlgFrElt, Rng -> BoolElt`

<a id="operation-op-notin-algfrelt-rng"></a>
### `a notin R: AlgFrElt, Rng -> BoolElt`

## Predicates on Algebra Elements

<a id="function-iszero-algfrelt"></a>
### `IsZero(f): AlgFrElt -> BoolElt`

<a id="function-isone-algfrelt"></a>
### `IsOne(f): AlgFrElt -> BoolElt`

<a id="function-isminusone-algfrelt"></a>
### `IsMinusOne(f): AlgFrElt -> BoolElt`

<a id="function-isnilpotent-algfrelt"></a>
### `IsNilpotent(f): AlgFrElt -> BoolElt`

<a id="function-isidempotent-algfrelt"></a>
### `IsIdempotent(f): AlgFrElt -> BoolElt`

<a id="function-isunit-algfrelt"></a>
### `IsUnit(f): AlgFrElt -> BoolElt`

<a id="function-iszerodivisor-algfrelt"></a>
### `IsZeroDivisor(f): AlgFrElt -> BoolElt`

<a id="function-isregular-algfrelt"></a>
### `IsRegular(f): AlgFrElt -> BoolElt`

<a id="function-isirreducible-algfrelt"></a>
### `IsIrreducible(f): AlgFrElt -> BoolElt`

<a id="function-isprime-algfrelt"></a>
### `IsPrime(f): AlgFrElt -> BoolElt`

## Coefficients, Monomials, Terms, and Degree

The functions in this subsection allow one to access noncommutative polynomials.

<a id="function-coefficients-algfrelt"></a>
### `Coefficients(f): AlgFrElt -> [ RngElt ]`

Given a noncommutative polynomial $f$ with coefficients in $R$, this function returns a sequence of ‘base’ coefficients, that is, a sequence of elements of $R$ occurring as coefficients of the monomials in $f$. Note that the monomials are ordered, and that the sequence of coefficients corresponds exactly to the sequence of monomials returned by `Monomials(f)`.

<a id="function-leadingcoefficient-algfrelt"></a>
### `LeadingCoefficient(f): AlgFrElt -> RngElt`

Given a noncommutative polynomial $f$ with coefficients in $R$, this function returns the leading coefficient of $f$ as an element of $R$; this is the coefficient of the leading monomial of $f$, that is, the first among the monomials occurring in $f$ with respect to the ordering of monomials used in $F$.

<a id="function-trailingcoefficient-algfrelt"></a>
### `TrailingCoefficient(f): AlgFrElt -> RngElt`

Given a noncommutative polynomial $f$ with coefficients in $R$, this function returns the trailing coefficient of $f$ as an element of $R$; this is the coefficient of the trailing monomial of $f$, that is, the last among the monomials occurring in $f$ with respect to the ordering of monomials used in $F$.

<a id="function-monomialcoefficient-algfrelt-algfrelt"></a>
### `MonomialCoefficient(f, m): AlgFrElt, AlgFrElt -> RngElt`

Given a noncommutative polynomial $f$ and a monomial $m$, this function returns the coefficient with which $m$ occurs in $f$ as an element of $R$.

<a id="function-monomials-algfrelt"></a>
### `Monomials(f): AlgFrElt -> [ AlgFrElt ]`

Given a noncommutative polynomial $f\in F$, this function returns a sequence of the monomials (monoid words) occurring in $f$. Note that the monomials in $F$ are ordered, and that the sequence of monomials corresponds exactly to the sequence of coefficients returned by `Coefficients(f)`.

<a id="function-leadingmonomial-algfrelt"></a>
### `LeadingMonomial(f): AlgFrElt -> AlgFrElt`

Given a noncommutative polynomial $f\in F$ this function returns the leading monomial of $f$, that is, the first monomial element of $F$ that occurs in $f$, with respect to the ordering of monomials used in $F$.

<a id="function-terms-algfrelt"></a>
### `Terms(f): AlgFrElt -> [ AlgFrElt ]`

Given a noncommutative polynomial $f\in F$, this function returns the sequence of (non-zero) terms of $f$ as elements of $F$. The terms are ordered according to the ordering on the monomials in $F$. Consequently the $i$-th element of this sequence of terms will be equal to the product of the $i$-th element of the sequence of coefficients and the $i$-th element of the sequence of monomials.

<a id="function-leadingterm-algfrelt"></a>
### `LeadingTerm(f): AlgFrElt -> AlgFrElt`

Given a noncommutative polynomial $f\in F$, this function returns the leading term of $f$ as an element of $F$; this is the product of the leading monomial and the leading coefficient that is, the first among the monomial terms occurring in $f$ with respect to the ordering of monomials used in $F$.

<a id="function-trailingterm-algfrelt"></a>
### `TrailingTerm(f): AlgFrElt -> RngElt`

Given a noncommutative polynomial $f\in F$, this function returns the trailing term of $f$ as an element of $F$; this is the last among the monomial terms occurring in $f$ with respect to the ordering of monomials used in $F$.

<a id="function-length-algfrelt"></a>
### `Length(m): AlgFrElt -> RngIntElt`

Given a noncommutative monomial (word) $m$, return the length of $m$, i.e., the number of letters of $m$. Note that this differs from the commutative case, where the number of terms in a polynomial is returned.

<a id="literal-literal-m-i-algfrelt-rngintelt-algfrelt"></a>
### `m[i]: AlgFrElt, RngIntElt -> AlgFrElt`

Given a noncommutative monomial (word) $m$ of length $l$, and an integer $i$ with $1\leq i\leq l$, return the $i$-th letter of $m$.

<a id="function-totaldegree-algfrelt"></a>
### `TotalDegree(f): AlgFrElt -> RngIntElt`

Given a noncommutative polynomial $f$, this function returns the total degree of $f$, which is the maximum of the lengths of all monomials that occur in $f$. If $f$ is the zero polynomial, the return value is $-1$.

<a id="function-leadingtotaldegree-algfrelt"></a>
### `LeadingTotalDegree(f): AlgFrElt -> RngIntElt`

Given a noncommutative polynomial, this function returns the leading total degree of $f$, which is the length of the leading monomial of $f$.

<a id="example-ex-4ecfe7"></a>
### `Example: Monomials and Terms of an Element (ex-4ecfe7)`

In this example we illustrate the above access functions.

```magma
> K := RationalField();
> F<x,y,z> := FreeAlgebra(K, 3);
> f := (3*x*y - 2*y*z)*(4*x - 7*z*y) + 23*x*y*z;
> f;
-21*x*y*z*y + 14*y*z^2*y + 12*x*y*x + 23*x*y*z - 8*y*z*x
> TotalDegree(f);
4
> Coefficients(f);
[ -21, 14, 12, 23, -8 ]
> Monomials(f);
[
    x*y*z*y,
    y*z^2*y,
    x*y*x,
    x*y*z,
    y*z*x
]
> Terms(f);
[
    -21*x*y*z*y,
    14*y*z^2*y,
    12*x*y*x,
    23*x*y*z,
    -8*y*z*x
]
> MonomialCoefficient(f, x*y*z);
23
> LeadingTerm(f);
-21*x*y*z*y
> LeadingCoefficient(f);
-21
> m := Monomials(f)[1];
> m;
x*y*z*y
> Length(m);
4
> m[1];
x
> m[2];
y
```

## Evaluation

<a id="function-evaluate-algfrelt-rngelt"></a>
### `Evaluate(f, s): AlgFrElt, [ RngElt ] -> RngElt`

<a id="function-evaluate-algfrelt-rngelt-rngelt"></a>
### `Evaluate(f, s): AlgFrElt, < RngElt, ..., RngElt > -> RngElt`

Given an element $f$ of a free algebra $F=R\langle x_1, \ldots, x_n\rangle$ and a sequence or tuple $s$ of ring or algebra elements of length $n$, return the value of $f$ at $s$, that is, the value obtained by substituting $x_i=s[i]$. This behaves in the same way as the `hom` constructor above. If the elements of $s$ lie in a ring and can be lifted into the coefficient ring $R$, then the result will be an element of $R$. If the elements of $s$ cannot be lifted to the coefficient ring, then an attempt is made to do a generic evaluation of $f$ at $s$. In this case, the result will be of the same type as the elements of $s$.

<a id="example-ex-88ec97"></a>
### `Example: Evaluating an Element of a Free Algebra (ex-88ec97)`

In this example we illustrate the above access functions.

```magma
> K := RationalField();
> F<x,y,z> := FreeAlgebra(K, 3);
> g := x*y + y*z;
> g;
x*y + y*z
> Evaluate(g, [1,2,3]);
8
> Parent($1);
Rational Field
> Evaluate(g, [y,x,z]);
x*z + y*x
> Parent($1);
Finitely presented algebra of rank 3 over Rational Field
Non-commutative Graded Lexicographical Order
Variables: x, y, z
```
