Spaces:
Running
Running
Update solver.py
Browse files
solver.py
CHANGED
@@ -5,7 +5,15 @@ from sympy import integrate, diff, latex,simplify, expand, log, exp, sin, cos, t
|
|
5 |
import re
|
6 |
def format_expression(expr):
|
7 |
latex_expr = latex(expr)
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
'**': '^', # Power notation
|
10 |
'*x': 'x', # Remove unnecessary multiplication signs
|
11 |
'*(': '(', # Remove multiplication before parentheses
|
@@ -40,10 +48,12 @@ def format_expression(expr):
|
|
40 |
'Re': 'β', # Real part
|
41 |
'Im': 'β' # Imaginary part
|
42 |
}
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
47 |
|
48 |
def preprocess_equation(equation_str):
|
49 |
"""Convert user-friendly equation format to SymPy format."""
|
|
|
5 |
import re
|
6 |
def format_expression(expr):
|
7 |
latex_expr = latex(expr)
|
8 |
+
try:
|
9 |
+
# Convert string to float and handle sqrt
|
10 |
+
if isinstance(expr, sp.Number):
|
11 |
+
float_val = float(expr)
|
12 |
+
if float_val.is_integer():
|
13 |
+
return str(int(float_val))
|
14 |
+
return str(float_val)
|
15 |
+
# For other expressions
|
16 |
+
replacements = {
|
17 |
'**': '^', # Power notation
|
18 |
'*x': 'x', # Remove unnecessary multiplication signs
|
19 |
'*(': '(', # Remove multiplication before parentheses
|
|
|
48 |
'Re': 'β', # Real part
|
49 |
'Im': 'β' # Imaginary part
|
50 |
}
|
51 |
+
for old, new in replacements.items():
|
52 |
+
latex_expr = latex_expr.replace(old, new)
|
53 |
+
return latex_expr
|
54 |
+
except:
|
55 |
+
return latex_expr
|
56 |
+
|
57 |
|
58 |
def preprocess_equation(equation_str):
|
59 |
"""Convert user-friendly equation format to SymPy format."""
|