Goulib.polynomial module

simple manipulation of polynomials (without SimPy) see http://docs.sympy.org/dev/modules/polys/reference.html if you need more ...

class Goulib.polynomial.Polynomial(val)[source]

Bases: Goulib.expr.Expr

Param:val can be:
  • an iterable of the factors in ascending powers order : Polynomial([1,2,3]) holds 3*x^2+2*x+1
  • a string of the form “ax^n + b*x^m + ... + c x + d” where a,b,c,d, are floats and n,m ... are integers the ‘x’ variable name is fixed, and the spaces and ‘*’ chars are optional. terms can be in any order, and even “overlap” : Polynomial(‘3x+x^2-x’) holds x^2+2*x
__init__(val)[source]
Param:val can be:
  • an iterable of the factors in ascending powers order : Polynomial([1,2,3]) holds 3*x^2+2*x+1
  • a string of the form “ax^n + b*x^m + ... + c x + d” where a,b,c,d, are floats and n,m ... are integers the ‘x’ variable name is fixed, and the spaces and ‘*’ chars are optional. terms can be in any order, and even “overlap” : Polynomial(‘3x+x^2-x’) holds x^2+2*x
__lt__(other)[source]
__eq__(other)[source]
__add__(other)[source]
__radd__(other)[source]
__sub__(other)[source]
__rsub__(other)[source]
__mul__(other)[source]
__rmul__(other)[source]
__neg__()[source]
__pow__(e)[source]
integral()[source]
derivative()[source]
__and__(right)
__call__(x=None, **kwargs)

evaluate the Expr at x OR compose self(x())

__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__div__(right)
__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__ = None
__invert__()
__le__

Return self<=value.

__lshift__(dx)
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__or__(right)
__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__()
__rshift__(dx)
__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__()
__truediv__(right)
__xor__(right)
applx(f, var='x')

function composition f o self = self(f(x))

apply(f, right=None)

function composition self o f = f(self(x))

html(**kwargs)
isconstant
Returns:True if Expr evaluates to a constant number of bool
latex()
Returns:string LaTex formula
plot(**kwargs)

renders on IPython Notebook (alias to make usage more straightforward)

png(**kwargs)
render(fmt='svg', **kwargs)
save(filename, **kwargs)
svg(**kwargs)
Goulib.polynomial.plist(term)[source]

Force term to have the form of a polynomial list

Goulib.polynomial.peval(plist, x, x2=None)[source]

Eval the plist at value x. If two values are given, the difference between the second and the first is returned. This latter feature is included for the purpose of evaluating definite integrals.

Goulib.polynomial.integral(plist)[source]

Return a new plist corresponding to the integral of the input plist. This function uses zero as the constant term, which is okay when evaluating a definite integral, for example, but is otherwise ambiguous.

The math forces the coefficients to be turned into floats. Consider importing __future__ division to simplify this.

Goulib.polynomial.derivative(plist)[source]

Return a new plist corresponding to the derivative of the input plist.

Goulib.polynomial.add(p1, p2)[source]

Return a new plist corresponding to the sum of the two input plists.

Goulib.polynomial.sub(p1, p2)[source]
Goulib.polynomial.mult_const(p, c)[source]

Return a new plist corresponding to the input plist multplied by a const

Goulib.polynomial.multiply(p1, p2)[source]

Return a new plist corresponding to the product of the two input plists

Goulib.polynomial.mult_one(p, c, i)[source]

Return a new plist corresponding to the product of the input plist p with the single term c*x^i

Goulib.polynomial.power(p, e)[source]

Return a new plist corresponding to the e-th power of the input plist p

Goulib.polynomial.parse_string(s)[source]

Do very, very primitive parsing of a string into a plist. ‘x’ is the only term considered for the polynomial, and this routine can only handle terms of the form: 7x^2 + 6x - 5 and will choke on seemingly simple forms such as x^2*7 - 1 or x**2 - 1

Goulib.polynomial.tostring(p, **kwargs)[source]

Convert a plist into a string. This looks overly complex at first, but most of the complexity is caused by special cases.