str_to_sympy function
(Shortest import: from brian2.parsing.sympytools import str_to_sympy)
- brian2.parsing.sympytools.str_to_sympy(expr, variables=None)[source]
Parses a string into a sympy expression. There are two reasons for not using
sympify
directly: 1) sympify does afrom sympy import *
, adding all functions to its namespace. This leads to issues when trying to use sympy function names as variable names. For example, bothbeta
andfactor
– quite reasonable names for variables – are sympy functions, using them as variables would lead to a parsing error. 2) We want to use a common syntax across expressions and statements, e.g. we want to allow to useand
(instead of&
) and function names likeceil
(instead ofceiling
).- Parameters:
expr : str
The string expression to parse.
variables : dict, optional
Dictionary mapping variable/function names in the expr to their respective
Variable
/Function
objects.- Returns:
s_expr :
A sympy expression
Raises
SyntaxError
In case of any problems during parsing.