Spaces:
Sleeping
Sleeping
Update solver.py
Browse files
solver.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
import sympy as sp
|
| 2 |
from sympy.parsing.sympy_parser import parse_expr, standard_transformations, implicit_multiplication_application
|
| 3 |
from sympy.solvers import solve
|
| 4 |
-
from sympy import integrate, diff, simplify, expand, log, exp, sin, cos, tan, asin, acos, atan, Symbol, factorial, laplace_transform
|
| 5 |
import re
|
| 6 |
def format_expression(expr):
|
| 7 |
-
|
| 8 |
replacements = {
|
| 9 |
'**': '^', # Power notation
|
| 10 |
'*x': 'x', # Remove unnecessary multiplication signs
|
|
@@ -41,12 +41,9 @@ def format_expression(expr):
|
|
| 41 |
'Im': 'ℑ' # Imaginary part
|
| 42 |
}
|
| 43 |
for old, new in replacements.items():
|
| 44 |
-
|
| 45 |
-
return str_expr
|
| 46 |
|
| 47 |
-
|
| 48 |
-
str_expr = str_expr.replace(old, new)
|
| 49 |
-
return str_expr
|
| 50 |
|
| 51 |
def preprocess_equation(equation_str):
|
| 52 |
"""Convert user-friendly equation format to SymPy format."""
|
|
|
|
| 1 |
import sympy as sp
|
| 2 |
from sympy.parsing.sympy_parser import parse_expr, standard_transformations, implicit_multiplication_application
|
| 3 |
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 |
replacements = {
|
| 9 |
'**': '^', # Power notation
|
| 10 |
'*x': 'x', # Remove unnecessary multiplication signs
|
|
|
|
| 41 |
'Im': 'ℑ' # Imaginary part
|
| 42 |
}
|
| 43 |
for old, new in replacements.items():
|
| 44 |
+
latex_expr = latex_expr.replace(old, new)
|
|
|
|
| 45 |
|
| 46 |
+
return f"$$ {latex_expr} $$"
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def preprocess_equation(equation_str):
|
| 49 |
"""Convert user-friendly equation format to SymPy format."""
|