Feeds:
Posts
Comments

## SAGE tip: rewriting expressions

Today I was calculating some stuff with the help of SAGE, and realize that the expressions got a lot (really, a lot) simpler if they where written in terms of  hyperbolic functions instead of exponentials.

$e^x = \cosh(x)+\sinh(x)$

$e^{-x} = \cosh(x)-\sinh(x)$

So I enter the sage-devel channel of IRC (freenode), but there was a lazy day around… Sunday. Therefore I decided to write to the sage-dev group on Google groups.

Francois Maltey answer my question on how to do the transformation… He has written a package that does it!

Let follow his instructions…

• Go to page http://wiki.sagemath.org/symbolics/rewrite
look at the second line the “attachement” (in smaller characters)
and get the most recent file.
• Then put this file in your Sage directory
In Sage, type : load “/the/good/file/in/the/good/directory’
Then call the rewrite function.
• Thank you Francois

#### Example

Suppose the path to the file is “/home/me/rewrite-xxx.sage”

```sage: load "/home/me/rewrite-xxx.sage" sage: A = exp(x) + exp(-x) sage: rewrite(A, 'exp2sinhconh') 2*cosh(x)```

If you go to http://wiki.sagemath.org/symbolics/rewrite, will find all possible commands which perform such transformations.

Enjoy!

Dox

Advertisements

### 2 Responses

1. That looks handy!

2. […] The only problem here is that, even when the relations are simple in this example, I’ve not found a `trivial’ way of simplifying the matrix elements of the exponentiation, not even with the procedure post in here. I didn’t try with the rewrite package […]