ajdmom.poly¶
Class Poly, a customized dictionary, derived from UserDict
I defined a new class Poly
to extend the UserDict class
from the Python Standard Library collections, within which
I defined an attribute keyfor and the
following magic methods:
Magic Method |
Example |
Function |
|---|---|---|
__add__() |
|
Addition between two polynomials |
__sub__() |
|
Subtraction between two polynomials |
__mul__() |
|
Multiplication between two polynomials |
__rmul__() |
|
Reversely multiply by a constant |
__pow__() |
|
Raise a polynomial to power n |
It should be noted that:
Addition and subtraction are only for polynomials having the same
keyforattribute.The original poly or polys remain unchanged after these operations, all of which return a new poly.
Besides, I defined following methods:
Method |
Function |
|---|---|
Merge with another poly having the same keyfor attribute |
|
Insert a new key-val or add val to the existing key |
|
Remove any item having value 0 |
|
Set the |
|
Multiply by another poly of different type and return a new one |
|
Check whether the supplied argument is a Poly with the same keyfor |
|
Write the poly to a txt file with the |
|
Write the poly to a csv file with the |
|
Constant equivalent to 1 in real numbers |
|
Constant equivalent to 0 in real numbers |
Note that merge() (in-place) is different from
the magic method __add__() (not-in-place). The former changes the
original poly, while the latter does not.
Classes
|
Class for different versions of "Polynomial" |
Functions
|
get key[i] where key is a tuple |