The following operations are always available for polynomials. The operands must have a common base ring, no implicit conversions are performed.
f + g
The operator +
evaluates to the sum of the polynomials f and g,
which must be polynomials over a common base ring.
gap> f := Polynomial( GF(2), [Z(2), Z(2)] ); Z(2)^0*(X(GF(2)) + 1) gap> f + f; 0*X(GF(2))^0 gap> g := Polynomial( GF(4), [Z(2), Z(2)] ); X(GF(2^2)) + Z(2)^0 gap> f + g; Error, polynomials must have the same ring
f + scl
scl + f
The operator +
evaluates to the sum of the polynomial f and the
scalar scl, which must lie in the base ring of f.
gap> x := Indeterminate( Integers );; x.name := "x";; gap> h := Polynomial( Integers, [1,2,3,4] ); 4*x^3 + 3*x^2 + 2*x + 1 gap> h + 1; 4*x^3 + 3*x^2 + 2*x + 2 gap> 1/2 + h; Error, <l> must lie in the base ring of <r>
f - g
The operator -
evaluates to the difference of the polynomials f and
g, which must be polynomials over a common base ring.
gap> x := Indeterminate( Integers );; x.name := "x";; gap> h := Polynomial( Integers, [1,2,3,4] ); 4*x^3 + 3*x^2 + 2*x + 1 gap> h - 2*h; -4*x^3 - 3*x^2 - 2*x - 1
f - scl
scl - f
The operator -
evaluates to the difference of the polynomial f and
the scalar scl, which must lie in the base ring of f.
gap> x := Indeterminate( Integers );; x.name := "x";; gap> h := Polynomial( Integers, [1,2,3,4] ); 4*x^3 + 3*x^2 + 2*x + 1 gap> h - 1; 4*x^3 + 3*x^2 + 2*x gap> 1 - h; -4*x^3 - 3*x^2 - 2*x
f * g
The operator *
evaluates to the product of the two polynomials f and
g, which must be polynomial over a common base ring.
gap> x := Indeterminate(Integers);; x.name := "x";; gap> h := 4*x^3 + 3*x^2 + 2*x + 1; 4*x^3 + 3*x^2 + 2*x + 1 gap> h * h; 16*x^6 + 24*x^5 + 25*x^4 + 20*x^3 + 10*x^2 + 4*x + 1
f * scl
scl * f
The operator *
evaluates to the product of the polynomial f and the
scalar scl, which must lie in the base ring of f.
gap> f := Polynomial( GF(2), [Z(2), Z(2)] ); Z(2)^0*(X(GF(2)) + 1) gap> f - Z(2); X(GF(2)) gap> Z(4) - f; Error, <l> must lie in the base ring of <r>
f ^ n
The operator ^
evaluates the the n-th power of the polynomial f.
If n is negative ^
will try to invert f in the Laurent polynomial
ring ring.
gap> x := Indeterminate(Integers);; x.name := "x";; gap> k := x - 1 + x^-1; x - 1 + x^(-1) gap> k ^ 3; x^3 - 3*x^2 + 6*x - 7 + 6*x^(-1) - 3*x^(-2) + x^(-3) gap> k^-1; Error, cannot invert <l> in the laurent polynomial ring
f / scl
The operator /
evaluates to the product of the polynomial f and the
inverse of the scalar scl, which must be invertable in its default
ring.
gap> x := Indeterminate(Integers);; x.name := "x";; gap> h := 4*x^3 + 3*x^2 + 2*x + 1; 4*x^3 + 3*x^2 + 2*x + 1 gap> h / 3; (4/3)*x^3 + x^2 + (2/3)*x + (1/3)
scl / f
The operator /
evaluates to the product of the scalar scl and the
inverse of the polynomial f, which must be invertable in its Laurent
ring.
gap> x := Indeterminate(Integers);; x.name := "x";; gap> 30 / x; 30*x^(-1) gap> 3 / (1+x); Error, cannot invert <l> in the laurent polynomial ring
f / g
The operator /
evaluates to the quotient of the two polynomials f and
g, if such quotient exists in the Laurent polynomial ring. Otherwise
/
signals an error.
gap> x := Indeterminate(Integers);; x.name := "x";; gap> f := (1+x+x^2) * (3-x-2*x^2); -2*x^4 - 3*x^3 + 2*x + 3 gap> f / (1+x+x^2); -2*x^2 - x + 3 gap> f / (1+x); Error, cannot divide <l> by <r>
GAP 3.4.4