Dash-math_Database / layout /safe_sympy.py
Mochi0622's picture
initial deploy
e66cfb4
Raw
History Blame Contribute Delete
655 Bytes
# safe_sympy.py
import sympy as sp
x, y,z = sp.symbols("x y z")
ALLOWED_BASE = {
"x": x, "y": y,"z":z,
"pi": sp.pi, "e": sp.E,
"sin": sp.sin, "cos": sp.cos, "tan": sp.tan,
"asin": sp.asin, "acos": sp.acos, "atan": sp.atan, "atan2": sp.atan2,
"sinh": sp.sinh, "cosh": sp.cosh, "tanh": sp.tanh,
"exp": sp.exp, "log": sp.log, "sqrt": sp.sqrt, "abs": sp.Abs,
"floor": sp.floor, "ceil": sp.ceiling, "sign": sp.sign,
"Piecewise": sp.Piecewise, "Max": sp.Max, "Min": sp.Min,
}
def get_allowed(extra: dict | None = None) -> dict:
allowed = dict(ALLOWED_BASE)
if extra:
allowed.update(extra)
return allowed