Last week I was trying to integrate a power of the Hyperbolic Tangent (tanh) in sage, so I first try,

sage: n,x = var('n,x') sage: integrate(tanh(x)^n, x)

but Sage didn’t integrate it. So I impose to be an integer,

sage: n,x = var('n,x') sage: assume(n, 'integer') sage: integrate(tanh(x)^n, x)and still nothing. However, for specific values of it worked,

sage: for n in range(1,6): ... integrate(tanh(x)^n, x) ...the results were shown.

In the other hand, Mathematica could solve the integration in general,

Integrate[Tanh[x]^n, x]in terms of Hyperbolic Functions (which Maxima does not manages). Even in the case of specific values of , the given results were much nicer because the answer were given in term of hyperbolic functions instead of exponential.

Then, I decide to try the Sage-Mathematica synapses.

## What do we need?

- Mathematica installed in the computer.
- The License information of Mathematica (even if you have already registered it)
- A working Sage installation.

## Proceed…

Open a terminal and call a sage subshell,

$ sage -sh

and call the mathematica kernel,

$ math

Here you will be asked to provide the license information. NOTE: It is possible that if runs without the information of the license, in that case you are ready to use Mathematica within Sage.

After provide the information you are ready.

## Using it!

The way of using is a bit weird, at the beginning, for integrate the sine function, use this,

sage: mathematica.Integrate(sin(x), x)

**Explaination:**

Since we are welling to use Mathematica kernel, the first word would be mathematica, followed by a Mathematica command separated by a point. Then, using Sage notation the argument.

This would work! However, the answer is presented in Mathematica notation. If you’d like to have the answer in Sage notation, use something like

sage: eq = mathematica.Integrate(sin(x), x); eq._sage_()

That’s it.

*I’d like to thank to schilly for his help*.

## Leave a Reply