code

export.code

Functions

Name Description
inline_functions Inline all function applications in an expression.
print_Piecewise Print Piecewise expressions as nested np.where statements.
render_equation Render an equation to a target format.
render_expression Render a SymPy expression or string to target format code.

inline_functions

export.code.inline_functions(expr, func_defs)

Inline all function applications in an expression.

Parameters

expr : sympy.Expr The expression containing function calls to inline. func_defs : dict Dictionary mapping function name -> (arg_names, body_expr) where arg_names is a list of argument names and body_expr is the sympy expression for the function body.

Returns

sympy.Expr Expression with all function calls replaced by their inlined bodies.

Example

from sympy import symbols, Function x, y, v = symbols(‘x y v’) # Define Sigm(v) = 2e0/(1 + exp(r(v0 - v))) func_defs = {‘Sigm’: ([‘v’], 2e0/(1 + exp(r(v0 - v))))} expr = ASigm(x - y) inline_functions(expr, func_defs) 2Ae0/(1 + exp(r(v0 - x + y)))

print_Piecewise

export.code.print_Piecewise(Printer, expr, verbose=False)

Print Piecewise expressions as nested np.where statements.

render_equation

export.code.render_equation(
    equation,
    format='jax',
    local_dict={},
    user_functions={},
    replace=None,
    remove=None,
    inline_funcs=None,
    **kwargs,
)

Render an equation to a target format.

Parameters

equation : Equation The equation to render. format : str Target format: ‘jax’, ‘numpy’, ‘python’, ‘julia’, ‘fortran’, ‘latex’. local_dict : dict Dictionary of local symbols/functions for parsing. user_functions : dict Custom function mappings for the printer. replace : dict Symbol replacements {old_name: new_name}. remove : list Symbols to replace with zero. inline_funcs : dict, optional Dictionary mapping function name -> (arg_names, body_expr) for inlining custom functions. The body_expr should be a sympy expression. Example: {‘Sigm’: ([‘v’], 2e0/(1 + exp(r(v0 - v))))} **kwargs Additional arguments passed to parse_eq.

Returns

str The rendered equation string.

render_expression

export.code.render_expression(
    expression,
    format='jax',
    user_functions={},
    parameters=None,
    infer_broadcasting=False,
)

Render a SymPy expression or string to target format code.

Uses parse_eq for proper handling of indexed expressions and Sum/Product.

Parameters

expression : str or sympy.Expr The expression to render. format : str Target format (‘jax’, ‘numpy’, ‘julia’, ‘python’, etc.) user_functions : dict Custom function name mappings for the printer. These are also passed to parse_eq so they’re recognized as functions (not implicit multiplication). parameters : list of str, optional Parameter names to define as Symbols. These OVERRIDE SymPy built-in functions (e.g., ‘gamma’ becomes Symbol(‘gamma’), not the gamma function). infer_broadcasting : bool If True, analyze indexed expressions and automatically add broadcasting dimensions (e.g., rmse[i] -> rmse[:, None] when used with a[i,j]). This enables mathematically correct notation to generate correct array code.