Hacker News new | past | comments | ask | show | jobs | submit login

For your particular example, try foo.rewrite(cos). If you work with trigonometric expressions, it often pays to randomly do foo.rewrite(cos) or foo.rewrite(exp) along with simplify().

Your larger point is true though, at least from my experience.




Alas, sp.rewrite doesn't quite do what I want for the slightly more complicated (with new symbol 'k' suitably defined):

  bar = sp.exp(sp.I*(x + k - t)) - sp.exp(sp.I*(x+k+t))
The desired output would be 2 cos(t) exp(I(x+k)), but rewrite and simplify works on an all-or-nothing basis, affecting exp(I(x+k)) as well.

My mental framework is to come at this from something like a signal engineering perspective, looking at amplitude-modulated single frequencies. However, expressing that intent in a way that SymPy understands is for now beyond me.

My problem may ultimately be one of documentation. The basic SymPy tutorials are quite nice, and the raw documentation for the functions... exists, but I have yet to find good examples of intermediate to advanced use discussing the "what and why" of accomplishing nontrivial goals.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: