Taizun commited on
Commit
8891538
·
verified ·
1 Parent(s): 4c66c38

Update solver.py

Browse files
Files changed (1) hide show
  1. solver.py +9 -4
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
- result = sp.sqrt(expr)
119
- positive_root = result
120
- negative_root = -result
121
- return f"√{format_expression(expr)} = ±{format_expression(positive_root)}"
 
 
 
 
 
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,)))