Home | Trees | Index | Help |
|
---|
Module pypol :: Class Monomial |
|
object
--+
|
Monomial
Provide a class representing a monomial given coefficient and unknowns. Coefficient could be even a rational numer.
Example:>>> print Monomial(3.0/2.0, x=2, y=1, z=3) 2 3 3/2 x y z
Monomials can be added, subtracted, divided or multiplicated with other monomials or even with polynomials.
Example:>>> my_monomial = Monomial(2, x=2) >>> my_polynomial = Polynomial([Monomial(2, y=2), Monomial(2, x=2)]) >>> print my_monomial-my_polynomial 2 - 2 y
Unknowns are accesible via letteral_part dictionary attribute and via also normal attributes.
Example:>>> my_monomial = Monomial(2, x=2, y=3) >>> my_monomial.letteral_part['x'] 2 >>> my_monomial.y.degree 3
Method Summary | |
---|---|
Build a monomial given its coefficient and unknowns. | |
Add two monomials and return a new Monomial instance if the second term is Monomial, otherwise return a new Polynomial instance. | |
__cmp__(self,
my_monomial)
| |
Divide self by my_monomial. | |
__eq__(self,
my_monomial)
| |
Multiply two monomials or a monomial and a polynomial. | |
Determine if two monomials aren't equal. | |
Return a new Monomial instance with the opposite sign. | |
Called by bool(monomialInstance) return True if coefficient isn't 0 | |
Raise the monomial to the power n. | |
Addition with swapped operands. | |
Division with swapped operands. | |
Return a value that, passed to eval(), should return a Monomial instance equal to self. | |
Multiplication with swapped operands. | |
Subtraction with swapped operands. | |
Print to the stdout the monomial in a human-readable manner. | |
Subtract two monomials or a monomial and a polynomial. | |
Division with __future__.division. | |
Check if the second term of an operation is a Monomial | |
Replace the unknowns with given values and return the result. | |
is_similar(self,
my_monomial)
| |
Inherited from object | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
x.__hash__() <==> hash(x) | |
T.__new__(S, ...) -> a new object with type S, a subtype of T | |
helper for pickle | |
helper for pickle | |
x.__setattr__('name', value) <==> x.name = value |
Property Summary | |
---|---|
degree : Return monomial's degree. |
Method Details |
---|
__init__(self,
coefficient=1,
**unknowns)
|
__add__(self,
my_monomial)
|
__div__(self, my_monomial)Divide self by my_monomial. Example:>>> print Monomial(2, x=3)/Monomial(2, x=1) 2 x |
__mul__(self, my_monomial)Multiply two monomials or a monomial and a polynomial. Return a Monomial or a Polynomial new instance. Example:>>> print Monomial(2, x=1)*Monomial(3, y=2) 2 6 x y >>> print Monomial(2, x=1)*Polynomial([Monomial(3, x=1), ... Monomial(2, y=2)]) 2 2 4 x y + 6 x |
__ne__(self, my_monomial)Determine if two monomials aren't equal. |
__neg__(self)Return a new Monomial instance with the opposite sign. Example:>>> print -Monomial(2, x=2) 2 - 2 x |
__nonzero__(self)
|
__pow__(self, n)Raise the monomial to the power n. Example:>>> print Monomial(2, x=2)**2 4 4 x |
__radd__(self,
other)
|
__rdiv__(self, other)Division with swapped operands. See also method __div__ of this class. |
__repr__(self)
|
__rmul__(self, other)Multiplication with swapped operands. See also method __mul__ of this class. |
__rsub__(self, other)Subtraction with swapped operands. See method __sub__ of this class. |
__str__(self)
|
__sub__(self,
my_monomial)
|
__truediv__(self, my_monomial)Division with __future__.division. See also __div__ method of this class. |
check_second_term(wrapped)Check if the second term of an operation is a Monomial |
eval(self, **unknowns)Replace the unknowns with given values and return the result. Ignore exceeding arguments. Example:>>> a = Monomial(2, x=2, y=3, z=1) >>> print a.eval(x=1, y=2, z=2) 32 |
Property Details |
---|
degreeReturn monomial's degree. Example:>>> print Monomial(2, x=2, y=1).degree 3
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Fri Aug 10 15:00:04 2007 | http://epydoc.sf.net |