Welcome to ZOJ
Information
Problems
Runs
Statistics
Ranklist
Clarification
100 - Let's Celebrate the 100th Contest on ZOJ! - 100F
Complex Calculator

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Dr. Jimbo, an applied mathematician, needs to calculate complex numbers all day for solving his own problems. In his laboratory, he uses an excellent application program for manipulating complex numbers expressions, however, he cannot use it outside his laboratory because the software consumes much of resources. He wants to manipulate complex numbers outside, so he needs a small program similar to the excellent application for his handheld computer.

Your job is to provide him a program that computes expressions of complex numbers.

Expressions of complex numbers just has almost the same grammer as the C programming language's. The only difference is that all constants are complex numbers and there is a special constant "i", which is the imaginary unit (i*i=-1). Besides the elementary arithmetic operations, namely addition, subtraction, multiplication and division, all following function should be implemented:

function:
x+yreturn new complex value x plus y.
x-yreturn new complex value x minus y.
x*yreturn new complex value x times y.
x/yreturn new complex value x divided by y.
abs(x)return magnitude of x. abs(x) = sqrt(x * conj(x)).
acos(x)return complex arc cosine of x, with real part in [0,pi]. acos(x) = -i log(x + sqrt(x * x - 1))
acosh(x)return complex arc hyperbolic cosine of x, with imaginary part in [-pi,pi] and real part non-negative. acosh(x) = (0.5) * log((1 + x) / (1 - x)).
arg(x)return phase angle of x. arg(x) = atan2(imag(x), real(x))
asin(x)return complex arc sine of x, with real part in [-pi/2,pi/2]. asin(x) = -i log(iz + sqrt(1 - x * x)).
asinh(x)return complex arc hyperbolic sine of x, with imaginary part in [-pi/2,pi/2]. asinh(x) = log(x + sqrt(x * x + 1)).
atan(x)return complex arc tangent of x, with real part in [-pi/2,pi/2]. atan(x) = 1 / 2i log((1 + iz) / (1 - iz)).
atanh(x)return complex arc hyperbolic tangent of x, with imaginary part in [-pi/2,pi/2]. atanh(x) = 0.5 * log((1 + x) / (1 - x)).
conj(x)return complex conjugate of x.
cos(x)return complex cosine of x. cos(x) = (exp(i * x) + exp(-i * x)) / 2.
cosh(x)return complex hyperbolic cosine of x. cosh(x) = (exp(x) + exp(-x)) / 2.
exp(x)return complex base e exponential of x. exp(i * x) = cos(x) + i * sin(x)
imag(x)return imaginary part of complex number x.
log(x)return complex natural logarithm of x. log(x) = log(abs(x)) + i * arg(x).
pow(x,y)return x raised to the power y, with a branch cut for x along the negative real axis.
real(x)return real part of complex number x.
sin(x)return complex sine of x. sin(x) = (exp(i * x) - exp(-i * x)) / (2 * i).
sinh(x)return complex hyperbolic sine of x. sinh(x) = (exp(x) - exp(-x)) / 2.
sqrt(x)return complex square root of x, with non-negative real part, and with a branch cut along the negative real axis.
tan(x)return complex tangent of x. tan(x) = sin(x) / cos(x).
tanh(x)return complex hyperbolic tangent of x. tanh(x) = sinh(x) / cosh(x).

All other operations and functions are invalid. Overflow and division by zero are also invalid.

Input

Lines of expressions. There are no blanks in the expression and it's guaranteed that the expression is always valid.

Output

For each expression, output the result with six digits after the decimal point, always output the sign ('+' or '-'). See sample for more details. Never output "-0.000000"!

Sample Input

i*i
pow(-1*i,2)
sqrt(-1.0)
8+6*i/8-6*i
(8+6*i)/(8-6*i)
(8+6*i)*conj(8-6*i)
2*exp(i*acos(-1)/6)
pow(i,i)
cos(i)
cos(-1*i)
acos(cos(i))
acos(cos(i*-1))
pow(exp(1),acos(-1)*i)

Sample Output

-1.000000+0.000000*i
-1.000000+0.000000*i
+0.000000+1.000000*i
+8.000000-5.250000*i
+0.280000+0.960000*i
+28.000000+96.000000*i
+1.732051+1.000000*i
+0.207880+0.000000*i
+1.543081+0.000000*i
+1.543081+0.000000*i
+0.000000+1.000000*i
+0.000000+1.000000*i
-1.000000+0.000000*i

Author: WU, Zejun
Source: Let's Celebrate the 100th Contest on ZOJ!
Submit    Status