%mathpiper,def="Combine"

//Retract("Combine",*);

10 # Combine(expr_IsZero) <-- 0;

20 # Combine(_expr) <-- 
[
    Local(L);
    L := ReassembleListTerms(DisassembleExpression(expr));
    UnFlatten(L,"+",0);
];

%/mathpiper

    %output,preserve="false"
      Result: True
.   %/output




%mathpiper_docs,name="Combine",categories="User Functions;Expression Simplification"
*CMD Combine --- try to simplify an expression by combining terms or factors that cancel
*STD
*CALL
	Combine(expr)

*PARMS

{expr} -- expression to simplify

*DESC

This function tries to simplify the expression {expr} by combining like
terms or factors that will cancel. 
Unlike the related function {Simplify}, it does not manipulate the expression 
any further.

See Issue #14 for a description of why this function may be necessary.

At the present time, MathPiper's automatic evaluation scheme simplifies some
expressions but leaves other, similar ones, unsimplified (See examples 1 and 2
below).  
A call to Simplify()
may complete the simplification of the expression, but sometimes Simplify() does
too much (see example 3, below).

A call to Combine() is more likely to give what is wanted than a call to Simplify().
Until such time as we can make Combine() a part of MathPiper's automatic
expression evaluation, this is the best workaround.

*E.G.
In> e1:=3 + x/5 - 3
Result: x/5         (automatically simplified upon entry)

In> e2:=3-x/5-3
Result: 3-x/5-3     (NOT automatically simplified upon entry)

In> Simplify(e2)
Result: (-x)/5      (Simplify() does the job)

In> e3:=3 + x/5 + x/5
Result: (2*x)/5+3

In> Simplify(e3)
Result: (2*x+15)/5  (Simplify() does more than we want, here)

In> Combine(e3)
Result: (2*x)/5+3   (Combine() does just enough -- not too much)
    
*SEE Simplify, TrigSimpCombine, RadSimp
%/mathpiper_docs

    %output,preserve="false"
      
.   %/output


