Hyperbolic Simplification



mohamed abouzied <mohamedabouzied at hotmail.com> writes:
>  If you want to use the demoavre identity of exp(i)+exp(-i)=2cos(0) we
> can use: trigrat(exp(%i)+exp(-%i));

You can also use demoivre(exp(%i)+exp(-%i)) to do this, though the
answer is 2*cos(1), not 2*cos(0).  There's also an evaluation flag of
the same name, so you can say "demoivre:true;" and then this conversion
will be done automatically by the simplifier.

> But on the other hand if you want the hyperbolic identity,
> exp(1)+exp(-1)=2cosh(0)  Why does this not implemented?

Note: it should be 2*cosh(1), not 2*cosh(0).

Despite the similarity, it turns out to be much more difficult to do
this intelligently.  Demoivre simply converts every exponential whose
argument is in explicit rectangular form as follows:

  exp(a+b*%i) ==> exp(a)*(cos(b)+%i*sin(b))

The corresponding hyperbolic identity is:

  exp(a) ==> cosh(a) + sinh(a)

However, this doesn't work well in practice.  For example, consider:

  exp(2*x)+1

If you apply the simple rule above, you get:

  cosh(2*x) + sinh(2*x) + 1

However, you might have wanted this instead:

  2*exp(x)*cosh(x)

... especially if the example above was the numerator of this larger
expression:

  (exp(2*x)+1) / (exp(2*x)-1)
==>  2*exp(x)*cosh(x) / 2*exp(x)*sinh(x)
==>  coth(x)

So, although the simple demoivre rule can be uniformly applied to
individual exponentials with good results, an intelligent "hyperbolize"
function must find pairs of terms (at least one being an exponential),
and selectively use the following rule:

 A*exp(C) + B*exp(D)     (where C or D might be zero, but not both)
   ==> (A+B)*exp((C+D)/2)*cosh((C-D)/2) +
       (A-B)*exp((C+D)/2)*sinh((C-D)/2)

What if there are more than two exponential terms in a sum?  In that
case, you have to decide how best to combine them into pairs.  If there
are many exponential terms, this may become a rather expensive search.

I have written a preliminary "hyperbolize" function which attempts to
use a combination of heuristics to do this job with O(n^2) complexity
(where n is the number of terms per MPLUS with distinct exponential
arguments), but it is far more complex and ad-hoc than I would prefer,
and not yet ready for publication.  See below for a taste of its current
abilities and weaknesses.

     Mark


(%i2) load(hyperbolize);
(%o2) "/home/mhw/.maxima/hyperbolize.lisp"
(%i3) ex1: (exp(2*x)+1)/(exp(2*x)-1) + C;
(%o3) C+(%e^(2*x)+1)/(%e^(2*x)-1)
(%i4) hyperbolize(ex1);
(%o4) C+coth(x)
(%i5) expand(ex1);
(%o5) C+%e^(2*x)/(%e^(2*x)-1)+1/(%e^(2*x)-1)
(%i6) hyperbolize(%);
(%o6) C+coth(x)
(%i7) ratsimp(ex1);
(%o7) ((%e^(2*x)-1)*C+%e^(2*x)+1)/(%e^(2*x)-1)
(%i8) hyperbolize(%);
(%o8) C+coth(x)
(%i9) ex2: exp(2*x)+exp(-2*x)-exp(y)+exp(-y)+exp(3*y);
(%o9) %e^(3*y)-%e^y+%e^-y+%e^(2*x)+%e^-(2*x)
(%i10) hyperbolize(ex2);
(%o10) -2*sinh(y)+%e^(3*y)+2*cosh(2*x)
(%i11) multthru(exp(y), ex2);
(%o11) %e^(y+2*x)+%e^(y-2*x)+%e^(4*y)-%e^(2*y)+1
(%i12) hyperbolize(%);
(%o12) 2*%e^(3*y)*sinh(y)+2*cosh(2*x)*%e^y+1
(%i13) hyperbolize(exp(2)+exp(-2));
(%o13) 2*cosh(2)
(%i14) hyperbolize(exp(1)+exp(-2));
(%o14) %e+%e^-2
(%i15) hyperbolize(exp(1)+exp(-1));
(%o15) %e+%e^-1
(%i16) hyperbolize(1+exp(-2));
(%o16) 2*%e^-1*cosh(1)