Repository: sympy/sympy

Issue:
improve simplification of arg(exp(real*I))
Some obvious simplifications are missed:
```
In [26]: arg(exp(I*pi/7))
Out[26]:
    ⎛   ⎛π⎞⎞
    ⎜sin⎜─⎟⎟
    ⎜   ⎝7⎠⎟
atan⎜──────⎟
    ⎜   ⎛π⎞⎟
    ⎜cos⎜─⎟⎟
    ⎝   ⎝7⎠⎠

In [27]: simplify(_)
Out[27]:
π
─
7

In [28]: arg(exp(5*I))
Out[28]:
    ⎛sin(5)⎞
atan⎜──────⎟
    ⎝cos(5)⎠

In [29]: simplify(_)
Out[29]: 5 - 2⋅π

In [30]: arg(exp(pi*I/12))
Out[30]:
    ⎛  √2   √6⎞
    ⎜- ── + ──⎟
    ⎜  4    4 ⎟
atan⎜─────────⎟
    ⎜ √2   √6 ⎟
    ⎜ ── + ── ⎟
    ⎝ 4    4  ⎠

In [31]: simplify(_)
Out[31]:
    ⎛-1 + √3⎞
atan⎜───────⎟
    ⎝ 1 + √3⎠

In [32]: radsimp(_)
Out[32]:
π
──
12
```


Discussion:

Patch:
diff --git a/sympy/functions/elementary/complexes.py b/sympy/functions/elementary/complexes.py
index b00124189a..c615a3613d 100644
--- a/sympy/functions/elementary/complexes.py
+++ b/sympy/functions/elementary/complexes.py
@@ -758,9 +758,17 @@ def eval(cls, arg):
                 break
         else:
             return S.NaN
-        from sympy.functions.elementary.exponential import exp_polar
+        from sympy.functions.elementary.exponential import exp, exp_polar
         if isinstance(arg, exp_polar):
             return periodic_argument(arg, oo)
+        elif isinstance(arg, exp):
+            i_ = im(arg.args[0])
+            if i_.is_comparable:
+                i_ %= 2*S.Pi
+                if i_ > S.Pi:
+                    i_ -= 2*S.Pi
+                return i_
+
         if not arg.is_Atom:
             c, arg_ = factor_terms(arg).as_coeff_Mul()
             if arg_.is_Mul:


Test patch:
diff --git a/sympy/functions/elementary/tests/test_complexes.py b/sympy/functions/elementary/tests/test_complexes.py
index 8ff9803b1e..9fd2a0edaa 100644
--- a/sympy/functions/elementary/tests/test_complexes.py
+++ b/sympy/functions/elementary/tests/test_complexes.py
@@ -9,6 +9,7 @@
 from sympy.functions.elementary.miscellaneous import sqrt
 from sympy.functions.elementary.piecewise import Piecewise
 from sympy.functions.elementary.trigonometric import (acos, atan, atan2, cos, sin)
+from sympy.functions.elementary.hyperbolic import sinh
 from sympy.functions.special.delta_functions import (DiracDelta, Heaviside)
 from sympy.integrals.integrals import Integral
 from sympy.matrices.dense import Matrix
@@ -605,6 +606,15 @@ def test_arg():
     assert arg(exp_polar(4*pi*I)) == 4*pi
     assert arg(exp_polar(-7*pi*I)) == -7*pi
     assert arg(exp_polar(5 - 3*pi*I/4)) == pi*Rational(-3, 4)
+
+    assert arg(exp(I*pi/7)) == pi/7     # issue 17300
+    assert arg(exp(16*I)) == 16 - 6*pi
+    assert arg(exp(13*I*pi/12)) == -11*pi/12
+    assert arg(exp(123 - 5*I)) == -5 + 2*pi
+    assert arg(exp(sin(1 + 3*I))) == -2*pi + cos(1)*sinh(3)
+    r = Symbol('r', real=True)
+    assert arg(exp(r - 2*I)) == -2
+
     f = Function('f')
     assert not arg(f(0) + I*f(1)).atoms(re)