Skip to content

Discussion: how to handle variable names in expressions clashing with variables in sympy name space. #120

@MoAly98

Description

@MoAly98

The issue in #117 points out an failure to parse an expression as the parser tries to sum an Integer() with a FunctionClass when the expresion is 1+beta. This was traced in #118 to be because beta exists in the sympy namespace as sp.beta and the current expression parser (parse_expr) imports this whole namespace unless restricted by the global_dict argument passed form parse_expression. The rough fix in #118 restricts the functions imported from the sympy namespace. This is too restrictive, since users may want to use one of these functions (e.g. sp.min) in their expressions. One solution is enforcing a heirarchy where local variable names are prioritised over using the sympy variables with the same name, and another is to restrict users from using variable names that are in the sympy namespace.

A few examples that fail parsing for the above reason:

config = {
      "type": "generic_function",
      "name": "myfunc",
      "expression": "min + 1"
}
func = GenericFunction(**config)

config = {
      "type": "generic_function",
      "name": "myfunc",
      "expression": "beta + 1"
}
func = GenericFunction(**config)

config = {
      "type": "generic_function",
      "name": "myfunc",
      "expression": "gamma + 1"
}
func = GenericFunction(**config)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions