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

Type Polynomial

object --+    
         |    
      list --+
             |
            Polynomial


Provide a class representing a polynomial intended as a list of monomials. Inherits from the list built-in class and provide methods that implement the most common operations: addition, subtraction, multiplication, divison and power.

Example:
>>> print Polynomial([Monomial(2, x=2), Monomial(-1, y=1)])
2
2 x - y

Method Summary
  __init__(self, monomials)
Build a polynomial given a list of monomials.
  __add__(self, my_polynomial)
  __div__(self, my_polynomial)
Division without rest.
  __divmod__(self, my_polynomial)
  __eq__(self, my_polynomial)
  __iadd__(self, my_polynomial)
In-place addition.
  __imul__(self, my_polynomial)
In-place multiplication.
  __mod__(self, my_polynomial)
Division rest.
  __mul__(self, my_polynomial)
  __ne__(self, my_polynomial)
Determine if two polynomials aren't equal.
  __neg__(self)
Change the sign to all monomials in the polynomial.
  __pow__(self, n)
Raise the polynomial to the power n.
  __radd__(self, my_polynomial)
  __rdiv__(self, my_polynomial)
  __rdivmod__(self, my_polynomial)
  __repr__(self)
Return a value that, passed to eval(), should return a Polynomial instance equal to self.
  __rmod__(self, my_polynomial)
  __rmul__(self, my_polynomial)
  __rsub__(self, my_polynomial)
  __str__(self)
Print the polynomial in a human-readable manner.
  __sub__(self, my_polynomial)
  __truediv__(self, my_polynomial)
Division with __future__.division
  check_second_term(wrapped)
Check if the second term of an operation is a Polynomial
  eval(self, **unknowns)
Resolve the polynomial using it as a function P(x, y, ...).
  generate(cls, *coefficients)
Generate a polynomial instance with given coefficients and specified unknown (Class method)
  simplify(self)
Simplify the polynomial: sum similar monomials and delete zero-coefficient monomials.
    Inherited from list
  __contains__(x, y)
x.__contains__(y) <==> y in x
  __delitem__(x, y)
x.__delitem__(y) <==> del x[y]
  __delslice__(x, i, j)
Use of negative indices is not supported.
  __ge__(x, y)
x.__ge__(y) <==> x>=y
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __getitem__(x, y)
x.__getitem__(y) <==> x[y]
  __getslice__(x, i, j)
Use of negative indices is not supported.
  __gt__(x, y)
x.__gt__(y) <==> x>y
  __hash__(x)
x.__hash__() <==> hash(x)
  __iter__(x)
x.__iter__() <==> iter(x)
  __le__(x, y)
x.__le__(y) <==> x<=y
  __len__(x)
x.__len__() <==> len(x)
  __lt__(x, y)
x.__lt__(y) <==> x<y
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reversed__(...)
L.__reversed__() -- return a reverse iterator over the list
  __setitem__(x, i, y)
x.__setitem__(i, y) <==> x[i]=y
  __setslice__(x, i, j, y)
Use of negative indices is not supported.
  append(...)
L.append(object) -- append object to end
  count(L, value)
L.count(value) -> integer -- return number of occurrences of value
  extend(...)
L.extend(iterable) -- extend list by appending elements from the iterable
  index(...)
L.index(value, [start, [stop]]) -> integer -- return first index of value
  insert(...)
L.insert(index, object) -- insert object before index
  pop(L, index)
L.pop([index]) -> item -- remove and return item at index (default last)
  remove(...)
L.remove(value) -- remove first occurrence of value
  reverse(...)
L.reverse() -- reverse *IN PLACE*
  sort(...)
L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*; cmp(x, y) -> -1, 0, 1
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Property Summary
  degree: Return polynomial's degree.

Instance Method Details

__init__(self, monomials)
(Constructor)

Build a polynomial given a list of monomials.

Example:
>>> monomial1 = Monomial(3, x=1, y=2)
>>> monomial2 = Monomial(4, x=2, y=1)
>>> my_polynomial = ([monomial1, monomial2])
Overrides:
__builtin__.list.__init__

__div__(self, my_polynomial)

Division without rest.

See also method __divmod__.

__iadd__(self, my_polynomial)

In-place addition.

See also method __add__.
Overrides:
__builtin__.list.__iadd__

__imul__(self, my_polynomial)

In-place multiplication.

See also method __mul__.
Overrides:
__builtin__.list.__imul__

__mod__(self, my_polynomial)

Division rest.

See also method __divmod__.

__ne__(self, my_polynomial)

Determine if two polynomials aren't equal.
Overrides:
__builtin__.list.__ne__

__neg__(self)

Change the sign to all monomials in the polynomial.

Example:
>>> print -Polynomial([Monomial(2, x=2), Monomial(-1, y=1)])
2
- 2 x + y

__pow__(self, n)

Raise the polynomial to the power n.

Example:
>>> print Polynomial([Monomial(2, x=2), Monomial(2, y=1)])**2
4     2     2
4 x + 4 y + 8 x y

__repr__(self)
(Representation operator)

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

Example:
>>> a = Polynomial([Monomial(2, x=2, y=3), Monomial(3, z=1)])
>>> b = eval(repr(a))
>>> print a == b
True
Overrides:
__builtin__.list.__repr__

__str__(self)
(Informal representation operator)

Print the polynomial in a human-readable manner.

Example:
>>> monomial1 = Monomial(3, x=1, y=2)
>>> monomial2 = Monomial(4, x=2, y=1)
>>> my_polynomial = Polynomial([monomial1, monomial2])
>>> print my_polynomial
2     2
3 x y + 4 x y
Overrides:
__builtin__.object.__str__

__truediv__(self, my_polynomial)

Division with __future__.division

See also method __div__.

check_second_term(wrapped)

Check if the second term of an operation is a Polynomial

eval(self, **unknowns)

Resolve the polynomial using it as a function P(x, y, ...).

Example:
>>> p = Polynomial([Monomial(x=2, y=1), Monomial(y=1)])
>>> print p.eval(x=5, y=2)
52
Ignore exceeding arguments.

simplify(self)

Simplify the polynomial: sum similar monomials and delete zero-coefficient monomials. In-place method.

Example:
>>> my_polynomial = Polynomial([Monomial(2, x=2), Monomial(3, x=2),
... Monomial(-4, y=1)])
>>> print my_polynomial.simplify()
2
5 x - 4 y

Class Method Details

generate(cls, *coefficients)

Generate a polynomial instance with given coefficients and specified unknown

Example:
>>> a = Polynomial.generate(1,2,3)
>>> print a
2
x + 2 x + 3

Property Details

degree

Return polynomial's degree.

Example:
>>> print Polynomial([Monomial(2, x=2), Monomial(-1, y=1)]).degree
2
Get Method:
degree(...)

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