Repository: sympy/sympy

Issue:
sqrtdenest drops I
As described [here](https://stackoverflow.com/questions/59296496/converting-all-redundant-floats-in-a-string-to-integers/59305338#59305338):

```python
>>> -sqrt(-2 + 2*sqrt(3)*I)
-sqrt(-2 + 2*sqrt(3)*I)
>>> sqrtdenest(_), nsimplify(_)
(-1 + sqrt(3), -1 - sqrt(3)*I)
```

The `nsimplify` result is the right one.

Discussion:

Patch:
diff --git a/sympy/simplify/sqrtdenest.py b/sympy/simplify/sqrtdenest.py
index e437987d83..72a50c1c12 100644
--- a/sympy/simplify/sqrtdenest.py
+++ b/sympy/simplify/sqrtdenest.py
@@ -33,7 +33,8 @@ def sqrt_depth(p):
     >>> sqrt_depth(1 + sqrt(2)*sqrt(1 + sqrt(3)))
     2
     """
-
+    if p is S.ImaginaryUnit:
+        return 1
     if p.is_Atom:
         return 0
     elif p.is_Add or p.is_Mul:


Test patch:
diff --git a/sympy/simplify/tests/test_sqrtdenest.py b/sympy/simplify/tests/test_sqrtdenest.py
index ce9f177a20..6fb0d996ba 100644
--- a/sympy/simplify/tests/test_sqrtdenest.py
+++ b/sympy/simplify/tests/test_sqrtdenest.py
@@ -1,4 +1,4 @@
-from sympy import sqrt, root, S, Symbol, sqrtdenest, Integral, cos, Rational
+from sympy import sqrt, root, Symbol, sqrtdenest, Integral, cos, Rational, I
 from sympy.simplify.sqrtdenest import _subsets as subsets
 from sympy.simplify.sqrtdenest import _sqrt_match
 from sympy.utilities.pytest import slow
@@ -182,11 +182,13 @@ def test_issue_5653():
         sqrt(2 + sqrt(2 + sqrt(2)))) == sqrt(2 + sqrt(2 + sqrt(2)))
 
 def test_issue_12420():
-    I = S.ImaginaryUnit
-    assert _sqrt_match(4 + I) == []
     assert sqrtdenest((3 - sqrt(2)*sqrt(4 + 3*I) + 3*I)/2) == I
     e = 3 - sqrt(2)*sqrt(4 + I) + 3*I
     assert sqrtdenest(e) == e
 
 def test_sqrt_ratcomb():
     assert sqrtdenest(sqrt(1 + r3) + sqrt(3 + 3*r3) - sqrt(10 + 6*r3)) == 0
+
+def test_issue_18041():
+    e = -sqrt(-2 + 2*sqrt(3)*I)
+    assert sqrtdenest(e) == -1 - sqrt(3)*I