Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,34 @@ import gradio as gr
|
|
| 16 |
import numexpr
|
| 17 |
|
| 18 |
def safe_math_eval(expression: str) -> float:
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
Args:
|
| 22 |
expression: The nunexpr formatted expression to evaluate
|
|
|
|
| 16 |
import numexpr
|
| 17 |
|
| 18 |
def safe_math_eval(expression: str) -> float:
|
| 19 |
+
"""Enter a math formula using the supported operators and functions.
|
| 20 |
+
|
| 21 |
+
**Supported Operators:**
|
| 22 |
+
- `+` (addition)
|
| 23 |
+
- `-` (subtraction)
|
| 24 |
+
- `*` (multiplication)
|
| 25 |
+
- `/` (division)
|
| 26 |
+
- `**` (power)
|
| 27 |
+
- `%` (modulus)
|
| 28 |
+
- `<`, `<=`, `==`, `!=`, `>=`, `>` (comparisons)
|
| 29 |
+
- `&`, `|`, `~` (bitwise and logical operators)
|
| 30 |
+
|
| 31 |
+
**Supported Functions:**
|
| 32 |
+
- Trigonometric: `sin`, `cos`, `tan`, `arcsin`, `arccos`, `arctan`, `arctan2`
|
| 33 |
+
- Hyperbolic: `sinh`, `cosh`, `tanh`, `arcsinh`, `arccosh`, `arctanh`
|
| 34 |
+
- Logarithmic & Exponential: `log`, `log10`, `log1p`, `exp`, `expm1`
|
| 35 |
+
- Other: `sqrt`, `abs`, `where`, `complex`, `real`, `imag`, `conj`
|
| 36 |
+
|
| 37 |
+
**Examples:**
|
| 38 |
+
- `exp(2) + sqrt(9)`
|
| 39 |
+
- `log(10) / 2`
|
| 40 |
+
- `where(5 > 2, 10, 0)`
|
| 41 |
+
- `sin(3.14/2) * 2`
|
| 42 |
+
- `abs(-7) + 5**2`
|
| 43 |
+
- `log1p(9)`
|
| 44 |
+
- `real(complex(3, 4))`
|
| 45 |
+
- `arctan2(1, 1)`
|
| 46 |
+
- `tanh(2) > 0.9`
|
| 47 |
|
| 48 |
Args:
|
| 49 |
expression: The nunexpr formatted expression to evaluate
|