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]
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]

Return self<value.

`__eq__`(other)[source]

Return self==value.

`__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 `builtins.type`

`__delattr__`

Implement delattr(self, name).

`__dir__`()

Default dir() implementation.

`__div__`(right)
`__float__`()
`__format__`()

Default object formatter.

`__ge__`(other)

Return self>=value.

`__getattribute__`

Return getattr(self, name).

`__gt__`(other)

Return self>value.

`__hash__` = None
`__init_subclass__`()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

`__invert__`()
`__le__`(other)

Return self<=value.

`__lshift__`(dx)
`__ne__`(other)

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__`()

Return repr(self).

`__rshift__`(dx)
`__setattr__`

Implement setattr(self, name, value).

`__sizeof__`()

Size of object in memory, in bytes.

`__str__`()

Return str(self).

`__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))

`complexity`()

measures the complexity of Expr :return: int, sum of the precedence of used ops

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

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

`png`(**kwargs)
`points`(xmin=-1, xmax=1, step=0.1)
Returns: x,y lists of float : points for a line plot
`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.

`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.