How does Maple simplify algebraic expressions?

1.7k Views Asked by At

I use Maple to simplify messy algebraic expressions. My problem is that sometimes Maple does not do it and I do not know why.

For example, I know that a given expression is identically zero (checked it by hand several times) and it only contains elementary functions so there is no fancy mathematics.

I type the expression in, apply "simplify", Maple does transform it somewhat but it is still far from zero.

Then I transform a small part of the expression, doing the job for Maple, it goes "Aha!" and finally simplifies to zero.

So for some reason Maple sometimes just does not transform certain very simple expressions. Any idea why does it not?

Here is the example. Expressions L and R call function Q several times. L-R should simplify to zero.

restart;

Q := proc (x1, x2) options operator, arrow; -ln(exp(x1)+exp(x2))-ln(exp(-x1)+exp(-x2)) end proc;

Q := proc (x1, x2) options operator, arrow; -ln(2+exp(x1-x2)+exp(x2-x1)) end proc;

L := ln(exp(x1)+exp(ln(exp(x2)+exp(x3))+Q(x2, x3)))+Q(x1, ln(exp(x2)+exp(x3))+Q(x2, x3));

R := ln(exp(ln(exp(x1)+exp(x2))+Q(x1, x2))+exp(x3))+Q(ln(exp(x1)+exp(x2))+Q(x1, x2), x3);

simplify(L); simplify(R); simplify(L-R);

The first function Q and the second function Q are identical, the only difference is one line elementary transformation going from the first to the second.

If you use the first Q, and then execute the expressions L, R,..., simplify(L-R), that call function Q, you don't get answer 0.

If you use the second Q (after restart of course), the expression simplify(L-R) will become zero, as it should be, checked by manual calculations.

2

There are 2 best solutions below

3
On BEST ANSWER
restart;

kernelopts(version);

   Maple 2019.1, X86 64 LINUX, May 21 2019, Build ID 1399874

Q := (x1,x2) -> -ln(exp(x1)+exp(x2))-ln(exp(-x1)+exp(-x2)):

L := ln(exp(x1)+exp(ln(exp(x2)+exp(x3))+Q(x2, x3)))
     +Q(x1, ln(exp(x2)+exp(x3))+Q(x2, x3)):
R := ln(exp(ln(exp(x1)+exp(x2))+Q(x1, x2))+exp(x3))
     +Q(ln(exp(x1)+exp(x2))+Q(x1, x2), x3):

simplify(L-R);

                           0

And now the other Q,

restart;

Q := (x1,x2) -> -ln(2+exp(x1-x2)+exp(x2-x1)):

L := ln(exp(x1)+exp(ln(exp(x2)+exp(x3))+Q(x2, x3)))
     +Q(x1, ln(exp(x2)+exp(x3))+Q(x2, x3)):
R := ln(exp(ln(exp(x1)+exp(x2))+Q(x1, x2))+exp(x3))
     +Q(ln(exp(x1)+exp(x2))+Q(x1, x2), x3):

ln(normal(expand(exp(L-R))));

                           0

ln(factor(expand(exp(combine(L-R)))));

                           0

subsindets(combine(L-R),specfunc(ln),
           u->ln((expand@numer/expand@denom)(op(u))));

                           0

is(exp(L-R)=1);

                          true

is(L-R=0); # oof

                         false

The third way above, using subsindets, does not entail manually applying exp to the expression L-R up front. The call to subsindets forces Maple to expand numerator and denominator within any ln call, as a distinct action.

And, comparing just Q1 and Q2,

restart;

Q1 := (x1,x2) -> -ln(exp(x1)+exp(x2))-ln(exp(-x1)+exp(-x2)):
Q2 := (x1,x2) -> -ln(2+exp(x1-x2)+exp(x2-x1)):

ln(normal(expand(exp( Q1(x,y) -Q2(x,y) ))));

                           0

Of course, applying exp, manipulating, and then applying ln, is a specific trick.

2
On

All computer algebra systems can "simplify" algebraic expressions and perhaps beyond. Some of the methods used include distributing products over sums and factoring. There is no standard set of simplification algorithms and precise definition of simplicity of an expression. Some simplifications are dubious, such as, simplifying $\,\sqrt{x^2}\,$ or $\,\ln(e^x)\,$ to $\,x,\,$ or $\,x/x\,$ to $1$ without any assumptions on $\,x.\,$ In many difficult cases you have to "help" the system by giving explicit transformation rules. Simplification is not an easy subject.

In the particular case of your expressions, you may be able to show that the two expressions are the same by first exponentiating, then factoring. The following Mathematica code illustrates this:

ln = Log; exp = Exp;
Q1 = Function[{x1, x2}, -ln[exp[x1] + exp[x2]] - ln[exp[-x1] + exp[-x2]]];
Q2 = Function[{x1, x2}, -ln[2 + exp[x1 - x2] + exp[x2 - x1]]];
L = ln[exp[x1] + exp[ln[exp[x2] + exp[x3]] + Q[x2, x3]]] + 
    Q[x1, ln[exp[x2] + exp[x3]] + Q[x2, x3]];
R = ln[exp[ln[exp[x1] + exp[x2]] + Q[x1, x2]] + exp[x3]] + 
    Q[ln[exp[x1] + exp[x2]] + Q[x1, x2], x3];
exp /@ (L == R /. Q -> Q1)
Factor[exp /@ (L == R /. Q -> Q2)]

which returns the result True twice. Notice the Factor required for Q2. The key fact about logarithms is that they are multi-valued and this makes even simple transformations such as $\,\ln(x y) \to \ln(x) + \ln(y)\,$ problematic except in special cases. Thus, by exponentiating, you can eliminate potential problems and change sums of logarithm terms into a product of factors.