Poly
Klasse Poly
Polynome
Poly(list)
liefert Polynom mit den Koeffizienten aus list
(aufsteigend).
Die Koeffizienten müssen die Ringaxiome erfüllen,
für Division und Modulo-Operator (//, %, divmod) auch Körperaxiome,
und die Abfrage auf Gleichheit mit 0 implementieren.
Kurzform für Polynom mit Mod-Objekten:
Beispiel
Poly([Mod(1,2),Mod(0,2),Mod(1,2)])
Dafür auch Kurzschreibweise:
Poly([1,0,1,1],2)
Übersicht:
Poly (coeff=[], mod=0)
Methode | Bedeutung |
gcd (a,b) | Größter gemeinsamer Teiler von a und b |
gcdExt (a,b) | Erweiterter Euklidischer Algorithmus. |
irreducibles (maxDegree, mod=2) | Irreduzible Polynome |
Operator | Bedeutung |
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 |
Methode | Bedeutung |
copy () | unabhängige Kopie von p |
degree () | degree of the polynomial |
expand (x="x") | ausgeschriebenes Polynom für die Variable x |
inverse (mod) | Multiplikatives Inverses modulo Polynom m |
isOne () | |
isZero () | |
normalized () | |
operators () | Nur zur Dokumentation |
pretty (width=0) | Lesbare Darstellung des Polynoms |
toDigits () | String aus Koeffizienten |
value (x) | Wert des Polynoms für Argument x |
Konstruktor
Aufruf: Poly(coeff=[], mod=0)
gcd(a,b)
Aufruf: Poly.gcd(a,b)
Beschreibung:
Größter gemeinsamer Teiler von a und b
Berechnung mit dem Euklidischen Algorithmus
gcdExt(a,b)
Aufruf: Poly.gcdExt(a,b)
Beschreibung:
Erweiterter Euklidischer Algorithmus.
Gibt (d, x, y) zurück mit d == gcd(a,b) und x*a + y*b == d
Poly.irreducibles(maxDegree, mod=2)
Aufruf: Poly.irreducibles(maxDegree, mod=2)
Beschreibung:
Irreduzible Polynome
Rückgabewert: Liste der irreduziblen Polynome
über Z[mod] bis zum Grad maxDegree
a.__add__(b)
Aufruf: x + y
Beschreibung:
Addition
Also operator notation: a + b
Instead of a = a + b
you can write a += b
.
Polynomial division with remainder (operators // und //=):
Aufruf: x / y
Beschreibung:
f // g à f.__floordiv__ (g), if f is of type Poly
g.__rfloordiv__(f), otherwise
Polynomial division with remainder. (global function divmod)
Aufruf: divmod(x,y)
Beschreibung:
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 ==)
Aufruf: x == y
Beschreibung:
with other polynomial or ring element
Aufruf: x // y
Definition of the index operator []
Aufruf: x[i]
Beschreibung:
f[i] returns the i-th coefficient of the polynomial.
Modulo operator for polynomials (operators % und %=):
Aufruf: x % y
Beschreibung:
a % b à a.__mod__ (b), if f is of type Poly
b.__rmod__(a), otherwise
Multiplication (operators * and *=):
Aufruf: x * y
Beschreibung:
a * b à a.__mul__(b), if a is of type Poly
b.__rmul__(a), otherwise
Test for unequality (operator !=)
Aufruf: x != y
Beschreibung:
with other polynomial or ring element
unärer Operator -
Aufruf: -x
Beschreibung:
Object representation as string
Aufruf: str(x)
Beschreibung:
f >> n -- Multiplication of Polynomial by x**n
Aufruf: x >> y
Beschreibung:
Subtraction (operators - and -=):
Aufruf: x - y
Beschreibung:
a - b à a.__sub__(b), if a is of type Poly
b.__rsub__(a), otherwise
Aufruf: x / y
p.copy()
Aufruf: self.copy()
Beschreibung:
unabhängige Kopie von p
p.degree()
Aufruf: self.degree()
Beschreibung:
degree of the polynomial
p.expand(x="x")
Aufruf: f.expand(x="x")
Beschreibung:
ausgeschriebenes Polynom für die Variable x
p.inverse(m)
Aufruf: self.inverse(mod)
Beschreibung:
Multiplikatives Inverses modulo Polynom m
Das Polynom mod muss teilerfremd zu p sein!
Aufruf: self.isOne()
Aufruf: self.isZero()
Dividiert das Polynom durch den höchsten Koeffizienten
Aufruf: self.normalized()
Poly.operators()
Aufruf: self.operators()
Beschreibung:
Nur zur Dokumentation
Die Klasse Poly erlaubt folgende Operatoren:
Op. | Funktion | Beispiele |
---|---|---|
+ | Addition | a + b; a += b |
- | Subtraktion | a - b; a -= b |
* | Multiplikation | a * b; a *= b |
// | Polynomdivision (mit Rest) | a // b; a //= b |
divmod | Division und Modulo simultan | d,m = divmod(a,b) |
- | unäres Minus | -a |
p.pretty(width=0)
Aufruf: f.pretty(width=0)
Beschreibung:
Lesbare Darstellung des Polynoms
p.toDigits()
Aufruf: f.toDigits()
Beschreibung:
String aus Koeffizienten
Kurzform, nur für einstellige Mod-Koeffizienten:
Verkettung der Koeffizienten-Ziffern (ohne mod-Angabe).
Höchster Koeffizient links!
Beispiel
p=Poly([1,0,1,1],2)
p.toDigits()
Ergebnis: "1101"
p.value(x)
Aufruf: self.value(x)
Beschreibung:
Wert des Polynoms für Argument x