# 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

Thanks! sage: f.maxima_methods().exponentialize() and http://trac.sagemath.org/ticket/10038

( 2013-11-12 12:56:42 +0200 )edit

Thanks, @Shashank - I had completely forgotten about that ticket!

( 2013-11-12 17:01:59 +0200 )edit

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?

( 2013-11-12 09:05:40 +0200 )edit

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

( 2013-11-12 09:32:12 +0200 )edit
1

No, you can convert in both directions by being explicit, see [this ask answer](http://ask.sagemath.org/question/3134/complex-rectangular-to-polar#4231)

( 2013-11-12 09:35:31 +0200 )edit

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

( 2013-11-12 10:10:16 +0200 )edit

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

( 2013-11-12 10:17:44 +0200 )edit