I like the subst trick, but it can give ugly results even for simple cases:
(%i1) exp_to_tanh(e) := subst("^" = lambda([a,x], if a = '%e then (1 +
tanh(x/2))/(1 - tanh(x/2)) else a^x),e)$
(%i2) exp_to_tanh(exponentialize(tanh(x)));
(%o2) ((tanh(x/2)+1)/(1-tanh(x/2))-(1-tanh(x/2))/(tanh(x/2)+1))
/((1-tanh(x/2))/(tanh(x/2)+1)+(tanh(x/2)+1)/(1-tanh(x/2)))
(%i3) ratsimp(%);
(%o3) 2*tanh(x/2)/(tanh(x/2)^2+1) <<< not very nice
(%i4) %,halfangles;
(%o4) 2*(cosh(x)-1)/(((cosh(x)-1)^2/sinh(x)^2+1)*sinh(x)) <<< no better
Of course, the box/rembox trick requires that you know in advance what the
argument to the desired tanh is. Applying it to say tanh(a*x) doesn't work
very well....
-s
On Sun, Jan 9, 2011 at 14:48, Barton Willis <willisb at unk.edu> wrote:
> Another possibility:
>
> (%i45) exp_to_tanh(e) := subst("^" = lambda([a,x], if a = '%e then (1 +
> tanh(x/2))/(1 - tanh(x/2)) else a^x),e)$
>
> (%i47) ratsimp(exp_to_tanh( y = (%e^(2*x)+1)/(%e^(2*x)-1)+%c));
> (%o47) y=(%c*tanh(x)+1)/tanh(x)
>
> (%i50) exp_to_tanh( y = x^2/9 + exp(x^2));
> (%o50) y=(tanh(x^2/2)+1)/(1-tanh(x^2/2))+x^2/9
>
> Of course, it would be much better do the exp --> tanh substitution only
> when the result is something that
> is more appealing (aka simplified).
>
> --Barton
>
> -----maxima-bounces at math.utexas.edu wrote: -----
>
>
> >I haven't found an *automated* way of reexpressing this with tanh.
> >However, but substituting atanh(tanh(x)) for x (but temporarily blocking
> >the simplification), you can derive the result:
> >
> >(%i56) f: y = (%e^(2*x)+1)/(%e^(2*x)-1)+%c$
> >(%i57) subst(atanh(box(tanh(x))),x,f);
> >(%o57) y =
> >(%e^(2*atanh(box(tanh(x))))+1)/(%e^(2*atanh(box(tanh(x))))-1)+%c
> >
> >(%i58) expand(rembox(ratsimp(logarc(%))));
> >(%o58) y = 1/tanh(x)+%c
> >
> >On Sun, Jan 9, 2011 at 06:08, nijso beishuizen
> ><nijso at numerically-related.com> wrote:
> >
> >f: y = (%e^(2*x)+1)/(%e^(2*x)-1)+%c;
>