%mathpiper,def="Simplify"

//Retract("Simplify",*);

10 # Simplify(expr_IsList) <-- MapSingle("Simplify",expr);

15 # Simplify(Complex(_r,_i)) <-- Complex(Simplify(r),Simplify(i));

20 # Simplify((_xex) == (_yex)) <-- (Simplify(xex-yex) == 0);

20 # Simplify((_xex) > (_yex)) <-- (Simplify(xex-yex) > 0);
20 # Simplify((_xex) < (_yex)) <-- (Simplify(xex-yex) < 0);
20 # Simplify((_xex) >= (_yex)) <-- (Simplify(xex-yex) >= 0);
20 # Simplify((_xex) <= (_yex)) <-- (Simplify(xex-yex) <= 0);
20 # Simplify((_xex) !== (_yex)) <-- (Simplify(xex-yex) !== 0);

// conditionals
25 # Simplify(if (_a) _b) <-- "if" @ {Simplify(a), Simplify(b)};
25 # Simplify(_a else _b) <-- "else" @ {Simplify(a), Simplify(b)};

// otherwise
40 # Simplify(_expr)_(Type(expr)="Ln") <--
[
    //If(InVerboseMode(),Tell("Simplify_Ln",expr));
    LnCombine(expr);
];

40 # Simplify(_expr)_(Type(expr)="Exp") <--
[
    //If(InVerboseMode(),Tell("Simplify_Exp",expr));
    expr;
];

50 # Simplify(_expr) <-- 
[
    //If(InVerboseMode(),Tell("Simplify_other",expr));
    MultiSimp(Eval(expr));
];

%/mathpiper



%mathpiper_docs,name="Simplify",categories="User Functions;Expression Simplification"
*CMD Simplify --- try to simplify an expression
*STD
*CALL
	Simplify(expr)

*PARMS

{expr} -- expression to simplify

*DESC

This function tries to simplify the expression {expr} as much
as possible. It does this by grouping powers within terms, and then
grouping similar terms.

*E.G.

In> a*b*a^2/b-a^3
Result: (b*a^3)/b-a^3;
In> Simplify(a*b*a^2/b-a^3)
Result: 0;

*SEE TrigSimpCombine, RadSimp, Combine
%/mathpiper_docs