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:
Poly (coeff=[], mod=0)
Method | Meaning |
gcd (a,b) | greatest common divisor of a and b |
gcdExt (a,b) | Extended Euclidean algorithm. |
irreducibles (maxDegree, mod=2) | Irreducible polynomials |
Operator | Meaning |
x + y | Addition |
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 |
Method | Meaning |
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
Usage: Poly(coeff=[], mod=0)
gcd(a,b)
Usage: Poly.gcd(a,b)
Description:
greatest common divisor of a and b
Calculated using the Euclidean algorithm
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
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
a.__add__(b)
Usage: x + y
Description:
Addition
Also operator notation: a + b
Instead of a = a + b
you can write a += b
.
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
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
Test for equality (operator ==)
Usage: x == y
Description:
with other polynomial or ring element
Usage: x // y
Definition of the index operator []
Usage: x[i]
Description:
f[i] returns the i-th coefficient of the polynomial.
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
Multiplication (operators * and *=):
Usage: x * y
Description:
a * b à a.__mul__(b), if a is of type Poly
b.__rmul__(a), otherwise
Test for unequality (operator !=)
Usage: x != y
Description:
with other polynomial or ring element
unärer Operator -
Usage: -x
Description:
Object representation as string
Usage: str(x)
Description:
f >> n -- Multiplication of Polynomial by x**n
Usage: x >> y
Description:
Subtraction (operators - and -=):
Usage: x - y
Description:
a - b à a.__sub__(b), if a is of type Poly
b.__rsub__(a), otherwise
Usage: x / y
p.copy()
Usage: self.copy()
Description:
independent copy ("clone") of p
p.degree()
Usage: self.degree()
Description:
Grad des Polynoms
p.expand(x="x")
Usage: f.expand(x="x")
Description:
Polynomial written for the variable x
p.inverse(m)
Usage: self.inverse(mod)
Description:
Multiplicative inverse modulo polynomial m
The polynomial mod must be relative prime to p!
Usage: self.isOne()
Usage: self.isZero()
Divides the polynomial by the highest coefficient
Usage: self.normalized()
Poly.operators()
Usage: self.operators()
Description:
For documentation only
The following operators are defined in the class Poly:
Op. | Function | Examples |
---|---|---|
+ | Addition | a + b; a += b |
- | Subtraction | a - b; a -= b |
* | Multiplication | a * b; a *= b |
/ | Polynomial division (with remainder) | a / b; a /= b |
divmod | Division and remainder simultaneously | d,m = divmod(a,b) |
- | Unary minus | -a |
p.pretty(width=0)
Usage: f.pretty(width=0)
Description:
Human readable written representation
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"
p.value(x)
Usage: self.value(x)
Description:
Value of the polynomial for argument x