Spaces:
Sleeping
Sleeping
Update solver.py
Browse files
solver.py
CHANGED
|
@@ -4,15 +4,13 @@ from sympy.solvers import solve
|
|
| 4 |
from sympy import integrate, diff, latex,simplify, expand, log, exp, sin, cos, tan, asin, acos, atan, Symbol, factorial, laplace_transform
|
| 5 |
import re
|
| 6 |
def format_expression(expr):
|
| 7 |
-
latex_expr = latex(expr)
|
| 8 |
try:
|
| 9 |
-
#
|
| 10 |
-
if
|
| 11 |
-
|
| 12 |
-
if
|
| 13 |
-
return str(
|
| 14 |
-
|
| 15 |
-
# For other expressions
|
| 16 |
replacements = {
|
| 17 |
'**': '^', # Power notation
|
| 18 |
'*x': 'x', # Remove unnecessary multiplication signs
|
|
|
|
| 4 |
from sympy import integrate, diff, latex,simplify, expand, log, exp, sin, cos, tan, asin, acos, atan, Symbol, factorial, laplace_transform
|
| 5 |
import re
|
| 6 |
def format_expression(expr):
|
|
|
|
| 7 |
try:
|
| 8 |
+
# For numeric expressions, evaluate and return the result
|
| 9 |
+
if hasattr(expr, 'evalf'):
|
| 10 |
+
evaluated = expr.evalf()
|
| 11 |
+
if evaluated.is_real:
|
| 12 |
+
return str(float(evaluated))
|
| 13 |
+
latex_expr = latex(expr)
|
|
|
|
| 14 |
replacements = {
|
| 15 |
'**': '^', # Power notation
|
| 16 |
'*x': 'x', # Remove unnecessary multiplication signs
|