Spaces:
Running
Running
Update solver.py
Browse files
solver.py
CHANGED
@@ -1,7 +1,7 @@
|
|
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)
|
@@ -113,12 +113,25 @@ def process_expression(expr_str):
|
|
113 |
result = diff(expr, x)
|
114 |
return f"d/dx({format_expression(expr)}) = {format_expression(result)}"
|
115 |
|
|
|
116 |
elif 'sqrt' in processed_expr: # Handle square roots
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
elif 'factorial' in processed_expr: # Factorial case
|
124 |
expr = parse_expr(processed_expr, transformations=(standard_transformations + (implicit_multiplication_application,)))
|
|
|
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,sqrt, 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)
|
|
|
113 |
result = diff(expr, x)
|
114 |
return f"d/dx({format_expression(expr)}) = {format_expression(result)}"
|
115 |
|
116 |
+
|
117 |
elif 'sqrt' in processed_expr: # Handle square roots
|
118 |
+
try:
|
119 |
+
transformations = standard_transformations + (implicit_multiplication_application,)
|
120 |
+
expr = sp.parse_expr(processed_expr, transformations=transformations)
|
121 |
+
|
122 |
+
sqrt_result = sqrt(expr) # Compute square root
|
123 |
+
positive_root = sqrt_result
|
124 |
+
negative_root = -sqrt_result
|
125 |
+
|
126 |
+
steps = []
|
127 |
+
steps.append(f"**Step 1:** Original expression: \n{latex(expr)}")
|
128 |
+
steps.append(f"**Step 2:** Taking square root: \n{latex(sqrt_result)}")
|
129 |
+
steps.append(f"**Step 3:** Considering both positive and negative roots: \n±{latex(sqrt_result)}")
|
130 |
+
|
131 |
+
solution = "\n".join(steps)
|
132 |
+
|
133 |
+
except Exception as e:
|
134 |
+
solution = f"Error: {str(e)}"
|
135 |
|
136 |
elif 'factorial' in processed_expr: # Factorial case
|
137 |
expr = parse_expr(processed_expr, transformations=(standard_transformations + (implicit_multiplication_application,)))
|