Goulib.expr module¶
simple symbolic math expressions
-
Goulib.expr.
add_function
(f, s=None, r=None, l=None)[source]¶ add a function to those allowed in Expr.
Parameters: - f – function
- s – string representation, should be formula-like
- r – repr representation, should be cut&pastable in a calculator, or in python ...
- l – LaTeX representation
-
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 evaluate
- 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 -
isNum
¶
-
isconstant
¶ Returns: True if Expr evaluates to a constant number or bool
-
__div__
(right)¶
-
complexity
()[source]¶ measures the complexity of Expr :return: int, sum of the precedence of used ops
-
__delattr__
¶ Implement delattr(self, name).
-
__dir__
() → list¶ default dir() implementation
-
__format__
()¶ default object formatter
-
__getattribute__
¶ Return getattr(self, name).
-
__hash__
= None¶
-
__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 -
__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.
-