Spaces:
Sleeping
Sleeping
Update solver.py
Browse files
solver.py
CHANGED
|
@@ -66,11 +66,9 @@ def preprocess_equation(equation_str):
|
|
| 66 |
def process_expression(expr_str):
|
| 67 |
"""Process mathematical expressions without equations."""
|
| 68 |
try:
|
| 69 |
-
# Preprocess the expression
|
| 70 |
processed_expr = preprocess_equation(expr_str)
|
| 71 |
x = Symbol('x')
|
| 72 |
|
| 73 |
-
# Check for special operations
|
| 74 |
if expr_str.startswith('∫'): # Integration
|
| 75 |
expr_to_integrate = processed_expr[1:].strip()
|
| 76 |
expr = parse_expr(expr_to_integrate, transformations=(standard_transformations + (implicit_multiplication_application,)))
|
|
@@ -90,6 +88,12 @@ def process_expression(expr_str):
|
|
| 90 |
result = expr.doit()
|
| 91 |
return f"{format_expression(expr)} = {format_expression(result)}"
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
else: # Regular expression simplification
|
| 94 |
expr = parse_expr(processed_expr, transformations=(standard_transformations + (implicit_multiplication_application,)))
|
| 95 |
simplified = simplify(expr)
|
|
@@ -99,6 +103,10 @@ def process_expression(expr_str):
|
|
| 99 |
except Exception as e:
|
| 100 |
raise Exception(f"Error processing expression: {str(e)}")
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
def solve_equation(equation_str):
|
| 103 |
"""Solve the given equation and return the solution."""
|
| 104 |
try:
|
|
|
|
| 66 |
def process_expression(expr_str):
|
| 67 |
"""Process mathematical expressions without equations."""
|
| 68 |
try:
|
|
|
|
| 69 |
processed_expr = preprocess_equation(expr_str)
|
| 70 |
x = Symbol('x')
|
| 71 |
|
|
|
|
| 72 |
if expr_str.startswith('∫'): # Integration
|
| 73 |
expr_to_integrate = processed_expr[1:].strip()
|
| 74 |
expr = parse_expr(expr_to_integrate, 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)
|
| 94 |
+
decimal_value = float(simplified)
|
| 95 |
+
return f"Simplified: {format_expression(simplified)}\nDecimal: {decimal_value}"
|
| 96 |
+
|
| 97 |
else: # Regular expression simplification
|
| 98 |
expr = parse_expr(processed_expr, transformations=(standard_transformations + (implicit_multiplication_application,)))
|
| 99 |
simplified = simplify(expr)
|
|
|
|
| 103 |
except Exception as e:
|
| 104 |
raise Exception(f"Error processing expression: {str(e)}")
|
| 105 |
|
| 106 |
+
|
| 107 |
+
except Exception as e:
|
| 108 |
+
raise Exception(f"Error processing expression: {str(e)}")
|
| 109 |
+
|
| 110 |
def solve_equation(equation_str):
|
| 111 |
"""Solve the given equation and return the solution."""
|
| 112 |
try:
|