Module pypol :: Class Monomial
[show private | hide private]
[frames | no frames]

Type 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
  __init__(self, coefficient, **unknowns)
Build a monomial given its coefficient and unknowns.
  __add__(self, my_monomial)
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)
  __div__(self, my_monomial)
Divide self by my_monomial.
  __eq__(self, my_monomial)
  __mul__(self, my_monomial)
Multiply two monomials or a monomial and a polynomial.
  __ne__(self, my_monomial)
Determine if two monomials aren't equal.
  __neg__(self)
Return a new Monomial instance with the opposite sign.
  __nonzero__(self)
Called by bool(monomialInstance) return True if coefficient isn't 0
  __pow__(self, n)
Raise the monomial to the power n.
  __radd__(self, other)
Addition with swapped operands.
  __rdiv__(self, other)
Division with swapped operands.
  __repr__(self)
Return a value that, passed to eval(), should return a Monomial instance equal to self.
  __rmul__(self, other)
Multiplication with swapped operands.
  __rsub__(self, other)
Subtraction with swapped operands.
  __str__(self)
Print to the stdout the monomial in a human-readable manner.
  __sub__(self, my_monomial)
Subtract two monomials or a monomial and a polynomial.
  __truediv__(self, my_monomial)
Division with __future__.division.
  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.
  is_similar(self, my_monomial)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Property Summary
  degree: Return monomial's degree.

Method Details

__init__(self, coefficient=1, **unknowns)
(Constructor)

Build a monomial given its coefficient and unknowns.

Example:
>>> my_monomial = Monomial(3, x=1, y=3)
>>> print my_monomial.letteral_part
{'y': 3, 'x': 1}

>>> print my_monomial.coefficient
3

>>> print my_monomial.x.degree
1

>>> print my_monomial.y.degree
3
Overrides:
__builtin__.object.__init__

__add__(self, my_monomial)
(Addition operator)

Add two monomials and return a new Monomial instance if the second term is Monomial, otherwise return a new Polynomial instance.

Example:
>>> print Monomial(4, x=1, y=2)+Monomial(3, x=1, y=2)
2
7 x y

__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)
(Boolean test operator)

Called by bool(monomialInstance) return True if coefficient isn't 0

Example:
>>> a = Monomial(0)
>>> bool(a)
False

>>> b = Monomial(x=2)
>>> bool(b)
True

__pow__(self, n)

Raise the monomial to the power n.

Example:
>>> print Monomial(2, x=2)**2
4
4 x

__radd__(self, other)
(Right-side addition operator)

Addition with swapped operands.

See also method __add__ of this class.

__rdiv__(self, other)

Division with swapped operands.

See also method __div__ of this class.

__repr__(self)
(Representation operator)

Return a value that, passed to eval(), should return a Monomial instance equal to self.

Example:
>>> a = Monomial(2, x=1, y=2)
>>> b = eval(repr(a))
>>> print a == b
True
Overrides:
__builtin__.object.__repr__

__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)
(Informal representation operator)

Print to the stdout the monomial in a human-readable manner. If the coefficient is 1, it won't be printed.

Example:
>>> print Monomial(3, x=1, y=3)
3
3 x y
Overrides:
__builtin__.object.__str__

__sub__(self, my_monomial)
(Subtraction operator)

Subtract two monomials or a monomial and a polynomial. If subtrahend is a Polynomial instance return a Polynomial instance, otherwise return a Monomial instance.

Example:
>>> print Monomial(2, x=2) - Monomial(1, x=2)
2
x

__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

degree

Return monomial's degree.

Example:
>>> print Monomial(2, x=2, y=1).degree
3
Get Method:
degree(...)

Generated by Epydoc 2.1 on Fri Aug 10 15:00:04 2007 http://epydoc.sf.net