# sympy/sympy

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

# Cannot Evaluate I**I #12744

Closed
opened this Issue Jun 13, 2017 · 11 comments

Projects
None yet
5 participants
Contributor

### ayush1999 commented Jun 13, 2017 • edited

 from sympy import x=symbols("x") x=I**I print(x) This gives the output: I**I Although output should be equal to e**(-pi/2)
Member

### jksuom commented Jun 13, 2017

 Powers with non-integer exponents are defined in SymPy via logarithms: `I**k = exp(k*log(I))`. The logarithm is multivalued, in particular, `log(I)` takes the values `I*pi/2 + 2*n*pi*I` where `n` is an integer. Therefore the possible values of `I**k` are `exp(k*I*pi/2)*exp(k*2*n*pi*I)`. If `k` is an integer, this is well defined since the second factor has value 1. However, if `k == I` then the second factor takes an infinite number of different values for different choices of `n`. In that case SymPy returns the original expression in order to not loose information.
Contributor

### ayush1999 commented Jun 13, 2017

 But when i say: from sympy import * x=symbols("x") x=sin(I)**I print(x) The output comes out to be: (I*sinh(1))**I Though the exponent here is non integer, non real , we get the correct answer even without using log.
Member

### jksuom commented Jun 13, 2017

 But `(I*sinh(1))**I` is fully analogous to `I**I`. It also contains implicitly an infinite number of different values.
Member

### jksuom commented Jun 13, 2017

 In principle, it could be possible to return one of the many values, but that is not currently done. I suppose that is because SymPy is basically oriented towards symbolic computations instead of numerical calculations.
Contributor

### skirpichev commented Jun 14, 2017

 The logarithm is multivalued @jksuom, but `Pow(b, e)` assume the principal value of `exp(e*log(b))`, isn't?
Member

### jksuom commented Jun 14, 2017

 but Pow(b, e) assume the principal value of exp(e*log(b)), isn't? I agree that it would be a natural way of defining the value, but it seems that it not currently implemented so.

### iteachmachines commented Jun 14, 2017

 @jksuom is correct (I*sinh(1))I is fully analogous to II. It contains implicitly an infinite number of different values and it is made for symbolic computations instead of numerical calculations.
Contributor

### skirpichev commented Jun 14, 2017

 but it seems that it not currently implemented so I'm not sure that your assumptions helpers are implemented in a way, that doesn't assume this. Or even `_eval_power()` helper: ``````In [5]: Pow(I, Rational(1, 3)) Out[5]: 6 ____ ╲╱ -1 In [6]: root(I, 3) Out[6]: 6 ____ ╲╱ -1 In [7]: root(I, 3, 1) Out[7]: 5/6 (-1) In [8]: root(I, 3, 2) Out[8]: -ⅈ ``````
Member

### asmeurer commented Jun 14, 2017

 I remember there being another issue about this, but it's almost impossible to search for in the issue tracker. I thought I remembered there being a way to make SymPy convert `I**I` to `exp(-pi/2`), but I can't find it now. I agree with @skirpichev that Pow generally only assumes the principal value. If you want multivalued expression, it's much better to add a variable to represent that, and possibly use `exp_polar` and friends as well. At the very least, I think `Pow._eval_rewrite_as_exp` should be implemented so that `(I**I).rewrite(exp)` works.
Contributor

### skirpichev commented Jun 14, 2017

 Pow generally only assumes the principal value Then it worth documenting, if that's assumed.
Member

### asmeurer commented Jun 18, 2017

 There is some discussion in the `root` docstring, but only for real bases.

Merged

### smichr closed this in #14712 Jun 15, 2018

to join this conversation on GitHub. Already have an account? Sign in to comment