Main Overview

Class Poly

Class Poly
Polynomials
Poly(list) returns a polynomial with the coefficients from list (ascending).
The coefficients must comply with the ring axioms,
for division and modulo operator (//, %, divmod) also the field axioms,
and implement the equality with 0.
Short form for polynomial with Mod objektes:
Example
Poly([Mod(1,2),Mod(0,2),Mod(1,2)])
Short form:
Poly([1,0,1,1],2)

Overview:

Constructor

Poly (coeff=[], mod=0)

Class methods (static methods)

MethodMeaning
gcd (a,b)greatest common divisor of a and b
gcdExt (a,b)Extended Euclidean algorithm.
irreducibles (maxDegree, mod=2)Irreducible polynomials

Operators

OperatorMeaning
x + yAddition
x / y f // g à f.__floordiv__ (g), if f is of type Poly g.__rfloordiv__(f), otherwise
divmod(x,y) divmod(f, g) à f.__divmod__(g), if f is of type Poly g.__rdivmod__(f), otherwise Returns the pair (q,r) with: f == g * q + r and: r.degree() < g.degree() or r == 0
x == y with other polynomial or ring element
x // y
x[i] f[i] returns the i-th coefficient of the polynomial.
x % y a % b à a.__mod__ (b), if f is of type Poly b.__rmod__(a), otherwise
x * y a * b à a.__mul__(b), if a is of type Poly b.__rmul__(a), otherwise
x != y with other polynomial or ring element
-x
str(x)
x >> y
x - y a - b à a.__sub__(b), if a is of type Poly b.__rsub__(a), otherwise
x / y

Object Methods

MethodMeaning
copy ()independent copy ("clone") of p
degree ()Grad des Polynoms
expand (x="x")Polynomial written for the variable x
inverse (mod)Multiplicative inverse modulo polynomial m
isOne ()
isZero ()
normalized ()
operators ()For documentation only
pretty (width=0)Human readable written representation
toDigits ()String of coefficients
value (x)Value of the polynomial for argument x

Constructor

Poly

Constructor

Usage: Poly(coeff=[], mod=0)


Class methods (static methods)

gcd

gcd(a,b)

Usage: Poly.gcd(a,b)

Description:
greatest common divisor of a and b
Calculated using the Euclidean algorithm


gcdExt

gcdExt(a,b)

Usage: Poly.gcdExt(a,b)

Description:
Extended Euclidean algorithm.
Returns (d, x, y) with d == gcd(a,b) and x*a + y*b == d


irreducibles

Poly.irreducibles(maxDegree, mod=2)

Usage: Poly.irreducibles(maxDegree, mod=2)

Description:
Irreducible polynomials
Returns: List of irreducible polynomials over Z[mod] up to maxDegree


Operators

x + y

a.__add__(b)

Usage: x + y

Description:
Addition
Also operator notation: a + b
Instead of a = a + b you can write a += b.


x / y

Polynomial division with remainder (operators // und //=):

Usage: x / y

Description:
f // g à f.__floordiv__ (g), if f is of type Poly g.__rfloordiv__(f), otherwise


divmod(x,y)

Polynomial division with remainder. (global function divmod)

Usage: divmod(x,y)

Description:
divmod(f, g) à f.__divmod__(g), if f is of type Poly g.__rdivmod__(f), otherwise Returns the pair (q,r) with: f == g * q + r and: r.degree() < g.degree() or r == 0


x == y

Test for equality (operator ==)

Usage: x == y

Description:
with other polynomial or ring element


x // y

Usage: x // y


x[i]

Definition of the index operator []

Usage: x[i]

Description:
f[i] returns the i-th coefficient of the polynomial.


x % y

Modulo operator for polynomials (operators % und %=):

Usage: x % y

Description:
a % b à a.__mod__ (b), if f is of type Poly b.__rmod__(a), otherwise


x * y

Multiplication (operators * and *=):

Usage: x * y

Description:
a * b à a.__mul__(b), if a is of type Poly b.__rmul__(a), otherwise


x != y

Test for unequality (operator !=)

Usage: x != y

Description:
with other polynomial or ring element


-x

unärer Operator -

Usage: -x

Description:


str(x)

Object representation as string

Usage: str(x)

Description:


x >> y

f >> n -- Multiplication of Polynomial by x**n

Usage: x >> y

Description:


x - y

Subtraction (operators - and -=):

Usage: x - y

Description:
a - b à a.__sub__(b), if a is of type Poly b.__rsub__(a), otherwise


x / y

Usage: x / y


Object Methods

copy

p.copy()

Usage: self.copy()

Description:
independent copy ("clone") of p


degree

p.degree()

Usage: self.degree()

Description:
Grad des Polynoms


expand

p.expand(x="x")

Usage: f.expand(x="x")

Description:
Polynomial written for the variable x


inverse

p.inverse(m)

Usage: self.inverse(mod)

Description:
Multiplicative inverse modulo polynomial m
The polynomial mod must be relative prime to p!


isOne

Usage: self.isOne()


isZero

Usage: self.isZero()


normalized

Divides the polynomial by the highest coefficient

Usage: self.normalized()


operators

Poly.operators()

Usage: self.operators()

Description:
For documentation only
The following operators are defined in the class Poly:

Op.FunctionExamples
+Additiona + b; a += b
-Subtractiona - b; a -= b
*Multiplicationa * b; a *= b
/Polynomial division (with remainder)a / b; a /= b
divmodDivision and remainder simultaneouslyd,m = divmod(a,b)
-Unary minus-a
This method is for documentation only. It has no effect.


pretty

p.pretty(width=0)

Usage: f.pretty(width=0)

Description:
Human readable written representation


toDigits

p.toDigits()

Usage: f.toDigits()

Description:
String of coefficients
Short form, nur für singled digit Mod coefficients:
Concatenation of the coefficient digits (without mod).
Highest coeffizient left!
Example
p=Poly([1,0,1,1],2)
p.toDigits()
Result: "1101"


value

p.value(x)

Usage: self.value(x)

Description:
Value of the polynomial for argument x