Repeatedly applying trigsimp, ratsimp etc.



David,

I did have some code for this a while ago; not sure whether I can dredge it
up.

Your suggested approach actually won't work -- you don't want to keep only
the simplest version of each stage; you want to keep *all *versions because
sometimes the only way to get from form A to form C is through an
intermediate form B which is *not* "simplest".

Another important thing is of course defining what you mean by "simple".  A
simple metric is number of characters in string form, but that isn't
necessarily the "nicest" form.  Depending on your goal, any one of the
following may be the "simplest" form:

     (y+x+1)^2-1 (11 chars)
     (y+x)*(y+x+2) (13 chars)
     y^2+(2*x+2)*y+x^2+2*x (21 chars)
     x^2+(2*y+2)*x+y^2+2*y (21 chars)
     y^2+2*x*y+2*y+x^2+2*x (21 chars)]

Also, simply applying trigsimp/ratsimp/etc. multiple times is not the only
way to shorten an expression.  Sometimes you might want to look at all
subexpressions or do other clever things -- how are you going to get
(y+x+1)^2-1
from y^2+2*x*y+2*y+x^2+2*x?

           -s

On Wed, Oct 31, 2012 at 4:04 PM, David Scherfgen <d.scherfgen at googlemail.com
> wrote:

> Hello,
>
> Maxima has a lot of different simplification functions.
> I'm looking for a way to "try them all" and find the simplest expression.
> Basically I want to do this:
>
> Given an expression e, compute trigsimp(e), ratsimp(e), radcan(e) ...
> See which of these gives the "simplest" result and do the same again with
> this simpler result.
> Stop when none of the functions can produce a simpler result any more.
>
> First I thought that "scsimp" was the right function to do this, and I
> tried it like this:
>
> matchdeclare(x, true);
> defrule(r1, x, trigsimp(x));
> defrule(r2, x, ratsimp(x));
> // more rules follow
>
> // my expression to be simplified
> // it equals to 1, if you apply "trigsimp"
> expr : tan(x) * cot(x)
>
> scsimp(expr, r1, r2, ...);
>
> However, "scsimp" doesn't apply any of the rules.
> If I manually apply rule "r1", it gives me the correct result "1".
>
> Am I doing something wrong? Or does "scsimp" just not work like this?
> How could I do it manually? Is there a Maxima function that computes the
> length of an expression, so I could use it to select the best result in
> each step?
>
> I'm very grateful for any help.
>
> Kind regards,
> David Scherfgen
> ______________________________**_________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>;
>