# How to convert "cos(th)+i*sin(th)" to "e^(i*th)"?

This question is perhaps trivial but annoying. I don't expect a quick answer.

The following are all I have tried.

sage: th = var('th')

----------

sage: e^(I*th).simplify_trig()
e^(I*th)
sage: e^(I*th).simplify_exp()
e^(I*th)
sage: e^(I*th).simplify_full()
e^(I*th)

----------

sage: f = cos(th) + I*sin(th)
sage: f.simplify_trig()
I*sin(th) + cos(th)
sage: f.simplify_exp()
I*sin(th) + cos(th)
sage: f.simplify_full()
I*sin(th) + cos(th)


edit retag close merge delete

Sort by » oldest newest most voted You need to convert sage object to maxima object and then exponentialize

th=var('th')
f=cos(th)+I*sin(th)
sageobj(f._maxima_().exponentialize())

more

1

Note that if you indent you code by 4 spaces, then it will be displayed nicely.

That said, i do not know how to to the conversion automatically. What is clear is that Maxima "knows" that those two quantities are equal:

sage: th = var('th')
sage: f = cos(th) + I*sin(th)
sage: g = e^(I*th)
sage: f == g
cos(th) + I*sin(th) == e^(I*th)
sage: bool(f == g)
True


I do not know how to do the conversion automatically. The best i can is:

sage: g.real_part().full_simplify()
cos(th)
sage: g.imag_part().full_simplify()
sin(th)

more

Thanks! Does it mean that we can only convert it automatically from exp() to cos(), sin() , but cannot the other way round? PS, "indent the code by 4 spaces" muss I modify some initial/default configuration file of SAGE?

The indentation is for ask.sagemath only, note related to Sage.

1

I think that Maxima's rectform might be useful here - it might even be in Sage now?

@kcrismanhttp://trac.sagemath.org/ticket/13061 .. Yes, it works, but not the other round. The polar form is more convenient and intuitive.