Spaces:
Running
Running
Update solver.py
Browse files
solver.py
CHANGED
@@ -28,8 +28,9 @@ def preprocess_equation(equation_str):
|
|
28 |
'cos⁻¹': 'acos',
|
29 |
'tan⁻¹': 'atan',
|
30 |
'e^': 'exp',
|
31 |
-
'ln': 'log',
|
32 |
-
'
|
|
|
33 |
}
|
34 |
for old, new in replacements.items():
|
35 |
equation_str = equation_str.replace(old, new)
|
@@ -83,11 +84,12 @@ def process_expression(expr_str):
|
|
83 |
result = diff(expr, x)
|
84 |
return f"d/dx({format_expression(expr)}) = {format_expression(result)}"
|
85 |
|
86 |
-
elif 'factorial' in processed_expr: # Factorial
|
87 |
expr = parse_expr(processed_expr, transformations=(standard_transformations + (implicit_multiplication_application,)))
|
88 |
-
result = expr.doit()
|
89 |
return f"{format_expression(expr)} = {format_expression(result)}"
|
90 |
|
|
|
91 |
elif '/' in expr_str: # Handle fractions and return decimal
|
92 |
expr = parse_expr(processed_expr, transformations=(standard_transformations + (implicit_multiplication_application,)))
|
93 |
simplified = simplify(expr)
|
|
|
28 |
'cos⁻¹': 'acos',
|
29 |
'tan⁻¹': 'atan',
|
30 |
'e^': 'exp',
|
31 |
+
'ln': 'log', # Convert ln to log (SymPy default)
|
32 |
+
'√': 'sqrt', # Convert square root symbol to sqrt()
|
33 |
+
'!': '.factorial()', # Convert factorial to function call
|
34 |
}
|
35 |
for old, new in replacements.items():
|
36 |
equation_str = equation_str.replace(old, new)
|
|
|
84 |
result = diff(expr, x)
|
85 |
return f"d/dx({format_expression(expr)}) = {format_expression(result)}"
|
86 |
|
87 |
+
elif 'factorial' in processed_expr: # Factorial case
|
88 |
expr = parse_expr(processed_expr, transformations=(standard_transformations + (implicit_multiplication_application,)))
|
89 |
+
result = expr.doit() # Evaluate factorial properly
|
90 |
return f"{format_expression(expr)} = {format_expression(result)}"
|
91 |
|
92 |
+
|
93 |
elif '/' in expr_str: # Handle fractions and return decimal
|
94 |
expr = parse_expr(processed_expr, transformations=(standard_transformations + (implicit_multiplication_application,)))
|
95 |
simplified = simplify(expr)
|