Spaces:
Running
Running
Update solver.py
Browse files
solver.py
CHANGED
@@ -115,10 +115,15 @@ 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 |
-
|
119 |
-
positive_root =
|
120 |
-
negative_root = -
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
elif 'factorial' in processed_expr: # Factorial case
|
124 |
expr = parse_expr(processed_expr, transformations=(standard_transformations + (implicit_multiplication_application,)))
|
|
|
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 |
+
return f"√{format_expression(expr)} = ±{format_expression(positive_root)}"
|
125 |
+
else:
|
126 |
+
return f"√{format_expression(expr)} = ±√{format_expression(expr)}"
|
127 |
|
128 |
elif 'factorial' in processed_expr: # Factorial case
|
129 |
expr = parse_expr(processed_expr, transformations=(standard_transformations + (implicit_multiplication_application,)))
|