Spaces:
Sleeping
Sleeping
Update solver.py
Browse files
solver.py
CHANGED
|
@@ -115,13 +115,16 @@ def process_expression(expr_str):
|
|
| 115 |
|
| 116 |
elif 'sqrt' in processed_expr: # Handle square roots
|
| 117 |
expr = parse_expr(processed_expr, transformations=(standard_transformations + (implicit_multiplication_application,)))
|
| 118 |
-
# Calculate the square root
|
| 119 |
positive_root = sp.sqrt(expr)
|
| 120 |
negative_root = -positive_root
|
| 121 |
|
| 122 |
# Check if the expression is a perfect square
|
| 123 |
if expr.is_positive and positive_root.is_real:
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
else:
|
| 126 |
return f"β{format_expression(expr)} = Β±β{format_expression(expr)}"
|
| 127 |
|
|
|
|
| 115 |
|
| 116 |
elif 'sqrt' in processed_expr: # Handle square roots
|
| 117 |
expr = parse_expr(processed_expr, transformations=(standard_transformations + (implicit_multiplication_application,)))
|
|
|
|
| 118 |
positive_root = sp.sqrt(expr)
|
| 119 |
negative_root = -positive_root
|
| 120 |
|
| 121 |
# Check if the expression is a perfect square
|
| 122 |
if expr.is_positive and positive_root.is_real:
|
| 123 |
+
# Check if the expression is a perfect square
|
| 124 |
+
if positive_root.is_integer:
|
| 125 |
+
return f"β{format_expression(expr)} = {format_expression(positive_root)}"
|
| 126 |
+
else:
|
| 127 |
+
return f"β{format_expression(expr)} = Β±β{format_expression(expr)}"
|
| 128 |
else:
|
| 129 |
return f"β{format_expression(expr)} = Β±β{format_expression(expr)}"
|
| 130 |
|