Goulib.expr module

simple symbolic math expressions

Goulib.expr.eval(node, ctx={})[source]

safe eval of ast node : only functions and operators listed above can be used

Parameters:
  • node – ast.AST to evalaluate
  • ctx – dict of varname : value to substitute in node
Returns:

number or expression string

Goulib.expr.get_function_source(f)[source]

returns cleaned code of a function or lambda currently only supports: - lambda x:formula_of_(x) - def anything(x): return formula_of_(x)

class Goulib.expr.Expr(f)[source]

Bases: Goulib.plot.Plot

Math expressions that can be evaluated like standard functions combined using standard operators and plotted in IPython/Jupyter notebooks

Parameters:f – function or operator, Expr to copy construct, or formula string
__init__(f)[source]
Parameters:f – function or operator, Expr to copy construct, or formula string
__call__(x=None, **kwargs)[source]

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

__repr__()[source]
__str__()[source]
latex()[source]
Returns:string LaTex formula
apply(f, right=None)[source]

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

applx(f, var='x')[source]

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

isconstant
Returns:True if Expr evaluates to a constant number of bool
__eq__(other)[source]
__lt__(other)[source]
__add__(right)[source]
__sub__(right)[source]
__neg__()[source]
__mul__(right)[source]
__rmul__(right)[source]
__truediv__(right)[source]
__div__(right)
__invert__()[source]
__and__(right)[source]
__or__(right)[source]
__xor__(right)[source]
__lshift__(dx)[source]
__rshift__(dx)[source]
__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__ = None
__le__

Return self<=value.

__ne__

Return self!=value.

__new__()

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

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

html(**kwargs)
plot(**kwargs)

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

png(**kwargs)
render(fmt='svg', **kwargs)
save(filename, **kwargs)
svg(**kwargs)
class Goulib.expr.TextVisitor(dialect)[source]

Bases: ast.NodeVisitor

Parameters:dialect – int index in operators of symbols to use
__init__(dialect)[source]
Parameters:dialect – int index in operators of symbols to use
prec(n)[source]
prec_UnaryOp(n)[source]
prec_BinOp(n)[source]
visit_Call(n)[source]
visit_Name(n)[source]
visit_NameConstant(node)[source]
visit_UnaryOp(n)[source]
visit_BinOp(n)[source]
__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

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

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

visit(node)

Visit a node.

visit_Compare(n)[source]
visit_Num(n)[source]
generic_visit(n)[source]
class Goulib.expr.LatexVisitor[source]

Bases: Goulib.expr.TextVisitor

__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

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

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

generic_visit(n)
prec(n)
prec_BinOp(n)
prec_UnaryOp(n)
visit(node)

Visit a node.

visit_BinOp(n)
visit_Compare(n)
visit_Name(n)
visit_NameConstant(node)
visit_Num(n)
__init__()[source]
visit_Call(n)[source]
visit_UnaryOp(n)[source]