Repository: sympy/sympy
Pull request: Make complex exponential algebraic
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes #20617 

#### Brief description of what is fixed or changed

I've modified the _eval_is_algebraic to accept rational multiples of `I*pi` as algebraic numbers, but I'd first see if this passes the tests.

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
- functions
  - Fixed assumption `is_algebraic` for exponentials with rational multiples of `I*pi` to be `True`.
<!-- END RELEASE NOTES -->

Problem statement:
Complex exponentials are not recognized by domains
```python3
>>> from sympy import *

>>> x = Symbol('x')
>>> w = exp(I*2*pi/3)
>>> Poly([w**2, w, 1], x, extension=True)
Poly(exp(-2*I*pi/3)*x**2 + exp(2*I*pi/3)*x + 1, x, domain='ZZ(exp(I*pi/3))')
>>> w = w.expand(complex=True)
>>> Poly([w**2, w, 1], x, extension=True)
Poly((-1/2 - sqrt(3)*I/2)*x**2 + (-1/2 + sqrt(3)*I/2)*x + 1, x, domain='QQ<sqrt(3) + I>')
```

Only the second one gets recognized as algebraic extension

Hints from issue discussion:
I think it's because `_eval_is_algebraic` gives None

Commit message: Make complex exponential algebraic

Patch to review:
diff --git a/sympy/functions/elementary/exponential.py b/sympy/functions/elementary/exponential.py
index fd360934c67c..a035927e2a22 100644
--- a/sympy/functions/elementary/exponential.py
+++ b/sympy/functions/elementary/exponential.py
@@ -445,15 +445,15 @@ def complex_extended_negative(arg):
         return fuzzy_or(complex_extended_negative(self.args[0]))
 
     def _eval_is_algebraic(self):
-        s = self.func(*self.args)
-        if s.func == self.func:
-            if fuzzy_not(self.exp.is_zero):
-                if self.exp.is_algebraic:
-                    return False
-                elif (self.exp/S.Pi).is_rational:
-                    return False
-        else:
-            return s.is_algebraic
+        if fuzzy_not(self.exp.is_zero):
+            if (self.exp / S.Pi / S.ImaginaryUnit).is_rational:
+                return True
+            if self.exp.is_algebraic:
+                return False
+            elif (self.exp / S.Pi).is_rational:
+                return False
+        elif self.exp.is_zero:
+            return True
 
     def _eval_is_extended_positive(self):
         if self.args[0].is_extended_real:


Code review comments:
diff_hunk: @@ -445,15 +445,15 @@ def complex_extended_negative(arg):
         return fuzzy_or(complex_extended_negative(self.args[0]))
 
     def _eval_is_algebraic(self):
-        s = self.func(*self.args)
-        if s.func == self.func:
-            if fuzzy_not(self.exp.is_zero):
-                if self.exp.is_algebraic:
-                    return False
-                elif (self.exp/S.Pi).is_rational:
-                    return False
-        else:
-            return s.is_algebraic
+        if fuzzy_not(self.exp.is_zero):
+            if (self.exp / S.Pi / S.ImaginaryUnit).is_rational:
path: sympy/functions/elementary/exponential.py
text: @user1:
How about taking this test first? It would also cover the `exp.is_zero` test.